fix(client/import): file remains from previous instance (closes #7428)

This commit is contained in:
Elian Doran 2025-10-20 20:24:43 +03:00
parent 00720ae58f
commit 8fc7a20220
No known key found for this signature in database
3 changed files with 23 additions and 12 deletions

View File

@ -37,7 +37,7 @@ export default function ImportDialog() {
onSubmit={async () => { onSubmit={async () => {
if (!files || !parentNoteId) { if (!files || !parentNoteId) {
return; return;
} }
const options: UploadFilesOptions = { const options: UploadFilesOptions = {
safeImport: boolToString(safeImport), safeImport: boolToString(safeImport),
@ -51,7 +51,10 @@ export default function ImportDialog() {
setShown(false); setShown(false);
await importService.uploadFiles("notes", parentNoteId, Array.from(files), options); await importService.uploadFiles("notes", parentNoteId, Array.from(files), options);
}} }}
onHidden={() => setShown(false)} onHidden={() => {
setShown(false);
setFiles(null);
}}
footer={<Button text={t("import.import")} primary disabled={!files} />} footer={<Button text={t("import.import")} primary disabled={!files} />}
show={shown} show={shown}
> >
@ -82,7 +85,7 @@ export default function ImportDialog() {
currentValue={codeImportedAsCode} onChange={setCodeImportedAsCode} currentValue={codeImportedAsCode} onChange={setCodeImportedAsCode}
/> />
<FormCheckbox <FormCheckbox
name="replace-underscores-with-spaces" label={t("import.replaceUnderscoresWithSpaces")} name="replace-underscores-with-spaces" label={t("import.replaceUnderscoresWithSpaces")}
currentValue={replaceUnderscoresWithSpaces} onChange={setReplaceUnderscoresWithSpaces} currentValue={replaceUnderscoresWithSpaces} onChange={setReplaceUnderscoresWithSpaces}
/> />
</FormMultiGroup> </FormMultiGroup>
@ -92,4 +95,4 @@ export default function ImportDialog() {
function boolToString(value: boolean) { function boolToString(value: boolean) {
return value ? "true" : "false"; return value ? "true" : "false";
} }

View File

@ -40,14 +40,17 @@ export default function UploadAttachmentsDialog() {
if (!files || !parentNoteId) { if (!files || !parentNoteId) {
return; return;
} }
setIsUploading(true); setIsUploading(true);
const filesCopy = Array.from(files); const filesCopy = Array.from(files);
await importService.uploadFiles("attachments", parentNoteId, filesCopy, { shrinkImages }); await importService.uploadFiles("attachments", parentNoteId, filesCopy, { shrinkImages });
setIsUploading(false); setIsUploading(false);
setShown(false); setShown(false);
}} }}
onHidden={() => setShown(false)} onHidden={() => {
setShown(false);
setFiles(null);
}}
show={shown} show={shown}
> >
<FormGroup name="files" label={t("upload_attachments.choose_files")} description={description}> <FormGroup name="files" label={t("upload_attachments.choose_files")} description={description}>
@ -55,7 +58,7 @@ export default function UploadAttachmentsDialog() {
</FormGroup> </FormGroup>
<FormGroup name="shrink-images" label={t("upload_attachments.options")}> <FormGroup name="shrink-images" label={t("upload_attachments.options")}>
<FormCheckbox <FormCheckbox
hint={t("upload_attachments.tooltip")} label={t("upload_attachments.shrink_images")} hint={t("upload_attachments.tooltip")} label={t("upload_attachments.shrink_images")}
currentValue={shrinkImages} onChange={setShrinkImages} currentValue={shrinkImages} onChange={setShrinkImages}
/> />

View File

@ -1,6 +1,6 @@
import { Ref } from "preact"; import { Ref } from "preact";
import Button, { ButtonProps } from "./Button"; import Button, { ButtonProps } from "./Button";
import { useRef } from "preact/hooks"; import { useEffect, useRef } from "preact/hooks";
interface FormFileUploadProps { interface FormFileUploadProps {
name?: string; name?: string;
@ -11,6 +11,11 @@ interface FormFileUploadProps {
} }
export default function FormFileUpload({ inputRef, name, onChange, multiple, hidden }: FormFileUploadProps) { export default function FormFileUpload({ inputRef, name, onChange, multiple, hidden }: FormFileUploadProps) {
// Prevent accidental reuse of a file selected in a previous instance of the upload form.
useEffect(() => {
onChange(null);
}, []);
return ( return (
<label class="tn-file-input tn-input-field" style={hidden ? { display: "none" } : undefined}> <label class="tn-file-input tn-input-field" style={hidden ? { display: "none" } : undefined}>
<input <input
@ -18,7 +23,7 @@ export default function FormFileUpload({ inputRef, name, onChange, multiple, hid
name={name} name={name}
type="file" type="file"
class="form-control-file" class="form-control-file"
multiple={multiple} multiple={multiple}
onChange={e => onChange((e.target as HTMLInputElement).files)} /> onChange={e => onChange((e.target as HTMLInputElement).files)} />
</label> </label>
) )
@ -26,7 +31,7 @@ export default function FormFileUpload({ inputRef, name, onChange, multiple, hid
/** /**
* Combination of a button with a hidden file upload field. * Combination of a button with a hidden file upload field.
* *
* @param param the change listener for the file upload and the properties for the button. * @param param the change listener for the file upload and the properties for the button.
*/ */
export function FormFileUploadButton({ onChange, ...buttonProps }: Omit<ButtonProps, "onClick"> & Pick<FormFileUploadProps, "onChange">) { export function FormFileUploadButton({ onChange, ...buttonProps }: Omit<ButtonProps, "onClick"> & Pick<FormFileUploadProps, "onChange">) {
@ -39,10 +44,10 @@ export function FormFileUploadButton({ onChange, ...buttonProps }: Omit<ButtonPr
onClick={() => inputRef.current?.click()} onClick={() => inputRef.current?.click()}
/> />
<FormFileUpload <FormFileUpload
inputRef={inputRef} inputRef={inputRef}
hidden hidden
onChange={onChange} onChange={onChange}
/> />
</> </>
) )
} }