fix: Some spots where navigation state was not preserved

fix: Collection in main nav pops open when moving from starred collection
This commit is contained in:
Tom Moor
2022-04-04 19:04:28 -07:00
parent 26b5fa82e3
commit 20a69b711a
5 changed files with 11 additions and 21 deletions

View File

@@ -54,7 +54,7 @@ const CollectionLink: React.FC<Props> = ({
await collection.save({
name,
});
history.push(collection.url);
history.replace(collection.url, history.location.state);
},
[collection, history]
);

View File

@@ -13,7 +13,6 @@ import CollectionLinkChildren from "./CollectionLinkChildren";
import DropCursor from "./DropCursor";
import Relative from "./Relative";
import { DragObject } from "./SidebarLink";
import { useStarredContext } from "./StarredContext";
type Props = {
collection: Collection;
@@ -37,10 +36,8 @@ function DraggableCollectionLink({
}: Props) {
const locationStateStarred = useLocationStateStarred();
const { ui, collections } = useStores();
const inStarredSection = useStarredContext();
const [expanded, setExpanded] = React.useState(
collection.id === ui.activeCollectionId &&
locationStateStarred === inStarredSection
collection.id === ui.activeCollectionId && !locationStateStarred
);
const can = usePolicy(collection.id);
const belowCollectionIndex = belowCollection ? belowCollection.index : null;
@@ -88,18 +85,10 @@ function DraggableCollectionLink({
// If the current collection is active and relevant to the sidebar section we
// are in then expand it automatically
React.useEffect(() => {
if (
collection.id === ui.activeCollectionId &&
locationStateStarred === inStarredSection
) {
if (collection.id === ui.activeCollectionId && !locationStateStarred) {
setExpanded(true);
}
}, [
collection.id,
ui.activeCollectionId,
locationStateStarred,
inStarredSection,
]);
}, [collection.id, ui.activeCollectionId, locationStateStarred]);
const handleDisclosureClick = React.useCallback((ev) => {
ev.preventDefault();