diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/bookmarks.tab.module.js b/src/bundle/ui-dev/src/modules/universal-discovery/bookmarks.tab.module.js index da95fbef3f..1aa3779db1 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/bookmarks.tab.module.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/bookmarks.tab.module.js @@ -22,7 +22,8 @@ import { getIconPath } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scri import { getTranslator } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper'; const BookmarksTabModule = () => { - const shouldRestorePreviousStateRef = useRef(true); + const isMarkedLocationSetByBookmarksRef = useRef(false); + const restorationStateRef = useRef(null); const restInfo = useContext(RestInfoContext); const tabsConfig = useContext(TabsConfigContext); const [currentView] = useContext(CurrentViewContext); @@ -46,13 +47,24 @@ const BookmarksTabModule = () => { }; useEffect(() => { - setMarkedLocationId(null); - dispatchLoadedLocationsAction({ type: 'CLEAR_LOCATIONS' }); + const isCleared = markedLocationId === null && loadedLocationsMap?.length === 0; + if (!isCleared && !isMarkedLocationSetByBookmarksRef.current) { + restorationStateRef.current = { + markedLocationId, + loadedLocationsMap, + }; + + setMarkedLocationId(null); + dispatchLoadedLocationsAction({ type: 'CLEAR_LOCATIONS' }); + } + }, [setMarkedLocationId, dispatchLoadedLocationsAction, markedLocationId, loadedLocationsMap]); + + useEffect(() => { return () => { - if (shouldRestorePreviousStateRef.current) { - setMarkedLocationId(markedLocationId); - dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: loadedLocationsMap }); + if (!isMarkedLocationSetByBookmarksRef.current) { + setMarkedLocationId(restorationStateRef.current.markedLocationId); + dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: restorationStateRef.current.loadedLocationsMap }); } }; }, []); @@ -62,8 +74,9 @@ const BookmarksTabModule = () => { return; } - shouldRestorePreviousStateRef.current = false; + isMarkedLocationSetByBookmarksRef.current = true; setMarkedLocationId(bookmarkedLocationMarked); + loadAccordionData( { ...restInfo, @@ -90,7 +103,7 @@ const BookmarksTabModule = () => {