mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 03:33:06 +08:00
feat(core): use enter change workspace the name (#4007)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -7,7 +7,12 @@ import { IconButton } from '@toeverything/components/button';
|
|||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { useCallback, useState } from 'react';
|
import {
|
||||||
|
type KeyboardEvent,
|
||||||
|
startTransition,
|
||||||
|
useCallback,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
import { Upload } from '../../pure/file-upload';
|
import { Upload } from '../../pure/file-upload';
|
||||||
import { type WorkspaceSettingDetailProps } from './index';
|
import { type WorkspaceSettingDetailProps } from './index';
|
||||||
@@ -38,6 +43,25 @@ export const ProfilePanel = ({ workspace, isOwner }: ProfilePanelProps) => {
|
|||||||
[setName, t]
|
[setName, t]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleSetInput = useCallback((value: string) => {
|
||||||
|
startTransition(() => {
|
||||||
|
setInput(value);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleKeyUp = useCallback(
|
||||||
|
(e: KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (e.code === 'Enter' && name !== input) {
|
||||||
|
handleUpdateWorkspaceName(input);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[handleUpdateWorkspaceName, input, name]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleClick = useCallback(() => {
|
||||||
|
handleUpdateWorkspaceName(input);
|
||||||
|
}, [handleUpdateWorkspaceName, input]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.profileWrapper}>
|
<div className={style.profileWrapper}>
|
||||||
<div className={clsx(style.avatarWrapper, { disable: !isOwner })}>
|
<div className={clsx(style.avatarWrapper, { disable: !isOwner })}>
|
||||||
@@ -69,14 +93,13 @@ export const ProfilePanel = ({ workspace, isOwner }: ProfilePanelProps) => {
|
|||||||
placeholder={t['Workspace Name']()}
|
placeholder={t['Workspace Name']()}
|
||||||
maxLength={64}
|
maxLength={64}
|
||||||
minLength={0}
|
minLength={0}
|
||||||
onChange={setInput}
|
onChange={handleSetInput}
|
||||||
|
onKeyUp={handleKeyUp}
|
||||||
/>
|
/>
|
||||||
{input === workspace.blockSuiteWorkspace.meta.name ? null : (
|
{input === workspace.blockSuiteWorkspace.meta.name ? null : (
|
||||||
<IconButton
|
<IconButton
|
||||||
data-testid="save-workspace-name"
|
data-testid="save-workspace-name"
|
||||||
onClick={() => {
|
onClick={handleClick}
|
||||||
handleUpdateWorkspaceName(input);
|
|
||||||
}}
|
|
||||||
active={true}
|
active={true}
|
||||||
style={{
|
style={{
|
||||||
marginLeft: '12px',
|
marginLeft: '12px',
|
||||||
|
|||||||
Reference in New Issue
Block a user