2025-12-14 22:50:26 +02:00
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
|
|
2025-12-14 22:16:54 +02:00
|
|
|
import FNote from "../../entities/fnote";
|
|
|
|
|
import { t } from "../../services/i18n";
|
|
|
|
|
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
|
|
|
|
import ActionButton from "../react/ActionButton";
|
|
|
|
|
import { FormFileUploadActionButton } from "../react/FormFileUpload";
|
2025-12-14 22:50:26 +02:00
|
|
|
import { ParentComponent } from "../react/react_utils";
|
2025-12-14 22:16:54 +02:00
|
|
|
import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";
|
2025-12-14 22:45:23 +02:00
|
|
|
import { buildUploadNewImageRevisionListener } from "./ImagePropertiesTab";
|
2025-12-14 22:16:54 +02:00
|
|
|
|
2025-12-14 22:22:41 +02:00
|
|
|
interface NoteActionsCustomProps {
|
|
|
|
|
note: FNote;
|
2025-12-14 22:50:26 +02:00
|
|
|
ntxId: string;
|
2025-12-14 22:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-14 22:16:54 +02:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2025-12-14 22:50:26 +02:00
|
|
|
export default function NoteActionsCustom(props: NoteActionsCustomProps) {
|
2025-12-14 22:16:54 +02:00
|
|
|
return (
|
2025-12-14 22:22:41 +02:00
|
|
|
<div className="note-actions-custom">
|
2025-12-14 22:50:26 +02:00
|
|
|
<NoteActionsCustomInner {...props} />
|
2025-12-14 22:22:41 +02:00
|
|
|
</div>
|
2025-12-14 22:16:54 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 22:45:23 +02:00
|
|
|
//#region Note type mappings
|
2025-12-14 22:22:41 +02:00
|
|
|
function NoteActionsCustomInner(props: NoteActionsCustomProps) {
|
|
|
|
|
switch (props.note.type) {
|
|
|
|
|
case "file":
|
|
|
|
|
return <FileActions {...props} />;
|
2025-12-14 22:45:23 +02:00
|
|
|
case "image":
|
|
|
|
|
return <ImageActions {...props} />;
|
2025-12-14 22:22:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 22:50:26 +02:00
|
|
|
function FileActions(props: NoteActionsCustomProps) {
|
2025-12-14 22:45:23 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2025-12-14 22:50:26 +02:00
|
|
|
<UploadNewRevisionButton {...props} onChange={buildUploadNewFileRevisionListener(props.note)} />
|
|
|
|
|
<OpenExternallyButton {...props} />
|
|
|
|
|
<DownloadFileButton {...props} />
|
2025-12-14 22:45:23 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-14 22:16:54 +02:00
|
|
|
|
2025-12-14 22:50:26 +02:00
|
|
|
function ImageActions(props: NoteActionsCustomProps) {
|
2025-12-14 22:22:41 +02:00
|
|
|
return (
|
2025-12-14 22:16:54 +02:00
|
|
|
<>
|
2025-12-14 22:50:26 +02:00
|
|
|
<CopyReferenceToClipboardButton {...props} />
|
|
|
|
|
<UploadNewRevisionButton {...props} onChange={buildUploadNewImageRevisionListener(props.note)} />
|
|
|
|
|
<OpenExternallyButton {...props} />
|
|
|
|
|
<DownloadFileButton {...props} />
|
2025-12-14 22:16:54 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-14 22:45:23 +02:00
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region Shared buttons
|
|
|
|
|
function UploadNewRevisionButton({ note, onChange }: NoteActionsCustomProps & {
|
|
|
|
|
onChange: (files: FileList | null) => void;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<FormFileUploadActionButton
|
|
|
|
|
icon="bx bx-folder-open"
|
|
|
|
|
text={t("image_properties.upload_new_revision")}
|
2025-12-14 22:51:50 +02:00
|
|
|
disabled={!note.isContentAvailable()}
|
2025-12-14 22:45:23 +02:00
|
|
|
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) {
|
|
|
|
|
return (
|
|
|
|
|
<ActionButton
|
|
|
|
|
icon="bx bx-download"
|
|
|
|
|
text={t("file_properties.download")}
|
2025-12-14 22:51:50 +02:00
|
|
|
disabled={!note.isContentAvailable()}
|
2025-12-14 22:45:23 +02:00
|
|
|
onClick={() => downloadFileNote(note.noteId)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-14 22:50:26 +02:00
|
|
|
|
|
|
|
|
function CopyReferenceToClipboardButton({ ntxId }: NoteActionsCustomProps) {
|
|
|
|
|
const parentComponent = useContext(ParentComponent);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ActionButton
|
|
|
|
|
text={t("image_properties.copy_reference_to_clipboard")}
|
|
|
|
|
icon="bx bx-copy"
|
|
|
|
|
onClick={() => parentComponent?.triggerEvent("copyImageReferenceToClipboard", { ntxId })}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-14 22:45:23 +02:00
|
|
|
//#endregion
|