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:
@@ -54,7 +54,7 @@ const CollectionLink: React.FC<Props> = ({
|
|||||||
await collection.save({
|
await collection.save({
|
||||||
name,
|
name,
|
||||||
});
|
});
|
||||||
history.push(collection.url);
|
history.replace(collection.url, history.location.state);
|
||||||
},
|
},
|
||||||
[collection, history]
|
[collection, history]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import CollectionLinkChildren from "./CollectionLinkChildren";
|
|||||||
import DropCursor from "./DropCursor";
|
import DropCursor from "./DropCursor";
|
||||||
import Relative from "./Relative";
|
import Relative from "./Relative";
|
||||||
import { DragObject } from "./SidebarLink";
|
import { DragObject } from "./SidebarLink";
|
||||||
import { useStarredContext } from "./StarredContext";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
collection: Collection;
|
collection: Collection;
|
||||||
@@ -37,10 +36,8 @@ function DraggableCollectionLink({
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const locationStateStarred = useLocationStateStarred();
|
const locationStateStarred = useLocationStateStarred();
|
||||||
const { ui, collections } = useStores();
|
const { ui, collections } = useStores();
|
||||||
const inStarredSection = useStarredContext();
|
|
||||||
const [expanded, setExpanded] = React.useState(
|
const [expanded, setExpanded] = React.useState(
|
||||||
collection.id === ui.activeCollectionId &&
|
collection.id === ui.activeCollectionId && !locationStateStarred
|
||||||
locationStateStarred === inStarredSection
|
|
||||||
);
|
);
|
||||||
const can = usePolicy(collection.id);
|
const can = usePolicy(collection.id);
|
||||||
const belowCollectionIndex = belowCollection ? belowCollection.index : null;
|
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
|
// If the current collection is active and relevant to the sidebar section we
|
||||||
// are in then expand it automatically
|
// are in then expand it automatically
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (
|
if (collection.id === ui.activeCollectionId && !locationStateStarred) {
|
||||||
collection.id === ui.activeCollectionId &&
|
|
||||||
locationStateStarred === inStarredSection
|
|
||||||
) {
|
|
||||||
setExpanded(true);
|
setExpanded(true);
|
||||||
}
|
}
|
||||||
}, [
|
}, [collection.id, ui.activeCollectionId, locationStateStarred]);
|
||||||
collection.id,
|
|
||||||
ui.activeCollectionId,
|
|
||||||
locationStateStarred,
|
|
||||||
inStarredSection,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const handleDisclosureClick = React.useCallback((ev) => {
|
const handleDisclosureClick = React.useCallback((ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|||||||
@@ -55,15 +55,17 @@ function CollectionScene() {
|
|||||||
const canonicalUrl = updateCollectionUrl(match.url, collection);
|
const canonicalUrl = updateCollectionUrl(match.url, collection);
|
||||||
|
|
||||||
if (match.url !== canonicalUrl) {
|
if (match.url !== canonicalUrl) {
|
||||||
history.replace(canonicalUrl);
|
history.replace(canonicalUrl, history.location.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [collection, collection?.name, history, id, match.url]);
|
}, [collection, collection?.name, history, id, match.url]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (collection) {
|
if (collection) {
|
||||||
ui.setActiveCollection(collection);
|
ui.setActiveCollection(collection.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => ui.setActiveCollection(undefined);
|
||||||
}, [ui, collection]);
|
}, [ui, collection]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
if (response) {
|
if (response) {
|
||||||
this.replaceDocument(response.data);
|
this.replaceDocument(response.data);
|
||||||
toasts.showToast(t("Document restored"));
|
toasts.showToast(t("Document restored"));
|
||||||
history.replace(this.props.document.url);
|
history.replace(this.props.document.url, history.location.state);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { action, autorun, computed, observable } from "mobx";
|
import { action, autorun, computed, observable } from "mobx";
|
||||||
import { light as defaultTheme } from "@shared/theme";
|
import { light as defaultTheme } from "@shared/theme";
|
||||||
import Collection from "~/models/Collection";
|
|
||||||
import Document from "~/models/Document";
|
import Document from "~/models/Document";
|
||||||
import { ConnectionStatus } from "~/scenes/Document/components/MultiplayerEditor";
|
import { ConnectionStatus } from "~/scenes/Document/components/MultiplayerEditor";
|
||||||
|
|
||||||
@@ -150,8 +149,8 @@ class UiStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setActiveCollection = (collection: Collection): void => {
|
setActiveCollection = (collectionId: string | undefined): void => {
|
||||||
this.activeCollectionId = collection.id;
|
this.activeCollectionId = collectionId;
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|||||||
Reference in New Issue
Block a user