import { useCallback, useMemo } from "preact/hooks"; import Dropdown from "../react/Dropdown"; import { NOTE_TYPES } from "../../services/note_types"; import { FormDivider, FormListBadge, FormListItem } from "../react/FormList"; import { t } from "../../services/i18n"; import { useNoteContext, useNoteProperty, useTriliumOption } from "../react/hooks"; import mime_types from "../../services/mime_types"; import { NoteType } from "@triliumnext/commons"; import server from "../../services/server"; import dialog from "../../services/dialog"; import FormToggle from "../react/FormToggle"; import FNote from "../../entities/fnote"; import protected_session from "../../services/protected_session"; export default function BasicPropertiesTab() { const { note } = useNoteContext(); return (
); } function NoteTypeWidget({ note }: { note?: FNote | null }) { const noteTypes = useMemo(() => NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static), []); const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes"); const mimeTypes = useMemo(() => mime_types.getMimeTypes().filter(mimeType => mimeType.enabled), [ codeNotesMimeTypes ]); const notSelectableNoteTypes = useMemo(() => NOTE_TYPES.filter((nt) => nt.reserved || nt.static).map((nt) => nt.type), []); const currentNoteType = useNoteProperty(note, "type") ?? undefined; const currentNoteMime = useNoteProperty(note, "mime"); const changeNoteType = useCallback(async (type: NoteType, mime?: string) => { if (!note || (type === currentNoteType && mime === currentNoteMime)) { return; } // Confirm change if the note already has a content. if (type !== currentNoteType) { const blob = await note.getBlob(); if (blob?.content && blob.content.trim().length && !await (dialog.confirm(t("note_types.confirm-change")))) { return; } } await server.put(`notes/${note.noteId}/type`, { type, mime }); }, [ note, currentNoteType, currentNoteMime ]); return (
{t("basic_properties.note_type")}:   {findTypeTitle(currentNoteType, currentNoteMime)}} disabled={notSelectableNoteTypes.includes(currentNoteType ?? "text")} > {noteTypes.map(({ isNew, isBeta, type, mime, title }) => { const badges: FormListBadge[] = []; if (isNew) { badges.push({ className: "new-note-type-badge", text: t("note_types.new-feature") }); } if (isBeta) { badges.push({ text: t("note_types.beta-feature") }); } const checked = (type === currentNoteType); if (type !== "code") { return ( changeNoteType(type, mime)} >{title} ); } else { return ( <> {title} ) } })} {mimeTypes.map(({ title, mime }) => ( changeNoteType("code", mime)}> {title} ))}
) } function ProtectedNoteSwitch({ note }: { note?: FNote | null }) { const isProtected = useNoteProperty(note, "isProtected"); return (
note && protected_session.protectNote(note.noteId, shouldProtect, false)} switchOnName={t("protect_note.toggle-on")} switchOnTooltip={t("protect_note.toggle-on-hint")} switchOffName={t("protect_note.toggle-off")} switchOffTooltip={t("protect_note.toggle-off-hint")} />
) } function findTypeTitle(type?: NoteType, mime?: string | null) { if (type === "code") { const mimeTypes = mime_types.getMimeTypes(); const found = mimeTypes.find((mt) => mt.mime === mime); return found ? found.title : mime; } else { const noteType = NOTE_TYPES.find((nt) => nt.type === type); return noteType ? noteType.title : type; } }