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
client/image compression tool: integrate into the image viewer
Adorian Doran0c48c3c858a3
diff --git a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsxindex c9e031863f..703e18ed54 100644--- a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx+++ b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx@@ -10,6 +10,7 @@ import Button from "../react/Button";import { FormFileUploadButton } from "../react/FormFileUpload";import { useNoteBlob, useNoteLabel } from "../react/hooks";import { ParentComponent } from "../react/react_utils";+import { showImageCompressionDialog } from "../type_widgets/options/content_manager/space_usage/image_compression_dialog";import { TabContext } from "./ribbon-interface";export default function ImagePropertiesTab({ note, ntxId }: TabContext) {@@ -53,6 +54,12 @@ export default function ImagePropertiesTab({ note, ntxId }: TabContext) {onClick={() => openNoteExternally(note.noteId, note.mime)}/>+ <Button+ text={t("compress-image")}+ icon="bx bx-collapse-alt"+ onClick={() => void showImageCompressionDialog({ type: "note", noteId: note.noteId, mime: note.mime })}+ />+<Buttontext={t("image_properties.copy_reference_to_clipboard")}icon="bx bx-copy"diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsxindex f1230a6295..53c59aad9b 100644--- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx+++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx@@ -19,6 +19,7 @@ import { FormFileUploadActionButton, FormFileUploadFormListItem, FormFileUploadPimport { FormListItem } from "../react/FormList";import { useEffectiveReadOnly, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";import { isSplitEditorForcedReadOnly, resolveDisplayMode } from "../type_widgets/helpers/split_editor_mode";+import { showImageCompressionDialog } from "../type_widgets/options/content_manager/space_usage/image_compression_dialog";import { ParentComponent } from "../react/react_utils";import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";import { buildUploadNewImageRevisionListener } from "./ImagePropertiesTab";@@ -113,6 +114,7 @@ function ImageActions(props: NoteActionsCustomInnerProps) {<UploadNewRevisionButton {...props} onChange={buildUploadNewImageRevisionListener(props.note)} /><OpenExternallyButton {...props} /><DownloadFileButton {...props} />+ <CompressImageButton {...props} /></>);}@@ -143,6 +145,21 @@ function OpenExternallyButton({ note, noteMime }: NoteActionsCustomInnerProps) {);}+/**+ * Shrinks the picture being looked at, and only it — the mime is what tells the dialog it is aimed+ * at one image rather than at everything a note holds.+ */+function CompressImageButton({ note, noteMime }: NoteActionsCustomInnerProps) {+ return (+ <NoteAction+ icon="bx bx-collapse-alt"+ text={t("compress-image")}+ disabled={!note.isContentAvailable()}+ onClick={() => void showImageCompressionDialog({ type: "note", noteId: note.noteId, mime: noteMime })}+ />+ );+}+function DownloadFileButton({ note, parentComponent, ntxId }: NoteActionsCustomInnerProps) {return (<NoteAction