mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(core): sync list titles in sidebar (#6157)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { KeyboardEvent } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import Input from '../../ui/input';
|
||||
import { Menu } from '../../ui/menu';
|
||||
@@ -15,10 +16,24 @@ export const RenameModal = ({
|
||||
currentName: string;
|
||||
}) => {
|
||||
const [value, setValue] = useState(currentName);
|
||||
|
||||
const handleRename = useCallback(() => {
|
||||
onRename(value);
|
||||
onOpenChange(false);
|
||||
}, [onOpenChange, onRename, value]);
|
||||
|
||||
const onKeyDown = useCallback(
|
||||
(e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key !== 'Escape') return;
|
||||
if (currentName !== value) setValue(currentName);
|
||||
onOpenChange(false);
|
||||
},
|
||||
[currentName, value, onOpenChange]
|
||||
);
|
||||
|
||||
// Synchronize when the title is changed in the page header or title.
|
||||
useEffect(() => setValue(currentName), [currentName]);
|
||||
|
||||
return (
|
||||
<Menu
|
||||
rootOptions={{
|
||||
@@ -33,9 +48,10 @@ export const RenameModal = ({
|
||||
items={
|
||||
<Input
|
||||
autoFocus
|
||||
defaultValue={value}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
onEnter={handleRename}
|
||||
onKeyDown={onKeyDown}
|
||||
data-testid="rename-modal-input"
|
||||
style={{ width: 220, height: 34 }}
|
||||
/>
|
||||
|
||||
@@ -118,7 +118,7 @@ export const OperationItems = ({
|
||||
: []),
|
||||
|
||||
{
|
||||
element: <MenuSeparator />,
|
||||
element: <MenuSeparator key="menu-separator" />,
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
|
||||
Reference in New Issue
Block a user