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:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user