@@ -790,6 +790,14 @@ export const useAddItemsToContainer = (containerId?: string) => {
790790 queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
791791
792792 const containerType = getBlockType ( containerId ) ;
793+ if ( [ 'subsection' , 'section' ] . includes ( containerType ) ) {
794+ // If the container is a subsection or section, we invalidate the
795+ // children query to update the hierarchy.
796+ variables . forEach ( ( itemId ) => {
797+ queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . containerHierarchy ( itemId ) } ) ;
798+ } ) ;
799+ }
800+
793801 if ( containerType === 'section' ) {
794802 // We invalidate the search query of the each itemId if the container is a section.
795803 // This because the subsection page calls this query individually.
@@ -849,13 +857,13 @@ export const useUpdateContainerChildren = (containerId?: string) => {
849857export const useRemoveContainerChildren = ( containerId ?: string ) => {
850858 const queryClient = useQueryClient ( ) ;
851859 return useMutation ( {
852- mutationFn : async ( usageKeys : string [ ] ) => {
860+ mutationFn : async ( itemIds : string [ ] ) => {
853861 if ( ! containerId ) {
854862 return undefined ;
855863 }
856- return api . removeLibraryContainerChildren ( containerId , usageKeys ) ;
864+ return api . removeLibraryContainerChildren ( containerId , itemIds ) ;
857865 } ,
858- onSettled : ( ) => {
866+ onSettled : ( _data , _error , variables ) => {
859867 if ( ! containerId ) {
860868 return ;
861869 }
@@ -864,6 +872,15 @@ export const useRemoveContainerChildren = (containerId?: string) => {
864872 const libraryId = getLibraryId ( containerId ) ;
865873 queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
866874 queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . container ( containerId ) } ) ;
875+
876+ const containerType = getBlockType ( containerId ) ;
877+ if ( [ 'subsection' , 'section' ] . includes ( containerType ) ) {
878+ // If the container is a subsection or section, we invalidate the
879+ // children query to update the hierarchy.
880+ variables . forEach ( ( itemId ) => {
881+ queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . containerHierarchy ( itemId ) } ) ;
882+ } ) ;
883+ }
867884 } ,
868885 } ) ;
869886} ;
0 commit comments