Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): remove the ribbon's basic properties tab

Elian Doran79c1ec4f4627
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.css
index 0692b4ea68..c760489b57 100644
--- a/apps/client/src/stylesheets/theme-next/forms.css
+++ b/apps/client/src/stylesheets/theme-next/forms.css
@@ -763,8 +763,7 @@ optgroup {
/* Switches */
-.switch-widget.component,
-.note-language-container {
+.switch-widget.component {
--icon-button-size: 28px;
}
diff --git a/apps/client/src/stylesheets/theme-next/ribbon.css b/apps/client/src/stylesheets/theme-next/ribbon.css
index ffba0fcac9..52b090dfe2 100644
--- a/apps/client/src/stylesheets/theme-next/ribbon.css
+++ b/apps/client/src/stylesheets/theme-next/ribbon.css
@@ -88,31 +88,6 @@ div.promoted-attributes-container {
gap: 10px 40px;
}
-/*
- * Basic properties
- */
-
-/* Note type dropdown */
-
-ul.note-type-dropdown .check {
- margin-inline-end: 6px;
-}
-
-ul.note-type-dropdown li.dropdown-item {
- --menu-item-icon-vert-offset: 0;
-}
-
-/* Editability dropdown */
-
-ul.editability-dropdown li.dropdown-item > div {
- margin-inline-start: 4px;
-}
-
-.editability-dropdown .dropdown-item .description {
- opacity: 0.75;
- font-size: 0.85em;
-}
-
/*
* Edited notes (for calendar notes)
*/
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 5d4053c5f1..dd1cbbdfa6 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1282,8 +1282,6 @@
"basic_properties": {
"note_type": "Note type",
"editable": "Editable",
- "basic_properties": "Basic Properties",
- "language": "Language",
"configure_code_notes": "Configure code notes..."
},
"book_properties": {
@@ -2467,9 +2465,7 @@
"importSource": "Import source"
},
"bookmark_switch": {
- "bookmark": "Bookmark",
- "bookmark_this_note": "Bookmark this note to the left side panel",
- "remove_bookmark": "Remove bookmark"
+ "bookmark": "Bookmark"
},
"editability_select": {
"auto": "Auto",
@@ -2585,10 +2581,7 @@
"reorder": "Drag to reorder"
},
"protect_note": {
- "toggle-on": "Protect the note",
- "toggle-off": "Unprotect the note",
- "toggle-on-hint": "Note is not protected, click to make it protected",
- "toggle-off-hint": "Note is protected, click to make it unprotected"
+ "toggle-on": "Protect the note"
},
"llm_chat": {
"placeholder": "Type a message...",
@@ -2735,15 +2728,11 @@
},
"shared_switch": {
"shared": "Shared",
- "toggle-on-title": "Share the note",
- "toggle-off-title": "Unshare the note",
"shared-branch": "This note exists only as a shared note, unsharing would delete it. Do you want to continue and thus delete this note?",
"inherited": "Note cannot be unshared here because it is shared through inheritance from an ancestor."
},
"template_switch": {
- "template": "Template",
- "toggle-on-hint": "Make the note a template",
- "toggle-off-hint": "Remove the note as a template"
+ "template": "Template"
},
"full_content_width_switch": {
"title": "Full width"
diff --git a/apps/client/src/widgets/ribbon/useLanguageSwitcher.spec.tsx b/apps/client/src/widgets/dialogs/content_languages.spec.tsx
similarity index 98%
rename from apps/client/src/widgets/ribbon/useLanguageSwitcher.spec.tsx
rename to apps/client/src/widgets/dialogs/content_languages.spec.tsx
index 352cae36fd..47dbf31473 100644
--- a/apps/client/src/widgets/ribbon/useLanguageSwitcher.spec.tsx
+++ b/apps/client/src/widgets/dialogs/content_languages.spec.tsx
@@ -34,7 +34,7 @@ vi.mock("../../services/i18n", async () => {
});
import options from "../../services/options";
-import { useLanguageSwitcher } from "./BasicPropertiesTab";
+import { useLanguageSwitcher } from "./content_languages";
type Switcher = ReturnType<typeof useLanguageSwitcher>;
diff --git a/apps/client/src/widgets/dialogs/content_languages.tsx b/apps/client/src/widgets/dialogs/content_languages.tsx
index ede213e0c8..cf06ebcf48 100644
--- a/apps/client/src/widgets/dialogs/content_languages.tsx
+++ b/apps/client/src/widgets/dialogs/content_languages.tsx
@@ -1,16 +1,18 @@
-import { useState } from "preact/hooks";
+import { useMemo, useState } from "preact/hooks";
-import { useTriliumEvent } from "../react/hooks.jsx";
-import { ContentLanguagesModal } from "../ribbon/BasicPropertiesTab.jsx";
+import FNote from "../../entities/fnote";
+import { getAvailableLocales, getLocaleById, t } from "../../services/i18n";
+import { resolveContentLanguage } from "../../utils/formatters";
+import { useNoteLabel, useTriliumEvent, useTriliumOption } from "../react/hooks.jsx";
+import Modal from "../react/Modal";
+import { ContentLanguagesList } from "../type_widgets/options/i18n";
/**
* The content-languages modal, summoned by a command rather than owned by whatever offers it.
*
- * The ribbon and the status bar each hold their own copy behind a `useState`, which works because
- * both are components sitting next to the switcher they belong to. The AI assistant's Translate
- * submenu is neither: it is a CKEditor menu and a right-click menu, both built imperatively, with
- * nowhere to hang a modal. So the dialog joins the registry in `layout_commons`, where a command is
- * all it takes to raise one.
+ * The status bar's language switcher holds its own copy behind a `useState`. The AI assistant's
+ * Translate submenu is built imperatively by CKEditor and the context menu, so it has nowhere to
+ * mount a modal; it raises this one with the `showContentLanguagesDialog` command instead.
*/
export default function ContentLanguagesDialog() {
const [ shown, setShown ] = useState(false);
@@ -19,3 +21,62 @@ export default function ContentLanguagesDialog() {
return <ContentLanguagesModal modalShown={shown} setModalShown={setShown} />;
}
+
+export function useLanguageSwitcher(note: FNote | null | undefined) {
+ const [ languages ] = useTriliumOption("languages");
+ // Subscribed to for the re-render alone — the values are read below through
+ // `resolveContentLanguage`, which goes to the options store directly. Without these, changing
+ // the default in the settings would leave the picker naming a stale language until reopened.
+ useTriliumOption("defaultContentLanguage");
+ useTriliumOption("locale");
+
+ /**
+ * The locale a note without a `#language` of its own is actually written in.
+ *
+ * Not memoized: it is a lookup over a two-dozen-entry catalog, and `resolveContentLanguage`
+ * reads the options directly — so the subscriptions above, not a dependency array, are what
+ * make this follow a change to the setting.
+ */
+ const resolvedDefaultLocale = getLocaleById(resolveContentLanguage(null));
+
+ // Naming the resolved language here is the point: the entry used to read "No language set",
+ // which denied the existence of the default that was in fact deciding text direction and
+ // quotation marks. The id stays empty — it is the sentinel that clears the label.
+ const DEFAULT_LOCALE = {
+ id: "",
+ name: resolvedDefaultLocale
+ ? t("note_language.not_set_with_default", { language: resolvedDefaultLocale.name })
+ : t("note_language.not_set")
+ };
+ const [ currentNoteLanguage, setCurrentNoteLanguage ] = useNoteLabel(note, "language");
+ const locales = useMemo(() => {
+ const enabledLanguages = JSON.parse(languages ?? "[]") as string[];
+ const filteredLanguages = getAvailableLocales().filter((l) => typeof l !== "object" || enabledLanguages.includes(l.id));
+ return filteredLanguages;
+ }, [ languages ]);
+
+ /**
+ * The locale the note is actually written in — its own if it has one, the default otherwise.
+ * What the compact displays (the status bar badge, the mobile submenu title) name, so that a
+ * note without a `#language` reads as the language in force rather than as a bare dash.
+ */
+ const effectiveLocale = useMemo(
+ () => (currentNoteLanguage ? getLocaleById(currentNoteLanguage) : resolvedDefaultLocale),
+ [ currentNoteLanguage, resolvedDefaultLocale ]
+ );
+
+ return { locales, DEFAULT_LOCALE, resolvedDefaultLocale, effectiveLocale, currentNoteLanguage, setCurrentNoteLanguage };
+}
+
+export function ContentLanguagesModal({ modalShown, setModalShown }: { modalShown: boolean, setModalShown: (shown: boolean) => void }) {
+ return (
+ <Modal
+ className="content-languages-modal"
+ title={t("content_language.title")}
+ show={modalShown} onHidden={() => setModalShown(false)}
+ size="lg" scrollable
+ >
+ <ContentLanguagesList />
+ </Modal>
+ );
+}
diff --git a/apps/client/src/widgets/layout/NoteBadges.tsx b/apps/client/src/widgets/layout/NoteBadges.tsx
index 51aea38451..c93830509b 100644
--- a/apps/client/src/widgets/layout/NoteBadges.tsx
+++ b/apps/client/src/widgets/layout/NoteBadges.tsx
@@ -2,15 +2,22 @@ import "./NoteBadges.css";
import { isOfficeMimeType } from "@triliumnext/commons";
import { clsx } from "clsx";
-import { useEffect, useState } from "preact/hooks";
+import { useCallback, useEffect, useState } from "preact/hooks";
+import FNote from "../../entities/fnote";
+import branches from "../../services/branches";
import { copyTextWithToast } from "../../services/clipboard_ext";
+import dialog from "../../services/dialog";
import { t } from "../../services/i18n";
import { goToLinkExt } from "../../services/link";
+import server from "../../services/server";
+import sync from "../../services/sync";
import { Badge, BadgeWithDropdown } from "../react/Badge";
import { FormDropdownDivider, FormListItem } from "../react/FormList";
-import { useGetContextDataFrom, useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty } from "../react/hooks";
-import { useShareState } from "../ribbon/BasicPropertiesTab";
+import {
+ useGetContextDataFrom, useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty,
+ useTriliumEvent
+} from "../react/hooks";
import { type ShareScope, useShareInfo } from "../shared_info";
import { ActiveContentBadges } from "./ActiveContentBadges";
import { SnippetBadge } from "./SnippetBadge";
@@ -223,3 +230,37 @@ export function SaveStatusBadge() {
/>
);
}
+
+export function useShareState(note: FNote | null | undefined) {
+ const [ isShared, setIsShared ] = useState(false);
+ const refreshState = useCallback(() => {
+ setIsShared(!!note?.hasAncestor("_share"));
+ }, [ note ]);
+
+ useEffect(() => refreshState(), [ refreshState ]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (note && loadResults.getBranchRows().find((b) => b.noteId === note.noteId)) {
+ refreshState();
+ }
+ });
+
+ const switchShareState = useCallback(async (shouldShare: boolean) => {
+ if (!note) return;
+
+ if (shouldShare) {
+ await branches.cloneNoteToParentNote(note.noteId, "_share");
+ } else {
+ if (note?.getParentBranches().length === 1 && !(await dialog.confirm(t("shared_switch.shared-branch")))) {
+ return;
+ }
+
+ const shareBranch = note?.getParentBranches().find((b) => b.parentNoteId === "_share");
+ if (!shareBranch?.branchId) return;
+ await server.remove(`branches/${shareBranch.branchId}?taskId=no-progress-reporting`);
+ }
+
+ sync.syncNow(true);
+ }, [ note ]);
+
+ return [ isShared, switchShareState ] as const;
+}
diff --git a/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx b/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx
index 6eb2063d61..77d19ed848 100644
--- a/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx
+++ b/apps/client/src/widgets/layout/NoteTypeSwitcher.spec.tsx
@@ -1,3 +1,4 @@
+import type { MimeType } from "@triliumnext/commons";
import { type ComponentChildren, render } from "preact";
import { act } from "preact/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -12,7 +13,7 @@ import server from "../../services/server.js";
import { buildNote } from "../../test/easy-froca.js";
import { noteSavedDataStore } from "../react/NoteStore.js";
import { NoteContextContext, ParentComponent } from "../react/react_utils.js";
-import NoteTypeSwitcher, { NoteTypeBadges, toSwitcherItems, useNoteTypeData } from "./NoteTypeSwitcher.js";
+import NoteTypeSwitcher, { codeLanguageItems, NoteTypeBadges, toSwitcherItems, useNoteTypeData } from "./NoteTypeSwitcher.js";
vi.mock("../../services/i18n.js", () => ({
t: (key: string) => key
@@ -153,6 +154,38 @@ describe("useNoteTypeData", () => {
});
});
+describe("codeLanguageItems", () => {
+ const mimeTypes = [
+ { title: "Plain text", mime: "text/plain", icon: "bx bx-file" },
+ { title: "C++ <templates>", mime: "text/x-c++src" }
+ ] as MimeType[];
+
+ it("lists the languages, ticks the note's own, and ends with the options when asked", () => {
+ const changeNoteType = vi.fn();
+ const onConfigure = vi.fn();
+ const items = codeLanguageItems({ currentMimeType: "text/x-c++src", mimeTypes, changeNoteType, onConfigure });
+
+ // Titles are HTML in a menu, so a language's name is escaped.
+ expect(items.map((item) => ("kind" in item ? item.kind : item.title))).toEqual([
+ "Plain text", "C++ &lt;templates&gt;", "separator", "basic_properties.configure_code_notes"
+ ]);
+ expect(items.map((item) => "checked" in item && item.checked)).toEqual([ false, true, false, false ]);
+ // A language's own icon, or the code note type's when it has none, as the note tree shows it.
+ expect(items.slice(0, 2).map((item) => "uiIcon" in item && item.uiIcon)).toEqual([ "bx bx-file", "bx bx-code" ]);
+
+ const [ plain, , , configure ] = items;
+ if ("kind" in plain || "kind" in configure) throw new Error("expected rows");
+ plain.handler?.(plain, new MouseEvent("click"));
+ expect(changeNoteType).toHaveBeenCalledWith("code", "text/plain");
+ configure.handler?.(configure, new MouseEvent("click"));
+ expect(onConfigure).toHaveBeenCalledTimes(1);
+ expect(configure.uiIcon).toBe("bx bx-cog");
+
+ // Without a way to open the options, there is no row for them.
+ expect(codeLanguageItems({ mimeTypes, changeNoteType })).toHaveLength(2);
+ });
+});
+
function mount(content: ComponentChildren, host = new Component()) {
if (container) {
const mounted = container;
diff --git a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
index 427150d697..ff14941395 100644
--- a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
+++ b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
@@ -1,20 +1,28 @@
import "./NoteTypeSwitcher.css";
-import type { NoteType } from "@triliumnext/commons";
-import { useEffect, useState } from "preact/hooks";
+import { getCodeLanguageIcon, type MimeType, type NoteType } from "@triliumnext/commons";
+import { type Dispatch, type StateUpdater, useCallback, useEffect, useMemo, useState } from "preact/hooks";
import FNote from "../../entities/fnote";
import type { MenuCommandItem, MenuItem } from "../../menus/context_menu";
import type { TreeCommandNames } from "../../menus/tree_context_menu";
import attributes from "../../services/attributes";
+import dialog from "../../services/dialog";
import { t } from "../../services/i18n";
+import mime_types from "../../services/mime_types";
import { applyNotePreset } from "../../services/note_presets";
-import note_types, { MARKDOWN_NOTE_TYPE_MIME, NOTE_TYPES, type NoteTypeData } from "../../services/note_types";
+import note_types, {
+ isCurrentNoteType, MARKDOWN_NOTE_TYPE_MIME, NOTE_TYPES, type NoteTypeData, selectableNoteTypes
+} from "../../services/note_types";
import server from "../../services/server";
+import { escapeHtml } from "../../services/utils";
import { Badge, BadgeWithDropdown } from "../react/Badge";
import {
- useGetContextDataFrom, useNoteContext, useNoteProperty, useNoteSavedData, useTriliumEvent
+ useGetContextDataFrom, useNoteContext, useNoteProperty, useNoteSavedData, useTriliumEvent, useTriliumOption
} from "../react/hooks";
+import { MenuItemRows } from "../react/Menu";
+import Modal from "../react/Modal";
+import { CodeMimeTypesList } from "../type_widgets/options/code_mime_types_list";
import { onWheelHorizontalScroll } from "../widget_utils";
/** The note types offered as a pill of their own, each a single click away. */
@@ -164,3 +172,117 @@ function switchTo(
function switchNoteType(noteId: string, type: string, mime?: string) {
return server.put(`notes/${noteId}/type`, { type, mime });
}
+
+interface NoteTypeListProps {
+ currentNoteType?: NoteType;
+ currentNoteMime?: string | null;
+ note?: FNote | null;
+ setModalShown: Dispatch<StateUpdater<boolean>>;
+ noCodeNotes?: boolean;
+}
+
+/** The note types to switch `note` to, as rows of a menu or a list. See {@link useNoteTypeItems}. */
+export function NoteTypeDropdownContent(props: NoteTypeListProps) {
+ return <MenuItemRows items={useNoteTypeItems(props)} />;
+}
+
+/**
+ * The note types to switch `note` to, the current one ticked, as menu items: the note types, then,
+ * unless {@link NoteTypeListProps.noCodeNotes}, the enabled code languages under a "Code" heading
+ * and a row opening their options.
+ */
+export function useNoteTypeItems({ currentNoteType, currentNoteMime, note, setModalShown, noCodeNotes }: NoteTypeListProps) {
+ const { enabledMimeTypes } = useMimeTypes();
+ const noteTypes = useMemo(() => selectableNoteTypes(!noCodeNotes), [ noCodeNotes ]);
+ 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 switchNoteType(note.noteId, type, mime);
+ }, [ note, currentNoteType, currentNoteMime ]);
+
+ const items: MenuItem<unknown>[] = [];
+ for (const { isNew, isBeta, type, mime, title } of noteTypes) {
+ if (noCodeNotes || type !== "code") {
+ items.push({
+ title: escapeHtml(title),
+ checked: isCurrentNoteType({ type, mime }, note),
+ badges: [
+ ...isNew ? [ { className: "new-note-type-badge", title: t("note_types.new-feature") } ] : [],
+ ...isBeta ? [ { title: t("note_types.beta-feature") } ] : []
+ ],
+ handler: () => void changeNoteType(type, mime)
+ });
+ } else {
+ // The code entries head the list of languages that follows.
+ items.push({ kind: "separator" }, { title: `<strong>${escapeHtml(title)}</strong>`, uiIcon: undefined, enabled: false });
+ }
+ }
+ if (!noCodeNotes) {
+ items.push(...codeLanguageItems({
+ currentMimeType: currentNoteMime ?? undefined,
+ mimeTypes: enabledMimeTypes,
+ changeNoteType: (type, mime) => void changeNoteType(type, mime),
+ onConfigure: () => setModalShown(true)
+ }));
+ }
+ return items;
+}
+
+interface CodeLanguageListProps {
+ currentMimeType?: string;
+ mimeTypes: MimeType[];
+ changeNoteType(type: NoteType, mime: string): void;
+ /** Opens the options of the code languages, from a row at the end; without it, there is none. */
+ onConfigure?(): void;
+}
+
+/** The code languages to switch a note to, the current one ticked, as menu items. */
+export function codeLanguageItems({ currentMimeType, mimeTypes, changeNoteType, onConfigure }: CodeLanguageListProps) {
+ const items: MenuItem<unknown>[] = mimeTypes.map((mimeType) => ({
+ title: escapeHtml(mimeType.title),
+ uiIcon: getCodeLanguageIcon(mimeType),
+ checked: mimeType.mime === currentMimeType,
+ handler: () => changeNoteType("code", mimeType.mime)
+ }));
+ if (onConfigure) {
+ items.push({ kind: "separator" }, { title: t("basic_properties.configure_code_notes"), uiIcon: "bx bx-cog", handler: onConfigure });
+ }
+ return items;
+}
+
+export function useMimeTypes() {
+ const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes");
+ return useMemo(() => {
+ mime_types.loadMimeTypes();
+ const allMimeTypes = mime_types.getMimeTypes();
+ return {
+ enabledMimeTypes: allMimeTypes.filter(mimeType => mimeType?.enabled),
+ allMimeTypes
+ };
+ }, [ codeNotesMimeTypes ]); // eslint-disable-line react-hooks/exhaustive-deps
+}
+
+export function NoteTypeOptionsModal({ modalShown, setModalShown }: { modalShown: boolean, setModalShown: (shown: boolean) => void }) {
+ return (
+ <Modal
+ className="code-mime-types-modal"
+ title={t("code_mime_types.title")}
+ show={modalShown} onHidden={() => setModalShown(false)}
+ size="xl" scrollable
+ >
+ <CodeMimeTypesList />
+ </Modal>
+ );
+}
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index a29868e102..11db339014 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -16,6 +16,7 @@ import { NOTE_TYPES } from "../../services/note_types";
import server from "../../services/server";
import { openInAppHelpFromUrl } from "../../services/utils";
import { formatDateTime } from "../../utils/formatters";
+import { ContentLanguagesModal, useLanguageSwitcher } from "../dialogs/content_languages";
import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";
import Dropdown, { type DropdownHandle, DropdownPanel, type DropdownPanelProps } from "../react/Dropdown";
import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";
@@ -24,7 +25,6 @@ import { useActiveNoteContext, useLegacyImperativeHandlers, useNoteLabel, useNot
import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
import { ParentComponent } from "../react/react_utils";
-import { codeLanguageItems, ContentLanguagesModal, NoteTypeOptionsModal, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/components/AttributeEditor";
import AttributeHelp from "../ribbon/components/AttributeHelp";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
@@ -34,6 +34,7 @@ import SimilarNotesTab from "../ribbon/SimilarNotesTab";
import type { RightPaneTabId } from "../sidebar/RightPaneTabs";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
import Breadcrumb from "./Breadcrumb";
+import { codeLanguageItems, NoteTypeOptionsModal, useMimeTypes } from "./NoteTypeSwitcher";
import { convertIndentation } from "./reindentation";
interface StatusBarContext {
diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
index d5df2bf126..94a0f4ffbc 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
@@ -7,7 +7,9 @@ import FNote, { NotePathRecord } from "../../entities/fnote";
import { t } from "../../services/i18n";
import note_create from "../../services/note_create";
import server from "../../services/server";
+import { useLanguageSwitcher } from "../dialogs/content_languages";
import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";
+import { codeLanguageItems, useMimeTypes } from "../layout/NoteTypeSwitcher";
import { getLocaleName, NoteInfoContent } from "../layout/StatusBar";
import ActionButton from "../react/ActionButton";
import type { DropdownHandle } from "../react/Dropdown";
@@ -15,7 +17,6 @@ import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react
import { useNoteContext, useNoteProperty } from "../react/hooks";
import { MenuItemRows } from "../react/Menu";
import Modal from "../react/Modal";
-import { codeLanguageItems, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
import { NoteContextMenu } from "../ribbon/NoteActions";
import NoteActionsCustom from "../ribbon/NoteActionsCustom";
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.css b/apps/client/src/widgets/ribbon/BasicPropertiesTab.css
deleted file mode 100644
index 9954a32c57..0000000000
--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.css
+++ /dev/null
@@ -1,29 +0,0 @@
-.basic-properties-widget {
- padding: 0px 12px 6px 12px;
- display: flex;
- align-items: baseline;
- flex-wrap: wrap;
-}
-
-.basic-properties-widget > * {
- margin-top: 9px;
- margin-bottom: 2px;
- margin-inline-end: 30px;
-}
-
-.note-type-container,
-.editability-select-container,
-.note-language-container {
- display: flex;
- align-items: center;
-}
-
-.note-type-dropdown {
- max-height: 500px;
- overflow-y: auto;
- overflow-x: hidden;
-}
-
-.editability-dropdown {
- width: 300px;
-}
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx
deleted file mode 100644
index 3e8a6776b4..0000000000
--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import type { MimeType } from "@triliumnext/commons";
-import { describe, expect, it, vi } from "vitest";
-
-// i18next is not initialized in the test env; echo the key so titles are what the spec reads.
-vi.mock("../../services/i18n", () => ({
- t: (key: string) => key,
- getAvailableLocales: () => [],
- getLocaleById: () => undefined
-}));
-
-import { codeLanguageItems } from "./BasicPropertiesTab";
-
-describe("codeLanguageItems", () => {
- const mimeTypes = [
- { title: "Plain text", mime: "text/plain", icon: "bx bx-file" },
- { title: "C++ <templates>", mime: "text/x-c++src" }
- ] as MimeType[];
-
- it("lists the languages, ticks the note's own, and ends with the options when asked", () => {
- const changeNoteType = vi.fn();
- const onConfigure = vi.fn();
- const items = codeLanguageItems({ currentMimeType: "text/x-c++src", mimeTypes, changeNoteType, onConfigure });
-
- // Titles are HTML in a menu, so a language's name is escaped.
- expect(items.map((item) => ("kind" in item ? item.kind : item.title))).toEqual([
- "Plain text", "C++ &lt;templates&gt;", "separator", "basic_properties.configure_code_notes"
- ]);
- expect(items.map((item) => "checked" in item && item.checked)).toEqual([ false, true, false, false ]);
- // A language's own icon, or the code note type's when it has none, as the note tree shows it.
- expect(items.slice(0, 2).map((item) => "uiIcon" in item && item.uiIcon)).toEqual([ "bx bx-file", "bx bx-code" ]);
-
- const [ plain, , , configure ] = items;
- if ("kind" in plain || "kind" in configure) throw new Error("expected rows");
- plain.handler?.(plain, new MouseEvent("click"));
- expect(changeNoteType).toHaveBeenCalledWith("code", "text/plain");
- configure.handler?.(configure, new MouseEvent("click"));
- expect(onConfigure).toHaveBeenCalledTimes(1);
- expect(configure.uiIcon).toBe("bx bx-cog");
-
- // Without a way to open the options, there is no row for them.
- expect(codeLanguageItems({ mimeTypes, changeNoteType })).toHaveLength(2);
- });
-});
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
deleted file mode 100644
index 08e039e932..0000000000
--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
+++ /dev/null
@@ -1,458 +0,0 @@
-import "./BasicPropertiesTab.css";
-
-import { getCodeLanguageIcon, MimeType, NoteType, ToggleInParentResponse } from "@triliumnext/commons";
-import { createPortal } from "preact";
-import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useState } from "preact/hooks";
-
-import FNote from "../../entities/fnote";
-import type { MenuItem } from "../../menus/context_menu";
-import branches from "../../services/branches";
-import dialog from "../../services/dialog";
-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";
-import { getAvailableLocales, getLocaleById, t } from "../../services/i18n";
-import { resolveContentLanguage } from "../../utils/formatters";
-import mime_types from "../../services/mime_types";
-import { isCurrentNoteType, NOTE_TYPES, selectableNoteTypes } from "../../services/note_types";
-import protected_session from "../../services/protected_session";
-import server from "../../services/server";
-import sync from "../../services/sync";
-import toast from "../../services/toast";
-import { escapeHtml } from "../../services/utils";
-import Dropdown from "../react/Dropdown";
-import FormDropdownList from "../react/FormDropdownList";
-import { FormListItem } from "../react/FormList";
-import FormToggle from "../react/FormToggle";
-import HelpButton from "../react/HelpButton";
-import { MenuItemRows } from "../react/Menu";
-import { useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumOption } from "../react/hooks";
-import Modal from "../react/Modal";
-import { CodeMimeTypesList } from "../type_widgets/options/code_mime_types_list";
-import { LocaleSelector } from "../type_widgets/options/components/LocaleSelector";
-import { ContentLanguagesList } from "../type_widgets/options/i18n";
-import { TabContext } from "./ribbon-interface";
-
-export default function BasicPropertiesTab({ note }: TabContext) {
- return (
- <div className="basic-properties-widget">
- <NoteTypeWidget note={note} />
- <ProtectedNoteSwitch note={note} />
- <EditabilitySelect note={note} />
- <BookmarkSwitch note={note} />
- <SharedSwitch note={note} />
- <TemplateSwitch note={note} />
- <NoteLanguageSwitch note={note} />
- </div>
- );
-}
-
-function NoteTypeWidget({ note }: { note?: FNote | null }) {
- 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);
- const items = useNoteTypeItems({ currentNoteType, currentNoteMime, note, setModalShown });
-
- return (
- <div className="note-type-container">
- <span>{t("basic_properties.note_type")}:</span> &nbsp;
- <Dropdown
- dropdownContainerClassName="note-type-dropdown"
- text={<span className="note-type-desc">{findTypeTitle(currentNoteType, currentNoteMime)}</span>}
- disabled={notSelectableNoteTypes.includes(currentNoteType ?? "text")}
- items={items} filterable
- />
-
- {createPortal(
- <NoteTypeOptionsModal modalShown={modalShown} setModalShown={setModalShown} />,
- document.body
- )}
- </div>
- );
-}
-
-interface NoteTypeListProps {
- currentNoteType?: NoteType;
- currentNoteMime?: string | null;
- note?: FNote | null;
- setModalShown: Dispatch<StateUpdater<boolean>>;
- noCodeNotes?: boolean;
-}
-
-/** The note types to switch `note` to, as rows of a menu or a list. See {@link useNoteTypeItems}. */
-export function NoteTypeDropdownContent(props: NoteTypeListProps) {
- return <MenuItemRows items={useNoteTypeItems(props)} />;
-}
-
-/**
- * The note types to switch `note` to, the current one ticked, as menu items: the note types, then,
- * unless {@link NoteTypeListProps.noCodeNotes}, the enabled code languages under a "Code" heading
- * and a row opening their options.
- */
-export function useNoteTypeItems({ currentNoteType, currentNoteMime, note, setModalShown, noCodeNotes }: NoteTypeListProps) {
- const { enabledMimeTypes } = useMimeTypes();
- const noteTypes = useMemo(() => selectableNoteTypes(!noCodeNotes), [ noCodeNotes ]);
- 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 ]);
-
- const items: MenuItem<unknown>[] = [];
- for (const { isNew, isBeta, type, mime, title } of noteTypes) {
- if (noCodeNotes || type !== "code") {
- items.push({
- title: escapeHtml(title),
- checked: isCurrentNoteType({ type, mime }, note),
- badges: [
- ...isNew ? [ { className: "new-note-type-badge", title: t("note_types.new-feature") } ] : [],
- ...isBeta ? [ { title: t("note_types.beta-feature") } ] : []
- ],
- handler: () => void changeNoteType(type, mime)
- });
- } else {
- // The code entries head the list of languages that follows.
- items.push({ kind: "separator" }, { title: `<strong>${escapeHtml(title)}</strong>`, uiIcon: undefined, enabled: false });
- }
- }
- if (!noCodeNotes) {
- items.push(...codeLanguageItems({
- currentMimeType: currentNoteMime ?? undefined,
- mimeTypes: enabledMimeTypes,
- changeNoteType: (type, mime) => void changeNoteType(type, mime),
- onConfigure: () => setModalShown(true)
- }));
- }
- return items;
-}
-
-interface CodeLanguageListProps {
- currentMimeType?: string;
- mimeTypes: MimeType[];
- changeNoteType(type: NoteType, mime: string): void;
- /** Opens the options of the code languages, from a row at the end; without it, there is none. */
- onConfigure?(): void;
-}
-
-/** The code languages to switch a note to, the current one ticked, as menu items. */
-export function codeLanguageItems({ currentMimeType, mimeTypes, changeNoteType, onConfigure }: CodeLanguageListProps) {
- const items: MenuItem<unknown>[] = mimeTypes.map((mimeType) => ({
- title: escapeHtml(mimeType.title),
- uiIcon: getCodeLanguageIcon(mimeType),
- checked: mimeType.mime === currentMimeType,
- handler: () => changeNoteType("code", mimeType.mime)
- }));
- if (onConfigure) {
- items.push({ kind: "separator" }, { title: t("basic_properties.configure_code_notes"), uiIcon: "bx bx-cog", handler: onConfigure });
- }
- return items;
-}
-
-export function useMimeTypes() {
- const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes");
- return useMemo(() => {
- mime_types.loadMimeTypes();
- const allMimeTypes = mime_types.getMimeTypes();
- return {
- enabledMimeTypes: allMimeTypes.filter(mimeType => mimeType?.enabled),
- allMimeTypes
- };
- }, [ codeNotesMimeTypes ]); // eslint-disable-line react-hooks/exhaustive-deps
-}
-
-export function NoteTypeOptionsModal({ modalShown, setModalShown }: { modalShown: boolean, setModalShown: (shown: boolean) => void }) {
- return (
- <Modal
- className="code-mime-types-modal"
- title={t("code_mime_types.title")}
- show={modalShown} onHidden={() => setModalShown(false)}
- size="xl" scrollable
- >
- <CodeMimeTypesList />
- </Modal>
- );
-}
-
-function ProtectedNoteSwitch({ note }: { note?: FNote | null }) {
- const isProtected = useNoteProperty(note, "isProtected");
-
- return (
- <div className="protected-note-switch-container">
- <FormToggle
- 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")}
- currentValue={!!isProtected}
- onChange={(shouldProtect) => note && protected_session.protectNote(note.noteId, shouldProtect, false)}
- />
- </div>
- );
-}
-
-function EditabilitySelect({ note }: { note?: FNote | null }) {
- const [ readOnly, setReadOnly ] = useNoteLabelBoolean(note, "readOnly");
- const [ autoReadOnlyDisabled, setAutoReadOnlyDisabled ] = useNoteLabelBoolean(note, "autoReadOnlyDisabled");
-
- const options = useMemo(() => ([
- {
- value: "auto",
- label: t("editability_select.auto"),
- description: t("editability_select.note_is_editable"),
- },
- {
- value: "readOnly",
- label: t("editability_select.read_only"),
- description: t("editability_select.note_is_read_only")
- },
- {
- value: "autoReadOnlyDisabled",
- label: t("editability_select.always_editable"),
- description: t("editability_select.note_is_always_editable")
- }
- ]), []);
-
- return (
- <div class="editability-select-container">
- <span>{t("basic_properties.editable")}:</span> &nbsp;
-
- <FormDropdownList
- dropdownContainerClassName="editability-dropdown"
- values={options}
- currentValue={ readOnly ? "readOnly" : autoReadOnlyDisabled ? "autoReadOnlyDisabled" : "auto" }
- keyProperty="value" titleProperty="label" descriptionProperty="description"
- onChange={(editability: string) => {
- setReadOnly(editability === "readOnly");
- setAutoReadOnlyDisabled(editability === "autoReadOnlyDisabled");
- }}
- />
- </div>
- );
-}
-
-function BookmarkSwitch({ note }: { note?: FNote | null }) {
- const [ isBookmarked, setIsBookmarked ] = useNoteBookmarkState(note);
-
- return (
- <div className="bookmark-switch-container">
- <FormToggle
- switchOnName={t("bookmark_switch.bookmark")} switchOnTooltip={t("bookmark_switch.bookmark_this_note")}
- switchOffName={t("bookmark_switch.bookmark")} switchOffTooltip={t("bookmark_switch.remove_bookmark")}
- currentValue={isBookmarked}
- onChange={setIsBookmarked}
- disabled={["root", "_hidden"].includes(note?.noteId ?? "")}
- />
- </div>
- );
-}
-
-export function useNoteBookmarkState(note: FNote | null | undefined) {
- const [ isBookmarked, setIsBookmarked ] = useState<boolean>(false);
- const refreshState = useCallback(() => {
- const isBookmarked = note && !!note.getParentBranches().find((b) => b.parentNoteId === "_lbBookmarks");
- setIsBookmarked(!!isBookmarked);
- }, [ note ]);
-
- const changeHandler = useCallback(async (shouldBookmark: boolean) => {
- if (!note) return;
- const resp = await server.put<ToggleInParentResponse>(`notes/${note.noteId}/toggle-in-parent/_lbBookmarks/${shouldBookmark}`);
-
- if (!resp.success && "message" in resp) {
- toast.showError(resp.message);
- }
- }, [ note ]);
-
- useEffect(() => refreshState(), [ refreshState ]);
- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- if (note && loadResults.getBranchRows().find((b) => b.noteId === note.noteId)) {
- refreshState();
- }
- });
- return [ isBookmarked, changeHandler ] as const;
-}
-
-function TemplateSwitch({ note }: { note?: FNote | null }) {
- const [ isTemplate, setIsTemplate ] = useNoteLabelBoolean(note, "template");
-
- return (
- <div className="template-switch-container">
- <FormToggle
- switchOnName={t("template_switch.template")} switchOnTooltip={t("template_switch.toggle-on-hint")}
- switchOffName={t("template_switch.template")} switchOffTooltip={t("template_switch.toggle-off-hint")}
- helpPage="KC1HB96bqqHX"
- disabled={note?.noteId.startsWith("_options")}
- currentValue={isTemplate} onChange={setIsTemplate}
- />
- </div>
- );
-}
-
-function SharedSwitch({ note }: { note?: FNote | null }) {
- const [ isShared, switchShareState ] = useShareState(note);
-
- return (
- <div className="shared-switch-container">
- <FormToggle
- currentValue={isShared}
- onChange={switchShareState}
- switchOnName={t("shared_switch.shared")} switchOnTooltip={t("shared_switch.toggle-on-title")}
- switchOffName={t("shared_switch.shared")} switchOffTooltip={t("shared_switch.toggle-off-title")}
- helpPage="R9pX4DGra2Vt"
- disabled={["root", "_share", "_hidden"].includes(note?.noteId ?? "") || note?.noteId.startsWith("_options")}
- />
- </div>
- );
-}
-
-export function useShareState(note: FNote | null | undefined) {
- const [ isShared, setIsShared ] = useState(false);
- const refreshState = useCallback(() => {
- setIsShared(!!note?.hasAncestor("_share"));
- }, [ note ]);
-
- useEffect(() => refreshState(), [ refreshState ]);
- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- if (note && loadResults.getBranchRows().find((b) => b.noteId === note.noteId)) {
- refreshState();
- }
- });
-
- const switchShareState = useCallback(async (shouldShare: boolean) => {
- if (!note) return;
-
- if (shouldShare) {
- await branches.cloneNoteToParentNote(note.noteId, "_share");
- } else {
- if (note?.getParentBranches().length === 1 && !(await dialog.confirm(t("shared_switch.shared-branch")))) {
- return;
- }
-
- const shareBranch = note?.getParentBranches().find((b) => b.parentNoteId === "_share");
- if (!shareBranch?.branchId) return;
- await server.remove(`branches/${shareBranch.branchId}?taskId=no-progress-reporting`);
- }
-
- sync.syncNow(true);
- }, [ note ]);
-
- return [ isShared, switchShareState ] as const;
-}
-
-function NoteLanguageSwitch({ note }: { note?: FNote | null }) {
- return (
- <div className="note-language-container">
- <span>{t("basic_properties.language")}:</span>
- &nbsp;
-
- <NoteLanguageSelector note={note} />
- <HelpButton helpPage="veGu4faJErEM" style={{ marginInlineStart: "4px" }} />
- </div>
- );
-}
-
-export function NoteLanguageSelector({ note }: { note: FNote | null | undefined }) {
- const [ modalShown, setModalShown ] = useState(false);
- const { locales, DEFAULT_LOCALE, currentNoteLanguage, setCurrentNoteLanguage } = useLanguageSwitcher(note);
-
- return (
- <>
- <LocaleSelector
- locales={locales}
- defaultLocale={DEFAULT_LOCALE}
- currentValue={currentNoteLanguage} onChange={setCurrentNoteLanguage}
- extraChildren={<>
- <FormListItem
- onClick={() => setModalShown(true)}
- icon="bx bx-cog"
- >{t("note_language.configure-languages")}</FormListItem>
- </>}
- />
- {createPortal(
- <ContentLanguagesModal modalShown={modalShown} setModalShown={setModalShown} />,
- document.body
- )}
- </>
- );
-}
-
-export function useLanguageSwitcher(note: FNote | null | undefined) {
- const [ languages ] = useTriliumOption("languages");
- // Subscribed to for the re-render alone — the values are read below through
- // `resolveContentLanguage`, which goes to the options store directly. Without these, changing
- // the default in the settings would leave the picker naming a stale language until reopened.
- useTriliumOption("defaultContentLanguage");
- useTriliumOption("locale");
-
- /**
- * The locale a note without a `#language` of its own is actually written in.
- *
- * Not memoized: it is a lookup over a two-dozen-entry catalog, and `resolveContentLanguage`
- * reads the options directly — so the subscriptions above, not a dependency array, are what
- * make this follow a change to the setting.
- */
- const resolvedDefaultLocale = getLocaleById(resolveContentLanguage(null));
-
- // Naming the resolved language here is the point: the entry used to read "No language set",
- // which denied the existence of the default that was in fact deciding text direction and
- // quotation marks. The id stays empty — it is the sentinel that clears the label.
- const DEFAULT_LOCALE = {
- id: "",
- name: resolvedDefaultLocale
- ? t("note_language.not_set_with_default", { language: resolvedDefaultLocale.name })
- : t("note_language.not_set")
- };
- const [ currentNoteLanguage, setCurrentNoteLanguage ] = useNoteLabel(note, "language");
- const locales = useMemo(() => {
- const enabledLanguages = JSON.parse(languages ?? "[]") as string[];
- const filteredLanguages = getAvailableLocales().filter((l) => typeof l !== "object" || enabledLanguages.includes(l.id));
- return filteredLanguages;
- }, [ languages ]);
-
- /**
- * The locale the note is actually written in — its own if it has one, the default otherwise.
- * What the compact displays (the status bar badge, the mobile submenu title) name, so that a
- * note without a `#language` reads as the language in force rather than as a bare dash.
- */
- const effectiveLocale = useMemo(
- () => (currentNoteLanguage ? getLocaleById(currentNoteLanguage) : resolvedDefaultLocale),
- [ currentNoteLanguage, resolvedDefaultLocale ]
- );
-
- return { locales, DEFAULT_LOCALE, resolvedDefaultLocale, effectiveLocale, currentNoteLanguage, setCurrentNoteLanguage };
-}
-
-export function ContentLanguagesModal({ modalShown, setModalShown }: { modalShown: boolean, setModalShown: (shown: boolean) => void }) {
- return (
- <Modal
- className="content-languages-modal"
- title={t("content_language.title")}
- show={modalShown} onHidden={() => setModalShown(false)}
- size="lg" scrollable
- >
- <ContentLanguagesList />
- </Modal>
- );
-}
-
-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;
- }
- const noteType = NOTE_TYPES.find((nt) => nt.type === type);
-
- return noteType ? noteType.title : type;
-
-}
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index 4b943dc043..c116187e22 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -1,8 +1,8 @@
import "./NoteActions.css";
-import { ConvertToAttachmentResponse } from "@triliumnext/commons";
+import { ConvertToAttachmentResponse, ToggleInParentResponse } from "@triliumnext/commons";
import { ComponentChildren, RefObject } from "preact";
-import { useContext, useEffect, useRef } from "preact/hooks";
+import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";
import appContext, { CommandNames } from "../../components/app_context";
import Component from "../../components/component";
@@ -21,13 +21,14 @@ import ClosePaneButton from "../buttons/close_pane_button";
import CreatePaneButton from "../buttons/create_pane_button";
import MovePaneButton from "../buttons/move_pane_button";
import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
+import { useShareState } from "../layout/NoteBadges";
+import { NoteTypeDropdownContent } from "../layout/NoteTypeSwitcher";
import { isAlwaysFullWidthByType } from "../note_wrapper";
import ActionButton from "../react/ActionButton";
import Dropdown, { type DropdownHandle } from "../react/Dropdown";
import { FormDropdownDivider, FormDropdownSubmenu, FormListHeader, FormListItem, FormListToggleableItem } from "../react/FormList";
import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteLabelOptionalBool, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption } from "../react/hooks";
import { ParentComponent } from "../react/react_utils";
-import { NoteTypeDropdownContent, useNoteBookmarkState, useShareState } from "./BasicPropertiesTab";
import NoteActionsCustom from "./NoteActionsCustom";
const isNewLayout = isExperimentalFeatureEnabled("new-layout");
@@ -440,3 +441,28 @@ function ExportAsImage({ ntxId, parentComponent }: { ntxId: string | null | unde
</FormDropdownSubmenu>
);
}
+
+export function useNoteBookmarkState(note: FNote | null | undefined) {
+ const [ isBookmarked, setIsBookmarked ] = useState<boolean>(false);
+ const refreshState = useCallback(() => {
+ const isBookmarked = note && !!note.getParentBranches().find((b) => b.parentNoteId === "_lbBookmarks");
+ setIsBookmarked(!!isBookmarked);
+ }, [ note ]);
+
+ const changeHandler = useCallback(async (shouldBookmark: boolean) => {
+ if (!note) return;
+ const resp = await server.put<ToggleInParentResponse>(`notes/${note.noteId}/toggle-in-parent/_lbBookmarks/${shouldBookmark}`);
+
+ if (!resp.success && "message" in resp) {
+ toast.showError(resp.message);
+ }
+ }, [ note ]);
+
+ useEffect(() => refreshState(), [ refreshState ]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (note && loadResults.getBranchRows().find((b) => b.noteId === note.noteId)) {
+ refreshState();
+ }
+ });
+ return [ isBookmarked, changeHandler ] as const;
+}
diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
index 6102738199..93b282cb10 100644
--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts
+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
@@ -1,6 +1,5 @@
import { t } from "../../services/i18n";
import options from "../../services/options";
-import BasicPropertiesTab from "./BasicPropertiesTab";
import EditedNotesTab from "./EditedNotesTab";
import FilePropertiesTab from "./FilePropertiesTab";
import ImagePropertiesTab from "./ImagePropertiesTab";
@@ -62,13 +61,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
toggleCommand: "toggleRibbonTabImageProperties",
activate: true,
},
- {
- title: t("basic_properties.basic_properties"),
- icon: "bx bx-slider",
- content: BasicPropertiesTab,
- show: ({note}) => !note?.isLaunchBarConfig(),
- toggleCommand: "toggleRibbonTabBasicProperties"
- },
{
title: t("owned_attribute_list.owned_attributes"),
icon: "bx bx-list-check",