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();

View File

@@ -55,15 +55,17 @@ function CollectionScene() {
const canonicalUrl = updateCollectionUrl(match.url, collection);
if (match.url !== canonicalUrl) {
history.replace(canonicalUrl);
history.replace(canonicalUrl, history.location.state);
}
}
}, [collection, collection?.name, history, id, match.url]);
React.useEffect(() => {
if (collection) {
ui.setActiveCollection(collection);
ui.setActiveCollection(collection.id);
}
return () => ui.setActiveCollection(undefined);
}, [ui, collection]);
React.useEffect(() => {

View File

@@ -200,7 +200,7 @@ class DocumentScene extends React.Component<Props> {
if (response) {
this.replaceDocument(response.data);
toasts.showToast(t("Document restored"));
history.replace(this.props.document.url);
history.replace(this.props.document.url, history.location.state);
}
};

View File

@@ -1,6 +1,5 @@
import { action, autorun, computed, observable } from "mobx";
import { light as defaultTheme } from "@shared/theme";
import Collection from "~/models/Collection";
import Document from "~/models/Document";
import { ConnectionStatus } from "~/scenes/Document/components/MultiplayerEditor";
@@ -150,8 +149,8 @@ class UiStore {
};
@action
setActiveCollection = (collection: Collection): void => {
this.activeCollectionId = collection.id;
setActiveCollection = (collectionId: string | undefined): void => {
this.activeCollectionId = collectionId;
};
@action