diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx index d42617dae..9c6f656d4 100644 --- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx +++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useState } from "preact/hooks"; +import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useState } from "preact/hooks"; import Dropdown from "../react/Dropdown"; import { NOTE_TYPES } from "../../services/note_types"; import { FormDropdownDivider, FormListBadge, FormListItem } from "../react/FormList"; @@ -28,7 +28,7 @@ const isNewLayout = isExperimentalFeatureEnabled("new-layout"); export default function BasicPropertiesTab({ note }: TabContext) { return (
- + {!isNewLayout && } {!isNewLayout && } {!isNewLayout && } {!isNewLayout && } @@ -40,18 +40,42 @@ export default function BasicPropertiesTab({ note }: TabContext) { } 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.loadMimeTypes(); - return 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 [ modalShown, setModalShown ] = useState(false); + return ( +
+ {t("basic_properties.note_type")}:   + {findTypeTitle(currentNoteType, currentNoteMime)}} + disabled={notSelectableNoteTypes.includes(currentNoteType ?? "text")} + > + + + + setModalShown(false)} + size="xl" scrollable + > + + +
+ ); +} + +export function NoteTypeDropdownContent({ currentNoteType, currentNoteMime, note, setModalShown }: { currentNoteType?: NoteType, currentNoteMime?: string | null, note?: FNote | null, setModalShown: Dispatch> }) { + const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes"); + const noteTypes = useMemo(() => NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static), []); + const mimeTypes = useMemo(() => { + mime_types.loadMimeTypes(); + return mime_types.getMimeTypes().filter(mimeType => mimeType.enabled); + }, [ codeNotesMimeTypes ]); const changeNoteType = useCallback(async (type: NoteType, mime?: string) => { if (!note || (type === currentNoteType && mime === currentNoteMime)) { return; @@ -71,70 +95,54 @@ function NoteTypeWidget({ note }: { note?: FNote | null }) { }, [ 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") - }); - } + <> + {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 ( + const checked = (type === currentNoteType); + if (type !== "code") { + return ( + changeNoteType(type, mime)} + >{title} + ); + } else { + return ( + <> + changeNoteType(type, mime)} - >{title} - ); - } else { - return ( - <> - - - {title} - - - ) - } - })} + disabled + > + {title} + + + ); + } + })} - {mimeTypes.map(({ title, mime }) => ( - changeNoteType("code", mime)}> - {title} - - ))} + {mimeTypes.map(({ title, mime }) => ( + changeNoteType("code", mime)}> + {title} + + ))} - - setModalShown(true)}>{t("basic_properties.configure_code_notes")} - - - setModalShown(false)} - size="xl" scrollable - > - - -
+ + setModalShown(true)}>{t("basic_properties.configure_code_notes")} + ) } diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx index 282bb6b9c..515535ba8 100644 --- a/apps/client/src/widgets/ribbon/NoteActions.tsx +++ b/apps/client/src/widgets/ribbon/NoteActions.tsx @@ -1,5 +1,5 @@ import { ConvertToAttachmentResponse } from "@triliumnext/commons"; -import { useContext } from "preact/hooks"; +import { useContext, useState } from "preact/hooks"; import appContext, { CommandNames } from "../../components/app_context"; import NoteContext from "../../components/note_context"; @@ -17,7 +17,7 @@ import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListTogglea import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumOption } from "../react/hooks"; import { ParentComponent } from "../react/react_utils"; import { isExperimentalFeatureEnabled } from "../../services/experimental_features"; -import { useNoteBookmarkState, useShareState } from "./BasicPropertiesTab"; +import { NoteTypeDropdownContent, useNoteBookmarkState, useShareState } from "./BasicPropertiesTab"; import protected_session from "../../services/protected_session"; const isNewLayout = isExperimentalFeatureEnabled("new-layout"); @@ -148,6 +148,8 @@ function NoteBasicProperties({ note }: { note: FNote }) { title={t("protect_note.toggle-on")} currentValue={!!isProtected} onChange={shouldProtect => protected_session.protectNote(note.noteId, shouldProtect, false)} /> + + ; } @@ -169,6 +171,18 @@ function EditabilityDropdown({ note }: { note: FNote }) { ); } +function NoteTypeDropdown({ note }: { note: FNote }) { + const currentNoteType = useNoteProperty(note, "type") ?? undefined; + const currentNoteMime = useNoteProperty(note, "mime"); + const [ modalShown, setModalShown ] = useState(false); + + return ( + + + + ); +} + function DevelopmentActions({ note, noteContext }: { note: FNote, noteContext?: NoteContext }) { return (