import { useContext } from "preact/hooks";
import FNote from "../../entities/fnote";
import { t } from "../../services/i18n";
import { downloadFileNote, openNoteExternally } from "../../services/open";
import server from "../../services/server";
import toast from "../../services/toast";
import { clearBrowserCache, formatSize } from "../../services/utils";
import Button from "../react/Button";
import { FormFileUploadButton } from "../react/FormFileUpload";
import { useNoteBlob, useNoteLabel } from "../react/hooks";
import { ParentComponent } from "../react/react_utils";
import { TabContext } from "./ribbon-interface";
export default function ImagePropertiesTab({ note, ntxId }: TabContext) {
const [ originalFileName ] = useNoteLabel(note, "originalFileName");
const blob = useNoteBlob(note);
const parentComponent = useContext(ParentComponent);
return (
{note && (
<>
{t("image_properties.original_file_name")}:{" "}
{originalFileName ?? "?"}
{t("image_properties.file_type")}:{" "}
{note.mime}
{t("image_properties.file_size")}:{" "}
{formatSize(blob?.contentLength)}
>
)}
);
}
export function buildUploadNewImageRevisionListener(note: FNote) {
return async (files: FileList | null) => {
if (!files) return;
const fileToUpload = files[0]; // copy to allow reset below
const result = await server.upload(`images/${note.noteId}`, fileToUpload);
if (result.uploaded) {
toast.showMessage(t("image_properties.upload_success"));
await clearBrowserCache();
} else {
toast.showError(t("image_properties.upload_failed", { message: result.message }));
}
};
}