import { useContext, useMemo } from "preact/hooks"; import { t } from "../../services/i18n"; import FormSelect, { FormSelectWithGroups } from "../react/FormSelect"; import { TabContext } from "./ribbon-interface"; import { mapToKeyValueArray } from "../../services/utils"; import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks"; import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxProperty, NumberProperty } from "./collection-properties-config"; import Button from "../react/Button"; import { ParentComponent } from "../react/react_utils"; import FNote from "../../entities/fnote"; import FormCheckbox from "../react/FormCheckbox"; import FormTextBox from "../react/FormTextBox"; import { ComponentChildren } from "preact"; import { ViewTypeOptions } from "../collections/interface"; const VIEW_TYPE_MAPPINGS: Record = { grid: t("book_properties.grid"), list: t("book_properties.list"), calendar: t("book_properties.calendar"), table: t("book_properties.table"), geoMap: t("book_properties.geo-map"), board: t("book_properties.board"), presentation: t("book_properties.presentation") }; export default function CollectionPropertiesTab({ note }: TabContext) { const [ viewType, setViewType ] = useNoteLabel(note, "viewType"); const viewTypeWithDefault = (viewType ?? "grid") as ViewTypeOptions; const properties = bookPropertiesConfig[viewTypeWithDefault].properties; return (
{note && ( <> )}
); } function CollectionTypeSwitcher({ viewType, setViewType }: { viewType: string, setViewType: (newValue: string) => void }) { const collectionTypes = useMemo(() => mapToKeyValueArray(VIEW_TYPE_MAPPINGS), []); return (
{t("book_properties.view_type")}:   
) } function BookProperties({ viewType, note, properties }: { viewType: ViewTypeOptions, note: FNote, properties: BookProperty[] }) { return ( <> {properties.map(property => (
{mapPropertyView({ note, property })}
))} {viewType !== "list" && viewType !== "grid" && ( )} ) } function mapPropertyView({ note, property }: { note: FNote, property: BookProperty }) { switch (property.type) { case "button": return case "checkbox": return case "number": return case "combobox": return } } function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) { const parentComponent = useContext(ParentComponent); return