feat: improve collection sidebar (#1320)

* feat: improve collection sidebar

* feat: add comments to splice blockTypesArray code

Co-authored-by: Jillian <jill@opencraft.com>
---------

Co-authored-by: Jillian <jill@opencraft.com>
Co-authored-by: Chris Chávez <xnpiochv@gmail.com>
This commit is contained in:
Rômulo Penido
2024-09-27 23:24:12 -03:00
committed by GitHub
parent c80483c053
commit 4d67e8bda9
29 changed files with 1155 additions and 139 deletions

View File

@@ -26,8 +26,11 @@ import {
updateXBlockFields,
createCollection,
getXBlockOLX,
updateCollectionMetadata,
type UpdateCollectionComponentsRequest,
updateCollectionComponents,
type CreateLibraryCollectionDataRequest,
getCollectionMetadata,
} from './api';
export const libraryQueryPredicate = (query: Query, libraryId: string): boolean => {
@@ -278,6 +281,33 @@ export const useXBlockOLX = (usageKey: string) => (
})
);
/**
* Get the metadata for a collection in a library
*/
export const useCollection = (libraryId: string, collectionId: string) => (
useQuery({
enabled: !!libraryId && !!collectionId,
queryKey: libraryAuthoringQueryKeys.collection(libraryId, collectionId),
queryFn: () => getCollectionMetadata(libraryId!, collectionId!),
})
);
/**
* Use this mutation to update the fields of a collection in a library
*/
export const useUpdateCollection = (libraryId: string, collectionId: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: UpdateCollectionComponentsRequest) => updateCollectionMetadata(libraryId, collectionId, data),
onSettled: () => {
// NOTE: We invalidate the library query here because we need to update the library's
// collection list.
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.collection(libraryId, collectionId) });
},
});
};
/**
* Use this mutation to add components to a collection in a library
*/