import { t } from "i18next"; import FNote from "../../entities/fnote"; import { ViewTypeOptions } from "../collections/interface"; import Dropdown from "../react/Dropdown"; import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "../react/FormList"; import Icon from "../react/Icon"; import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab"; import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, SplitButtonProperty } from "../ribbon/collection-properties-config"; import { useNoteLabelBoolean } from "../react/hooks"; import { useContext } from "preact/hooks"; import { ParentComponent } from "../react/react_utils"; const ICON_MAPPINGS: Record = { grid: "bx bxs-grid", list: "bx bx-list-ul", calendar: "bx bx-calendar", table: "bx bx-table", geoMap: "bx bx-map-alt", board: "bx bx-columns", presentation: "bx bx-rectangle" }; export default function CollectionProperties({ note }: { note: FNote }) { const [ viewType, setViewType ] = useViewType(note); return ( <> ); } function ViewTypeSwitcher({ note, viewType, setViewType }: { note: FNote, viewType: ViewTypeOptions, setViewType: (newValue: ViewTypeOptions) => void }) { return (   {VIEW_TYPE_MAPPINGS[viewType]} } > {Object.entries(VIEW_TYPE_MAPPINGS).map(([ key, label ]) => ( setViewType(key as ViewTypeOptions)} selected={viewType === key} disabled={viewType === key} icon={ICON_MAPPINGS[key as ViewTypeOptions]} >{label} ))} ); } function ViewOptions({ note, viewType }: { note: FNote, viewType: ViewTypeOptions }) { const properties = bookPropertiesConfig[viewType].properties; return ( {properties.map(property => ( ))} {properties.length > 0 && } ); } function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) { switch (property.type) { case "button": return ; case "split-button": return ; case "checkbox": return ; } } function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) { const parentComponent = useContext(ParentComponent); return ( { if (!parentComponent) return; property.onClick({ note, triggerCommand: parentComponent.triggerCommand.bind(parentComponent) }); }} >{property.label} ); } function SplitButtonPropertyView({ note, property }: { note: FNote, property: SplitButtonProperty }) { const parentComponent = useContext(ParentComponent); const ItemsComponent = property.items; const clickContext = parentComponent && { note, triggerCommand: parentComponent.triggerCommand.bind(parentComponent) }; return (parentComponent && clickContext && property.onClick(clickContext)} > ); } function CheckBoxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) { const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel); return ( ); }