mirror of
https://github.com/zadam/trilium.git
synced 2025-12-20 15:19:56 +01:00
refactor(layout): extract file actions to separate file
This commit is contained in:
46
apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
Normal file
46
apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import FNote from "../../entities/fnote";
|
||||
import { t } from "../../services/i18n";
|
||||
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
||||
import protected_session_holder from "../../services/protected_session_holder";
|
||||
import ActionButton from "../react/ActionButton";
|
||||
import { FormFileUploadActionButton } from "../react/FormFileUpload";
|
||||
import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";
|
||||
|
||||
/**
|
||||
* Part of {@link NoteActions} on the new layout, but are rendered with a slight spacing
|
||||
* from the rest of the note items and the buttons differ based on the note type.
|
||||
*/
|
||||
export default function NoteActionsCustom({ note }: { note: FNote }) {
|
||||
return (
|
||||
<FileActions note={note} />
|
||||
);
|
||||
}
|
||||
|
||||
function FileActions({ note }: { note: FNote }) {
|
||||
const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable();
|
||||
|
||||
return (note.type === "file" &&
|
||||
<>
|
||||
<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)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user