Skip to content

Commit

Permalink
fix: fix shortcut navigation crash
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Apr 4, 2024
1 parent 0a4d2c6 commit 876283d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/modules/navigation/ItemNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';

import { Alert } from '@mui/material';
Expand All @@ -20,6 +21,11 @@ const { useItem, useDescendants, useItemsTags } = hooks;
const DrawerNavigation = (): JSX.Element | null => {
const { rootId, itemId } = useParams();
const navigate = useNavigate();
const [prevRootId, setPrevRootId] = useState(rootId);

useEffect(() => {
setPrevRootId(rootId);
}, [rootId]);

const { t: translateMessage } = useMessagesTranslation();

Expand All @@ -32,6 +38,14 @@ const DrawerNavigation = (): JSX.Element | null => {
navigate(buildContentPagePath({ rootId, itemId: newItemId }));
};

// on root change, we need to destroy the tree
// since it keeps the same data on reload despite prop changes
// we cannot rely on isLoading because the data is taken from the cache
// bc of our query client optimization
if (prevRootId !== rootId) {
return <LoadingTree />;
}

if (rootItem) {
if (rootItem.id === rootId) {
return (
Expand All @@ -50,7 +64,6 @@ const DrawerNavigation = (): JSX.Element | null => {
</MainMenu>
);
}
console.log('switching');
return <LoadingTree />;
}

Expand Down

0 comments on commit 876283d

Please sign in to comment.