fix: After renaming collection, url does not update

This commit is contained in:
Tom Moor
2021-10-24 17:57:17 -07:00
parent bb36425175
commit 1d6bae05e6
3 changed files with 10 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import { observer } from "mobx-react";
import * as React from "react"; import * as React from "react";
import { useDrop, useDrag } from "react-dnd"; import { useDrop, useDrag } from "react-dnd";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom"; import { useLocation, useHistory } from "react-router-dom";
import styled from "styled-components"; import styled from "styled-components";
import Collection from "models/Collection"; import Collection from "models/Collection";
import Document from "models/Document"; import Document from "models/Document";
@@ -40,6 +40,7 @@ function CollectionLink({
isDraggingAnyCollection, isDraggingAnyCollection,
onChangeDragging, onChangeDragging,
}: Props) { }: Props) {
const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
const { search } = useLocation(); const { search } = useLocation();
const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean(); const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean();
@@ -53,8 +54,9 @@ function CollectionLink({
const handleTitleChange = React.useCallback( const handleTitleChange = React.useCallback(
async (name: string) => { async (name: string) => {
await collection.save({ name }); await collection.save({ name });
history.push(collection.url);
}, },
[collection] [collection, history]
); );
const { ui, documents, policies, collections } = useStores(); const { ui, documents, policies, collections } = useStores();

View File

@@ -4,6 +4,7 @@ import { observer } from "mobx-react";
import * as React from "react"; import * as React from "react";
import { useState } from "react"; import { useState } from "react";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import Button from "components/Button"; import Button from "components/Button";
import Flex from "components/Flex"; import Flex from "components/Flex";
import HelpText from "components/HelpText"; import HelpText from "components/HelpText";
@@ -30,6 +31,7 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => {
field: string, field: string,
direction: "asc" | "desc", direction: "asc" | "desc",
}>(collection.sort); }>(collection.sort);
const history = useHistory();
const [isSaving, setIsSaving] = useState(); const [isSaving, setIsSaving] = useState();
const { showToast } = useToasts(); const { showToast } = useToasts();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -46,6 +48,8 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => {
color, color,
sort, sort,
}); });
history.push(collection.url);
onSubmit(); onSubmit();
showToast(t("The collection was updated"), { showToast(t("The collection was updated"), {
type: "success", type: "success",
@@ -56,7 +60,7 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => {
setIsSaving(false); setIsSaving(false);
} }
}, },
[collection, color, icon, name, onSubmit, showToast, sort, t] [collection, history, color, icon, name, onSubmit, showToast, sort, t]
); );
const handleSortChange = (value: string) => { const handleSortChange = (value: string) => {

View File

@@ -2,7 +2,7 @@
import { HocuspocusProvider, WebSocketStatus } from "@hocuspocus/provider"; import { HocuspocusProvider, WebSocketStatus } from "@hocuspocus/provider";
import * as React from "react"; import * as React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useHistory } from "react-router"; import { useHistory } from "react-router-dom";
import { IndexeddbPersistence } from "y-indexeddb"; import { IndexeddbPersistence } from "y-indexeddb";
import * as Y from "yjs"; import * as Y from "yjs";
import Editor, { type Props as EditorProps } from "components/Editor"; import Editor, { type Props as EditorProps } from "components/Editor";