fix: make file renaming consistent with tag & note renaming (#920)

This commit is contained in:
Aman Harwara
2022-03-12 19:27:07 +05:30
committed by GitHub
parent 772079338f
commit fc2a350cca

View File

@@ -72,16 +72,14 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
}, [isRenamingFile]);
const renameFile = async (file: SNFile, name: string) => {
const didRename = await handleFileAction({
await handleFileAction({
type: PopoverFileItemActionType.RenameFile,
payload: {
file,
name,
},
});
if (didRename) {
setIsRenamingFile(false);
}
setIsRenamingFile(false);
};
const handleFileNameInput = (event: Event) => {
@@ -90,11 +88,14 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
const handleFileNameInputKeyDown = (event: KeyboardEvent) => {
if (event.key === KeyboardKey.Enter) {
renameFile(file, fileName);
return;
fileNameInputRef.current?.blur();
}
};
const handleFileNameInputBlur = () => {
renameFile(file, fileName);
};
return (
<div className="flex items-center justify-between p-3">
<div className="flex items-center">
@@ -108,6 +109,7 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
ref={fileNameInputRef}
onInput={handleFileNameInput}
onKeyDown={handleFileNameInputKeyDown}
onBlur={handleFileNameInputBlur}
/>
) : (
<div className="text-sm mb-1">{file.nameWithExt}</div>