diff --git a/app/components/IconPicker/index.tsx b/app/components/IconPicker/index.tsx index a1261942ee..c087673f21 100644 --- a/app/components/IconPicker/index.tsx +++ b/app/components/IconPicker/index.tsx @@ -82,6 +82,7 @@ const IconPicker = ({ modal: true, unstable_offset: [0, 0], }); + const { hide, show, visible } = popover; const tab = useTabState({ selectedId: defaultTab }); const previouslyVisible = usePrevious(popover.visible); @@ -96,12 +97,12 @@ const IconPicker = ({ const handleIconChange = React.useCallback( (ic: string) => { - popover.hide(); + hide(); const icType = determineIconType(ic); const finalColor = icType === IconType.SVG ? chosenColor : null; onChange(ic, finalColor); }, - [popover, onChange, chosenColor] + [hide, onChange, chosenColor] ); const handleIconColorChange = React.useCallback( @@ -118,32 +119,32 @@ const IconPicker = ({ ); const handleIconRemove = React.useCallback(() => { - popover.hide(); + hide(); onChange(null, null); - }, [popover, onChange]); + }, [hide, onChange]); const handlePopoverButtonClick = React.useCallback( (ev: React.MouseEvent) => { ev.stopPropagation(); - if (popover.visible) { - popover.hide(); + if (visible) { + hide(); } else { - popover.show(); + show(); } }, - [popover] + [hide, show, visible] ); // Popover open effect React.useEffect(() => { - if (popover.visible && !previouslyVisible) { + if (visible && !previouslyVisible) { onOpen?.(); - } else if (!popover.visible && previouslyVisible) { + } else if (!visible && previouslyVisible) { onClose?.(); setQuery(""); resetDefaultTab(); } - }, [popover.visible, previouslyVisible, onOpen, onClose, resetDefaultTab]); + }, [visible, previouslyVisible, onOpen, onClose, resetDefaultTab]); // Custom click outside handling rather than using `hideOnClickOutside` from reakit so that we can // prevent event bubbling. diff --git a/app/components/Notifications/Notifications.tsx b/app/components/Notifications/Notifications.tsx index 95f68d6870..9754e4c43c 100644 --- a/app/components/Notifications/Notifications.tsx +++ b/app/components/Notifications/Notifications.tsx @@ -24,13 +24,15 @@ import NotificationListItem from "./NotificationListItem"; type Props = { /** Callback when the notification panel wants to close. */ onRequestClose: () => void; + /** Whether the panel is open or not. */ + isOpen: boolean; }; /** * A panel containing a list of notifications and controls to manage them. */ function Notifications( - { onRequestClose }: Props, + { onRequestClose, isOpen }: Props, ref: React.RefObject ) { const context = useActionContext(); @@ -72,7 +74,7 @@ function Notifications( ( { shrink flex > - + ); diff --git a/app/components/Sidebar/Sidebar.tsx b/app/components/Sidebar/Sidebar.tsx index bff82e4072..924ab83b33 100644 --- a/app/components/Sidebar/Sidebar.tsx +++ b/app/components/Sidebar/Sidebar.tsx @@ -217,15 +217,7 @@ const Sidebar = React.forwardRef(function _Sidebar( /> } > - - {(rest: SidebarButtonProps) => ( - } - /> - )} - + )} @@ -240,6 +232,14 @@ const Sidebar = React.forwardRef(function _Sidebar( ); }); +const Notifications = () => ( + + {(rest: SidebarButtonProps) => ( + } /> + )} + +); + const Backdrop = styled.a` animation: ${fadeIn} 250ms ease-in-out; position: fixed; diff --git a/app/components/Sidebar/components/CollectionLink.tsx b/app/components/Sidebar/components/CollectionLink.tsx index abbe9b9d60..52b6d89079 100644 --- a/app/components/Sidebar/components/CollectionLink.tsx +++ b/app/components/Sidebar/components/CollectionLink.tsx @@ -112,6 +112,10 @@ const CollectionLink: React.FC = ({ sidebarContext, }); + const handleRename = React.useCallback(() => { + editableTitleRef.current?.setIsEditing(true); + }, [editableTitleRef]); + return ( @@ -157,7 +161,7 @@ const CollectionLink: React.FC = ({ editableTitleRef.current?.setIsEditing(true)} + onRename={handleRename} onOpen={handleMenuOpen} onClose={handleMenuClose} /> diff --git a/app/scenes/Document/components/CommentEditor.tsx b/app/scenes/Document/components/CommentEditor.tsx index 32394baff3..b0c1dc8ebc 100644 --- a/app/scenes/Document/components/CommentEditor.tsx +++ b/app/scenes/Document/components/CommentEditor.tsx @@ -1,3 +1,4 @@ +import { observer } from "mobx-react"; import * as React from "react"; import { basicExtensions, withComments } from "@shared/editor/nodes"; import HardBreak from "@shared/editor/nodes/HardBreak"; @@ -36,4 +37,4 @@ const CommentEditor = ( ); }; -export default React.forwardRef(CommentEditor); +export default observer(React.forwardRef(CommentEditor)); diff --git a/app/scenes/Document/components/CommentThread.tsx b/app/scenes/Document/components/CommentThread.tsx index a38833b341..04865bb181 100644 --- a/app/scenes/Document/components/CommentThread.tsx +++ b/app/scenes/Document/components/CommentThread.tsx @@ -192,8 +192,8 @@ function CommentThread({ editor?.removeComment(comment.id)} - onUpdate={(attrs) => editor?.updateComment(comment.id, attrs)} + onDelete={editor?.removeComment} + onUpdate={editor?.updateComment} key={comment.id} firstOfThread={index === 0} lastOfThread={index === commentsInThread.length - 1 && !draft} diff --git a/app/scenes/Document/components/CommentThreadItem.tsx b/app/scenes/Document/components/CommentThreadItem.tsx index 6a9123b533..5b24906e45 100644 --- a/app/scenes/Document/components/CommentThreadItem.tsx +++ b/app/scenes/Document/components/CommentThreadItem.tsx @@ -76,9 +76,9 @@ type Props = { /** Whether the user can reply in the thread */ canReply: boolean; /** Callback when the comment has been deleted */ - onDelete: () => void; + onDelete?: (id: string) => void; /** Callback when the comment has been updated */ - onUpdate: (attrs: { resolved: boolean }) => void; + onUpdate?: (id: string, attrs: { resolved: boolean }) => void; /** Text to highlight at the top of the comment */ highlightedText?: string; }; @@ -106,15 +106,29 @@ function CommentThreadItem({ const [isEditing, setEditing, setReadOnly] = useBoolean(); const formRef = React.useRef(null); - const handleChange = (value: (asString: boolean) => ProsemirrorData) => { - setData(value(false)); - }; + const handleUpdate = React.useCallback( + (attrs: { resolved: boolean }) => { + onUpdate?.(comment.id, attrs); + }, + [comment.id, onUpdate] + ); - const handleSave = () => { + const handleDelete = React.useCallback(() => { + onDelete?.(comment.id); + }, [comment.id, onDelete]); + + const handleChange = React.useCallback( + (value: (asString: boolean) => ProsemirrorData) => { + setData(value(false)); + }, + [] + ); + + const handleSave = React.useCallback(() => { formRef.current?.dispatchEvent( new Event("submit", { cancelable: true, bubbles: true }) ); - }; + }, []); const handleSubmit = action(async (event: React.FormEvent) => { event.preventDefault(); @@ -202,8 +216,8 @@ function CommentThreadItem({ )} diff --git a/app/scenes/Document/components/Editor.tsx b/app/scenes/Document/components/Editor.tsx index 929b4d2d39..304b33fce1 100644 --- a/app/scenes/Document/components/Editor.tsx +++ b/app/scenes/Document/components/Editor.tsx @@ -193,6 +193,16 @@ function DocumentEditor(props: Props, ref: React.RefObject) { [childOffsetHeight] ); + const handleInit = React.useCallback( + () => setEditorInitialized(true), + [setEditorInitialized] + ); + + const handleDestroy = React.useCallback( + () => setEditorInitialized(false), + [setEditorInitialized] + ); + return ( ) { ? handleRemoveComment : undefined } - onInit={() => setEditorInitialized(true)} - onDestroy={() => setEditorInitialized(false)} + onInit={handleInit} + onDestroy={handleDestroy} onChange={updateDocState} extensions={extensions} editorStyle={editorStyle}