From ea1397de63836be858bda5471fcddae03736d96e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 23 Aug 2025 23:22:07 +0300 Subject: [PATCH] feat(react/ribbon): reintroduce button collection properties --- apps/client/src/widgets/react/Button.tsx | 4 +- .../ribbon/CollectionPropertiesTab.tsx | 55 ++++++++++++++++--- .../widgets/ribbon_widgets/book_properties.ts | 31 ----------- .../ribbon_widgets/book_properties_config.ts | 2 +- 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx index ddfe225fe..f5317f843 100644 --- a/apps/client/src/widgets/react/Button.tsx +++ b/apps/client/src/widgets/react/Button.tsx @@ -19,9 +19,10 @@ export interface ButtonProps { size?: "normal" | "small" | "micro"; style?: CSSProperties; triggerCommand?: CommandNames; + title?: string; } -const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, size, style, triggerCommand }: ButtonProps) => { +const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, size, style, triggerCommand, ...restProps }: ButtonProps) => { // Memoize classes array to prevent recreation const classes = useMemo(() => { const classList: string[] = ["btn"]; @@ -65,6 +66,7 @@ const Button = memo(({ name, buttonRef: _buttonRef, className, text, onClick, ke disabled={disabled} style={style} data-trigger-command={triggerCommand} + {...restProps} > {icon && } {text} {shortcutElements} diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx index 027dafd30..d1066f6a9 100644 --- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx +++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx @@ -1,12 +1,14 @@ -import { useMemo } from "preact/hooks"; +import { useContext, useMemo } from "preact/hooks"; import { t } from "../../services/i18n"; import { ViewTypeOptions } from "../../services/note_list_renderer"; import FormSelect from "../react/FormSelect"; import { TabContext } from "./ribbon-interface"; import { mapToKeyValueArray } from "../../services/utils"; import { useNoteLabel } from "../react/hooks"; +import { bookPropertiesConfig, BookProperty, ButtonProperty } from "../ribbon_widgets/book_properties_config"; +import Button from "../react/Button"; +import { ParentComponent } from "../react/react_utils"; import FNote from "../../entities/fnote"; -import FormGroup from "../react/FormGroup"; const VIEW_TYPE_MAPPINGS: Record = { grid: t("book_properties.grid"), @@ -18,19 +20,20 @@ const VIEW_TYPE_MAPPINGS: Record = { }; export default function CollectionPropertiesTab({ note }: TabContext) { + const [ viewType, setViewType ] = useNoteLabel(note, "viewType"); + const viewTypeWithDefault = viewType ?? "grid"; + const properties = bookPropertiesConfig[viewTypeWithDefault].properties; + return (note &&
- - -
-
+ +
); } -function CollectionTypeSwitcher({ note }: { note: FNote }) { +function CollectionTypeSwitcher({ viewType, setViewType }: { viewType: string, setViewType: (newValue: string) => void }) { const collectionTypes = useMemo(() => mapToKeyValueArray(VIEW_TYPE_MAPPINGS), []); - const [ viewType, setViewType ] = useNoteLabel(note, "viewType"); return (
@@ -42,4 +45,40 @@ function CollectionTypeSwitcher({ note }: { note: FNote }) { />
) +} + +function BookProperties({ note, properties }: { note: FNote, properties: BookProperty[] }) { + return ( +
+ {properties.map(property => ( +
+ {mapPropertyView({ note, property })} +
+ ))} +
+ ) +} + +function mapPropertyView({ note, property }: { note: FNote, property: BookProperty }) { + switch (property.type) { + case "button": + return + } +} + +function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) { + const parentComponent = useContext(ParentComponent); + + return