Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): remove the floating display mode buttons

Elian Doran8c4d384bfa59
diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsx
index 7a31a4d315..4267088b54 100644
--- a/apps/client/src/widgets/FloatingButtons.tsx
+++ b/apps/client/src/widgets/FloatingButtons.tsx
@@ -1,12 +1,11 @@
import { t } from "i18next";
import "./FloatingButtons.css";
-import { useNoteContext, useNoteLabel, useNoteLabelBoolean } from "./react/hooks";
+import { useNoteContext } from "./react/hooks";
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
import { ParentComponent } from "./react/react_utils";
import { EventData, EventNames } from "../components/app_context";
import { type FloatingButtonsList, type FloatingButtonContext } from "./FloatingButtonsDefinitions";
import ActionButton from "./react/ActionButton";
-import { ViewTypeOptions } from "./collections/interface";
interface FloatingButtonsProps {
items: FloatingButtonsList;
@@ -22,8 +21,6 @@ interface FloatingButtonsProps {
export default function FloatingButtons({ items }: FloatingButtonsProps) {
const { note, noteContext } = useNoteContext();
const parentComponent = useContext(ParentComponent);
- const [ viewType ] = useNoteLabel(note, "viewType");
- const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
const context = useMemo<FloatingButtonContext | null>(() => {
if (!note || !noteContext || !parentComponent) return null;
@@ -31,8 +28,6 @@ export default function FloatingButtons({ items }: FloatingButtonsProps) {
note,
noteContext,
isDefaultViewMode: noteContext.viewScope?.viewMode === "default",
- viewType: viewType as ViewTypeOptions,
- isReadOnly,
triggerEvent<T extends EventNames>(name: T, data?: Omit<EventData<T>, "ntxId">) {
parentComponent.triggerEvent(name, {
ntxId: noteContext.ntxId,
@@ -40,7 +35,7 @@ export default function FloatingButtons({ items }: FloatingButtonsProps) {
} as EventData<T>);
}
};
- }, [ note, noteContext, parentComponent, viewType, isReadOnly ]);
+ }, [ note, noteContext, parentComponent ]);
// Manage the user-adjustable visibility of the floating buttons.
const [ visible, setVisible ] = useState(true);
diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
index 1aa2150f67..c8d5a1370c 100644
--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
@@ -18,23 +18,18 @@ import server from "../services/server";
import toast from "../services/toast";
import tree from "../services/tree";
import { createImageSrcUrl, isElectron, openInAppHelpFromUrl } from "../services/utils";
-import { ViewTypeOptions } from "./collections/interface";
import ActionButton, { ActionButtonProps } from "./react/ActionButton";
-import { ButtonGroup } from "./react/Button";
-import { useEffectiveReadOnly, useIsNoteReadOnly, useNoteLabel, useTriliumEvent, useTriliumOption, useWindowSize } from "./react/hooks";
+import { useIsNoteReadOnly, useTriliumEvent, useWindowSize } from "./react/hooks";
import NoItems from "./react/NoItems";
import NoteLink from "./react/NoteLink";
import RawHtml from "./react/RawHtml";
-import { isSplitEditorForcedReadOnly, resolveDisplayMode } from "./type_widgets/helpers/split_editor_mode";
export interface FloatingButtonContext {
note: FNote;
noteContext: NoteContext;
isDefaultViewMode: boolean;
- isReadOnly: boolean;
/** Shorthand for triggering an event from the parent component. The `ntxId` is automatically handled for convenience. */
triggerEvent<T extends EventNames>(name: T, data?: Omit<EventData<T>, "ntxId">): void;
- viewType?: ViewTypeOptions | null;
}
function FloatingButton({ className, ...props }: ActionButtonProps) {
@@ -48,8 +43,6 @@ function FloatingButton({ className, ...props }: ActionButtonProps) {
export type FloatingButtonsList = ((context: FloatingButtonContext) => false | VNode)[];
export const DESKTOP_FLOATING_BUTTONS: FloatingButtonsList = [
- SwitchSplitOrientationButton,
- DisplayModeSwitcher,
EditButton,
RunActiveNoteButton,
OpenTriliumApiDocsButton,
@@ -69,51 +62,6 @@ export const POPUP_HIDDEN_FLOATING_BUTTONS: FloatingButtonsList = [
InAppHelpButton
];
-function SwitchSplitOrientationButton({ note, isReadOnly, isDefaultViewMode }: FloatingButtonContext) {
- const [ displayMode ] = useNoteLabel(note, "displayMode");
- const [ splitEditorOrientation, setSplitEditorOrientation ] = useTriliumOption("splitEditorOrientation");
- const upcomingOrientation = splitEditorOrientation === "horizontal" ? "vertical" : "horizontal";
- const effectiveMode = displayMode === "source" || displayMode === "split" || displayMode === "preview"
- ? displayMode
- : isReadOnly ? "preview" : "split";
- const isEnabled = note.type === "mermaid" && note.isContentAvailable() && effectiveMode === "split" && isDefaultViewMode;
-
- return isEnabled && <FloatingButton
- text={upcomingOrientation === "vertical" ? t("switch_layout_button.title_vertical") : t("switch_layout_button.title_horizontal")}
- icon={upcomingOrientation === "vertical" ? "bx bxs-dock-bottom" : "bx bxs-dock-left"}
- onClick={() => setSplitEditorOrientation(upcomingOrientation)}
- />;
-}
-
-function DisplayModeSwitcher({ note, noteContext, isDefaultViewMode }: FloatingButtonContext) {
- const [ displayMode, setDisplayMode ] = useNoteLabel(note, "displayMode");
- const readOnly = useEffectiveReadOnly(note, noteContext);
- const isEnabled = (note.isMarkdown() || note.type === "mermaid" || note.isIconPack()) && note.isContentAvailable() && isDefaultViewMode;
- if (!isEnabled) return false;
-
- // Mirror SplitEditor's mode resolution so the active button matches the actual pane.
- const mode = resolveDisplayMode(displayMode, readOnly || isSplitEditorForcedReadOnly(note));
- const buttons: Array<{ value: "source" | "split" | "preview"; icon: string; text: string }> = [
- { value: "source", icon: "bx bx-code", text: t("display_mode.source") },
- { value: "split", icon: "bx bxs-dock-left", text: t("display_mode.split") },
- { value: "preview", icon: "bx bx-show", text: t("display_mode.preview") }
- ];
-
- return (
- <ButtonGroup size="sm">
- {buttons.map(({ value, icon, text }) => (
- <FloatingButton
- key={value}
- icon={icon}
- text={text}
- active={mode === value}
- onClick={() => setDisplayMode(value)}
- />
- ))}
- </ButtonGroup>
- );
-}
-
function EditButton({ note, noteContext }: FloatingButtonContext) {
const [animationClass, setAnimationClass] = useState("");
const {isReadOnly, enableEditing} = useIsNoteReadOnly(note, noteContext);