Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(import): add a "Shrink images" toggle to the provider import dialogs
Elian Doranff451daa50e3
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 984b8bffb2..0664bdff1d 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -223,6 +223,7 @@"explodeArchivesTooltip": "Creates notes from the files inside <code>.zip</code>, <code>.enex</code> and <code>.opml</code> archives. When off, the archives are attached as-is.","explodeArchives": "Read contents of <code>.zip</code>, <code>.enex</code> and <code>.opml</code> archives.","shrinkImagesTooltip": "Scales and optimizes images to save space, which may slightly reduce quality. Doesn't apply to <code>.zip</code> imports with metadata, which are assumed already optimized.",+ "shrinkImagesProviderTooltip": "Scales and optimizes imported images to save space, which may slightly reduce quality.","shrinkImages": "Shrink images","textImportedAsText": "Import HTML, Markdown and TXT as text notes if it's unclear from metadata","codeImportedAsCode": "Import recognized code files (e.g. <code>.json</code>) as code notes if it's unclear from metadata",diff --git a/apps/client/src/widgets/dialogs/import/anytype.tsx b/apps/client/src/widgets/dialogs/import/anytype.tsxindex e6363234fc..67ce1102f9 100644--- a/apps/client/src/widgets/dialogs/import/anytype.tsx+++ b/apps/client/src/widgets/dialogs/import/anytype.tsx@@ -5,11 +5,15 @@ import importService from "../../../services/import.js";import Button from "../../react/Button.js";import { Card, CardSection } from "../../react/Card.js";import FileDropZone from "../../react/FileDropZone.js";+import { useTriliumOptionBool } from "../../react/hooks.js";+import OptionsRow, { OptionsRowWithToggle } from "../../type_widgets/options/components/OptionsRow.js";import iconUrl from "./icons/anytype.svg?url";import type { ImportProvider, ImportProviderPanelProps } from "./types.js";function AnytypePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelProps) {const [file, setFile] = useState<File | null>(null);+ const [compressImages] = useTriliumOptionBool("compressImages");+ const [shrinkImages, setShrinkImages] = useState(compressImages);const onChange = useCallback((files: FileList | null) => setFile(files?.[0] ?? null), []);@@ -24,8 +28,8 @@ function AnytypePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPa// uploadFiles surfaces any upload error via its own toast; swallow the rejection so this void-ed// call doesn't raise an unhandled rejection.closeDialog();- await importService.uploadFiles("notes", parentNoteId, [file], { format: "anytype", safeImport: "true", shrinkImages: "false" }).catch(() => {});- }, [file, parentNoteId, closeDialog]);+ await importService.uploadFiles("notes", parentNoteId, [file], { format: "anytype", safeImport: "true", shrinkImages: shrinkImages ? "true" : "false" }).catch(() => {});+ }, [file, shrinkImages, parentNoteId, closeDialog]);// Keep the latest import handler in a ref so the footer effect depends only on `file` being present,// never on doImport's identity — otherwise re-pushing the footer on every change would loop with the@@ -47,8 +51,17 @@ function AnytypePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPareturn (<Card heading={t("anytype_import.choose_file")}><CardSection>- <p className="import-files-description">{t("anytype_import.description_long")}</p>- <FileDropZone onChange={onChange} accept=".zip" />+ <OptionsRow name="import-file" description={t("anytype_import.description_long")} stacked>+ <FileDropZone onChange={onChange} accept=".zip" />+ </OptionsRow>+ <OptionsRowWithToggle+ name="shrink-images"+ label={t("import.shrinkImages")}+ description={t("import.shrinkImagesProviderTooltip")}+ currentValue={compressImages && shrinkImages}+ onChange={setShrinkImages}+ disabled={!compressImages}+ /></CardSection></Card>);diff --git a/apps/client/src/widgets/dialogs/import/evernote.tsx b/apps/client/src/widgets/dialogs/import/evernote.tsxindex 1c2a7a8bb0..567e317a8a 100644--- a/apps/client/src/widgets/dialogs/import/evernote.tsx+++ b/apps/client/src/widgets/dialogs/import/evernote.tsx@@ -5,11 +5,15 @@ import importService from "../../../services/import.js";import Button from "../../react/Button.js";import { Card, CardSection } from "../../react/Card.js";import FileDropZone from "../../react/FileDropZone.js";+import { useTriliumOptionBool } from "../../react/hooks.js";+import OptionsRow, { OptionsRowWithToggle } from "../../type_widgets/options/components/OptionsRow.js";import iconUrl from "./icons/evernote.svg?url";import type { ImportProvider, ImportProviderPanelProps } from "./types.js";function EvernotePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelProps) {const [files, setFiles] = useState<File[]>([]);+ const [compressImages] = useTriliumOptionBool("compressImages");+ const [shrinkImages, setShrinkImages] = useState(compressImages);// An Evernote export is one ENEX (.enex) file per notebook, so allow selecting several at once.const onChange = useCallback((fileList: FileList | null) => setFiles(fileList ? Array.from(fileList) : []), []);@@ -25,8 +29,8 @@ function EvernotePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderP// each file becomes its own notebook root. uploadFiles surfaces upload errors via its own toast,// so swallow the rejection to avoid an unhandled rejection from this void-ed call.closeDialog();- await importService.uploadFiles("notes", parentNoteId, files, { safeImport: "true", shrinkImages: "true" }).catch(() => {});- }, [files, parentNoteId, closeDialog]);+ await importService.uploadFiles("notes", parentNoteId, files, { safeImport: "true", shrinkImages: shrinkImages ? "true" : "false" }).catch(() => {});+ }, [files, shrinkImages, parentNoteId, closeDialog]);// Keep the latest import handler in a ref so the footer effect depends only on whether files are// selected, never on doImport's identity — otherwise re-pushing the footer on every change would loop@@ -48,8 +52,17 @@ function EvernotePanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPreturn (<Card heading={t("evernote_import.choose_file")}><CardSection>- <p className="import-files-description">{t("evernote_import.description_long")}</p>- <FileDropZone multiple onChange={onChange} accept=".enex" />+ <OptionsRow name="import-file" description={t("evernote_import.description_long")} stacked>+ <FileDropZone multiple onChange={onChange} accept=".enex" />+ </OptionsRow>+ <OptionsRowWithToggle+ name="shrink-images"+ label={t("import.shrinkImages")}+ description={t("import.shrinkImagesProviderTooltip")}+ currentValue={compressImages && shrinkImages}+ onChange={setShrinkImages}+ disabled={!compressImages}+ /></CardSection></Card>);diff --git a/apps/client/src/widgets/dialogs/import/keep.tsx b/apps/client/src/widgets/dialogs/import/keep.tsxindex 004fba6d75..670554b86c 100644--- a/apps/client/src/widgets/dialogs/import/keep.tsx+++ b/apps/client/src/widgets/dialogs/import/keep.tsx@@ -5,11 +5,15 @@ import importService from "../../../services/import.js";import Button from "../../react/Button.js";import { Card, CardSection } from "../../react/Card.js";import FileDropZone from "../../react/FileDropZone.js";+import { useTriliumOptionBool } from "../../react/hooks.js";+import OptionsRow, { OptionsRowWithToggle } from "../../type_widgets/options/components/OptionsRow.js";import iconUrl from "./icons/keep.svg?url";import type { ImportProvider, ImportProviderPanelProps } from "./types.js";function KeepPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelProps) {const [file, setFile] = useState<File | null>(null);+ const [compressImages] = useTriliumOptionBool("compressImages");+ const [shrinkImages, setShrinkImages] = useState(compressImages);const onChange = useCallback((files: FileList | null) => setFile(files?.[0] ?? null), []);@@ -24,8 +28,8 @@ function KeepPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanel// uploadFiles surfaces any upload error via its own toast; swallow the rejection so this void-ed// call doesn't raise an unhandled rejection.closeDialog();- await importService.uploadFiles("notes", parentNoteId, [file], { format: "keep", safeImport: "true", shrinkImages: "false" }).catch(() => {});- }, [file, parentNoteId, closeDialog]);+ await importService.uploadFiles("notes", parentNoteId, [file], { format: "keep", safeImport: "true", shrinkImages: shrinkImages ? "true" : "false" }).catch(() => {});+ }, [file, shrinkImages, parentNoteId, closeDialog]);// Keep the latest import handler in a ref so the footer effect depends only on `file` being present,// never on doImport's identity — otherwise re-pushing the footer on every change would loop with the@@ -47,8 +51,17 @@ function KeepPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelreturn (<Card heading={t("keep_import.choose_file")}><CardSection>- <p className="import-files-description">{t("keep_import.description_long")}</p>- <FileDropZone onChange={onChange} accept=".zip" />+ <OptionsRow name="import-file" description={t("keep_import.description_long")} stacked>+ <FileDropZone onChange={onChange} accept=".zip" />+ </OptionsRow>+ <OptionsRowWithToggle+ name="shrink-images"+ label={t("import.shrinkImages")}+ description={t("import.shrinkImagesProviderTooltip")}+ currentValue={compressImages && shrinkImages}+ onChange={setShrinkImages}+ disabled={!compressImages}+ /></CardSection></Card>);diff --git a/apps/client/src/widgets/dialogs/import/notion.tsx b/apps/client/src/widgets/dialogs/import/notion.tsxindex 9d6c79a0ea..b2463452fa 100644--- a/apps/client/src/widgets/dialogs/import/notion.tsx+++ b/apps/client/src/widgets/dialogs/import/notion.tsx@@ -5,11 +5,15 @@ import importService from "../../../services/import.js";import Button from "../../react/Button.js";import { Card, CardSection } from "../../react/Card.js";import FileDropZone from "../../react/FileDropZone.js";+import { useTriliumOptionBool } from "../../react/hooks.js";+import OptionsRow, { OptionsRowWithToggle } from "../../type_widgets/options/components/OptionsRow.js";import iconUrl from "./icons/notion.svg?url";import type { ImportProvider, ImportProviderPanelProps } from "./types.js";function NotionPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelProps) {const [file, setFile] = useState<File | null>(null);+ const [compressImages] = useTriliumOptionBool("compressImages");+ const [shrinkImages, setShrinkImages] = useState(compressImages);const onChange = useCallback((files: FileList | null) => setFile(files?.[0] ?? null), []);@@ -24,8 +28,8 @@ function NotionPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPan// uploadFiles surfaces any upload error via its own toast; swallow the rejection so this void-ed// call doesn't raise an unhandled rejection.closeDialog();- await importService.uploadFiles("notes", parentNoteId, [file], { format: "notion", safeImport: "true", shrinkImages: "false" }).catch(() => {});- }, [file, parentNoteId, closeDialog]);+ await importService.uploadFiles("notes", parentNoteId, [file], { format: "notion", safeImport: "true", shrinkImages: shrinkImages ? "true" : "false" }).catch(() => {});+ }, [file, shrinkImages, parentNoteId, closeDialog]);// Keep the latest import handler in a ref so the footer effect depends only on `file` being present,// never on doImport's identity — otherwise re-pushing the footer on every change would loop with the@@ -47,8 +51,17 @@ function NotionPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanreturn (<Card heading={t("notion_import.choose_file")}><CardSection>- <p className="import-files-description">{t("notion_import.description_long")}</p>- <FileDropZone onChange={onChange} accept=".zip" />+ <OptionsRow name="import-file" description={t("notion_import.description_long")} stacked>+ <FileDropZone onChange={onChange} accept=".zip" />+ </OptionsRow>+ <OptionsRowWithToggle+ name="shrink-images"+ label={t("import.shrinkImages")}+ description={t("import.shrinkImagesProviderTooltip")}+ currentValue={compressImages && shrinkImages}+ onChange={setShrinkImages}+ disabled={!compressImages}+ /></CardSection></Card>);