diff --git a/app/components/Sidebar/components/CollectionLink.tsx b/app/components/Sidebar/components/CollectionLink.tsx index fee3734ea2..abbe9b9d60 100644 --- a/app/components/Sidebar/components/CollectionLink.tsx +++ b/app/components/Sidebar/components/CollectionLink.tsx @@ -4,7 +4,6 @@ import { PlusIcon } from "outline-icons"; import * as React from "react"; import { useDrop } from "react-dnd"; import { useTranslation } from "react-i18next"; -import { useHistory } from "react-router-dom"; import { CollectionValidation } from "@shared/validations"; import Collection from "~/models/Collection"; import Document from "~/models/Document"; @@ -47,7 +46,6 @@ const CollectionLink: React.FC = ({ const [isEditing, setIsEditing] = React.useState(false); const can = usePolicy(collection); const { t } = useTranslation(); - const history = useHistory(); const sidebarContext = useSidebarContext(); const editableTitleRef = React.useRef(null); @@ -56,9 +54,8 @@ const CollectionLink: React.FC = ({ await collection.save({ name, }); - history.replace(collection.path, history.location.state); }, - [collection, history] + [collection] ); // Drop to re-parent document diff --git a/app/components/Sidebar/components/EditableTitle.tsx b/app/components/Sidebar/components/EditableTitle.tsx index 8a35a0c481..7872871644 100644 --- a/app/components/Sidebar/components/EditableTitle.tsx +++ b/app/components/Sidebar/components/EditableTitle.tsx @@ -41,16 +41,6 @@ function EditableTitle( setIsEditing(true); }, []); - const handleKeyDown = React.useCallback( - (event) => { - if (event.key === "Escape") { - setIsEditing(false); - setValue(originalValue); - } - }, - [originalValue] - ); - const stopPropagation = React.useCallback((event) => { event.preventDefault(); event.stopPropagation(); @@ -63,6 +53,7 @@ function EditableTitle( const handleSave = React.useCallback( async (ev) => { ev.preventDefault(); + ev.stopPropagation(); setIsEditing(false); const trimmedValue = value.trim(); @@ -85,6 +76,22 @@ function EditableTitle( [originalValue, value, onSubmit] ); + const handleKeyDown = React.useCallback( + async (ev) => { + if (ev.nativeEvent.isComposing) { + return; + } + if (ev.key === "Escape") { + setIsEditing(false); + setValue(originalValue); + } + if (ev.key === "Enter") { + await handleSave(ev); + } + }, + [handleSave, originalValue] + ); + React.useEffect(() => { onEditing?.(isEditing); }, [onEditing, isEditing]);