Skip to content

Commit

Permalink
IBX-7825: Fix UDW empty browse tab when coming from bookmarks tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Mar 5, 2024
1 parent dde567b commit b5700fc
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ 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 didBookmarksMarkedLocationRef = useRef(false);
const restorationStateRef = useRef({
markedLocationId,
loadedLocationsMap,
});
const restInfo = useContext(RestInfoContext);
const tabsConfig = useContext(TabsConfigContext);
const [currentView] = useContext(CurrentViewContext);
Expand All @@ -46,13 +50,24 @@ const BookmarksTabModule = () => {
};

useEffect(() => {
setMarkedLocationId(null);
dispatchLoadedLocationsAction({ type: 'CLEAR_LOCATIONS' });
const isCleared = markedLocationId === null && loadedLocationsMap?.length === 0;

if (!isCleared && !didBookmarksMarkedLocationRef.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 (!didBookmarksMarkedLocationRef.current) {
setMarkedLocationId(restorationStateRef.current.markedLocationId);
dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: restorationStateRef.current.loadedLocationsMap });
}
};
}, []);
Expand All @@ -62,7 +77,7 @@ const BookmarksTabModule = () => {
return;
}

shouldRestorePreviousStateRef.current = false;
didBookmarksMarkedLocationRef.current = true;
setMarkedLocationId(bookmarkedLocationMarked);
loadAccordionData(
{
Expand Down Expand Up @@ -90,7 +105,7 @@ const BookmarksTabModule = () => {
<div className="m-bookmarks-tab">
<Tab>
<BookmarksList itemsPerPage={tabsConfig.bookmarks.itemsPerPage} setBookmarkedLocationMarked={setBookmarkedLocationMarked} />
{renderBrowseLocations()}
{didBookmarksMarkedLocationRef.current && renderBrowseLocations()}
</Tab>
</div>
);
Expand Down

0 comments on commit b5700fc

Please sign in to comment.