Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(note_actions): integrate shared switch into new layout
Elian Doranb36a0bd10b5d
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsxindex dc14284f3a..f1f51b2223 100644--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx+++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx@@ -32,7 +32,7 @@ export default function BasicPropertiesTab({ note }: TabContext) {<ProtectedNoteSwitch note={note} /><EditabilitySelect note={note} />{!isNewLayout && <BookmarkSwitch note={note} />}- <SharedSwitch note={note} />+ {!isNewLayout && <SharedSwitch note={note} />}<TemplateSwitch note={note} /><NoteLanguageSwitch note={note} /></div>@@ -251,12 +251,29 @@ function TemplateSwitch({ note }: { note?: FNote | null }) {}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(), [ note ]);+ useEffect(() => refreshState(), [ refreshState ]);useTriliumEvent("entitiesReloaded", ({ loadResults }) => {if (note && loadResults.getBranchRows().find((b) => b.noteId === note.noteId)) {refreshState();@@ -281,18 +298,7 @@ function SharedSwitch({ note }: { note?: FNote | null }) {sync.syncNow(true);}, [ 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>- )+ return [ isShared, switchShareState ] as const;}function NoteLanguageSwitch({ note }: { note?: FNote | null }) {diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsxindex ee5c949d7a..8cf1ffbebc 100644--- a/apps/client/src/widgets/ribbon/NoteActions.tsx+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx@@ -17,7 +17,7 @@ import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleaimport { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteProperty, useTriliumOption } from "../react/hooks";import { ParentComponent } from "../react/react_utils";import { isExperimentalFeatureEnabled } from "../../services/experimental_features";-import { useNoteBookmarkState } from "./BasicPropertiesTab";+import { useNoteBookmarkState, useShareState } from "./BasicPropertiesTab";const isNewLayout = isExperimentalFeatureEnabled("new-layout");@@ -118,9 +118,11 @@ function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: Notfunction NoteBasicProperties({ note }: { note: FNote }) {const [ isBookmarked, setIsBookmarked ] = useNoteBookmarkState(note);+ const [ isShared, switchShareState ] = useShareState(note);return <><FormListToggleableItem icon="bx bx-bookmark" title={t("bookmark_switch.bookmark")} currentValue={isBookmarked} onChange={setIsBookmarked} />+ <FormListToggleableItem icon="bx bx-share-alt" title={t("shared_switch.shared")} currentValue={isShared} onChange={switchShareState} /></>;}