diff --git a/app/scenes/Collection.tsx b/app/scenes/Collection.tsx index 9266f71da..afadcba38 100644 --- a/app/scenes/Collection.tsx +++ b/app/scenes/Collection.tsx @@ -50,14 +50,14 @@ function CollectionScene() { const can = usePolicy(collection?.id || ""); React.useEffect(() => { - if (collection) { + if (collection?.name) { const canonicalUrl = updateCollectionUrl(match.url, collection); if (match.url !== canonicalUrl) { history.replace(canonicalUrl); } } - }, [collection, history, id, match.url]); + }, [collection, collection?.name, history, id, match.url]); React.useEffect(() => { if (collection) { diff --git a/app/scenes/CollectionDelete.tsx b/app/scenes/CollectionDelete.tsx index 4c38b14d5..56d15a0cf 100644 --- a/app/scenes/CollectionDelete.tsx +++ b/app/scenes/CollectionDelete.tsx @@ -7,6 +7,7 @@ import Button from "~/components/Button"; import Flex from "~/components/Flex"; import Text from "~/components/Text"; import useCurrentTeam from "~/hooks/useCurrentTeam"; +import useStores from "~/hooks/useStores"; import useToasts from "~/hooks/useToasts"; import { homePath } from "~/utils/routeHelpers"; @@ -19,6 +20,7 @@ function CollectionDelete({ collection, onSubmit }: Props) { const [isDeleting, setIsDeleting] = React.useState(false); const team = useCurrentTeam(); const { showToast } = useToasts(); + const { ui } = useStores(); const history = useHistory(); const { t } = useTranslation(); const handleSubmit = React.useCallback( @@ -27,9 +29,12 @@ function CollectionDelete({ collection, onSubmit }: Props) { setIsDeleting(true); try { + const redirect = collection.id === ui.activeCollectionId; await collection.delete(); onSubmit(); - history.push(homePath()); + if (redirect) { + history.push(homePath()); + } } catch (err) { showToast(err.message, { type: "error", @@ -38,7 +43,7 @@ function CollectionDelete({ collection, onSubmit }: Props) { setIsDeleting(false); } }, - [collection, history, onSubmit, showToast] + [collection, history, onSubmit, showToast, ui.activeCollectionId] ); return ( diff --git a/app/scenes/CollectionEdit.tsx b/app/scenes/CollectionEdit.tsx index a3aaba3e4..899667a2d 100644 --- a/app/scenes/CollectionEdit.tsx +++ b/app/scenes/CollectionEdit.tsx @@ -3,7 +3,6 @@ import { observer } from "mobx-react"; import { useState } from "react"; import * as React from "react"; import { Trans, useTranslation } from "react-i18next"; -import { useHistory } from "react-router-dom"; import Button from "~/components/Button"; import Flex from "~/components/Flex"; import IconPicker from "~/components/IconPicker"; @@ -29,7 +28,6 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => { field: string; direction: "asc" | "desc"; }>(collection.sort); - const history = useHistory(); const [isSaving, setIsSaving] = useState(false); const { showToast } = useToasts(); const { t } = useTranslation(); @@ -46,7 +44,6 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => { color, sort, }); - history.push(collection.url); onSubmit(); showToast(t("The collection was updated"), { type: "success", @@ -59,7 +56,7 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => { setIsSaving(false); } }, - [collection, history, color, icon, name, onSubmit, showToast, sort, t] + [collection, color, icon, name, onSubmit, showToast, sort, t] ); const handleSortChange = (value: string) => {