mirror of
https://github.com/zadam/trilium.git
synced 2025-12-20 15:19:56 +01:00
feat(layout): integrate file-similar options to image
This commit is contained in:
@@ -5,6 +5,7 @@ import protected_session_holder from "../../services/protected_session_holder";
|
||||
import ActionButton from "../react/ActionButton";
|
||||
import { FormFileUploadActionButton } from "../react/FormFileUpload";
|
||||
import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";
|
||||
import { buildUploadNewImageRevisionListener } from "./ImagePropertiesTab";
|
||||
|
||||
interface NoteActionsCustomProps {
|
||||
note: FNote;
|
||||
@@ -22,38 +23,74 @@ export default function NoteActionsCustom({ note }: NoteActionsCustomProps) {
|
||||
);
|
||||
}
|
||||
|
||||
//#region Note type mappings
|
||||
function NoteActionsCustomInner(props: NoteActionsCustomProps) {
|
||||
switch (props.note.type) {
|
||||
case "file":
|
||||
return <FileActions {...props} />;
|
||||
case "image":
|
||||
return <ImageActions {...props} />;
|
||||
}
|
||||
}
|
||||
|
||||
function FileActions({ note }: NoteActionsCustomProps) {
|
||||
const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable();
|
||||
|
||||
return (
|
||||
<>
|
||||
<FormFileUploadActionButton
|
||||
icon="bx bx-folder-open"
|
||||
text={t("file_properties.upload_new_revision")}
|
||||
disabled={!canAccessProtectedNote}
|
||||
onChange={buildUploadNewFileRevisionListener(note)}
|
||||
/>
|
||||
|
||||
<ActionButton
|
||||
icon="bx bx-link-external"
|
||||
text={t("file_properties.open")}
|
||||
disabled={note.isProtected}
|
||||
onClick={() => openNoteExternally(note.noteId, note.mime)}
|
||||
/>
|
||||
|
||||
<ActionButton
|
||||
icon="bx bx-download"
|
||||
text={t("file_properties.download")}
|
||||
disabled={!canAccessProtectedNote}
|
||||
onClick={() => downloadFileNote(note.noteId)}
|
||||
/>
|
||||
<UploadNewRevisionButton note={note} onChange={buildUploadNewFileRevisionListener(note)} />
|
||||
<OpenExternallyButton note={note} />
|
||||
<DownloadFileButton note={note} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ImageActions({ note }: NoteActionsCustomProps) {
|
||||
return (
|
||||
<>
|
||||
<UploadNewRevisionButton note={note} onChange={buildUploadNewImageRevisionListener(note)} />
|
||||
<OpenExternallyButton note={note} />
|
||||
<DownloadFileButton note={note} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region Shared buttons
|
||||
function UploadNewRevisionButton({ note, onChange }: NoteActionsCustomProps & {
|
||||
onChange: (files: FileList | null) => void;
|
||||
}) {
|
||||
const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable();
|
||||
|
||||
return (
|
||||
<FormFileUploadActionButton
|
||||
icon="bx bx-folder-open"
|
||||
text={t("image_properties.upload_new_revision")}
|
||||
disabled={!canAccessProtectedNote}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function OpenExternallyButton({ note }: NoteActionsCustomProps) {
|
||||
return (
|
||||
<ActionButton
|
||||
icon="bx bx-link-external"
|
||||
text={t("file_properties.open")}
|
||||
disabled={note.isProtected}
|
||||
onClick={() => openNoteExternally(note.noteId, note.mime)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DownloadFileButton({ note }: NoteActionsCustomProps) {
|
||||
const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable();
|
||||
|
||||
return (
|
||||
<ActionButton
|
||||
icon="bx bx-download"
|
||||
text={t("file_properties.download")}
|
||||
disabled={!canAccessProtectedNote}
|
||||
onClick={() => downloadFileNote(note.noteId)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
Reference in New Issue
Block a user