2025-12-11 19:17:23 +02:00
|
|
|
import { t } from "i18next";
|
2025-12-11 18:53:48 +02:00
|
|
|
import FNote from "../../entities/fnote";
|
|
|
|
|
import { ViewTypeOptions } from "../collections/interface";
|
|
|
|
|
import Dropdown from "../react/Dropdown";
|
2025-12-11 19:17:23 +02:00
|
|
|
import { FormListItem, FormListToggleableItem } from "../react/FormList";
|
2025-12-11 18:59:28 +02:00
|
|
|
import Icon from "../react/Icon";
|
2025-12-11 18:53:48 +02:00
|
|
|
import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab";
|
2025-12-11 19:17:23 +02:00
|
|
|
import { BookProperty, CheckBoxProperty } from "../ribbon/collection-properties-config";
|
|
|
|
|
import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks";
|
2025-12-11 18:53:48 +02:00
|
|
|
|
2025-12-11 18:59:28 +02:00
|
|
|
const ICON_MAPPINGS: Record<ViewTypeOptions, string> = {
|
|
|
|
|
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"
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-11 18:53:48 +02:00
|
|
|
export default function CollectionProperties({ note }: { note: FNote }) {
|
|
|
|
|
return (
|
2025-12-11 19:17:23 +02:00
|
|
|
<>
|
|
|
|
|
<ViewTypeSwitcher note={note} />
|
|
|
|
|
<ViewOptions note={note} />
|
|
|
|
|
</>
|
2025-12-11 18:53:48 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewTypeSwitcher({ note }: { note: FNote }) {
|
|
|
|
|
const [ viewType, setViewType ] = useViewType(note);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown
|
2025-12-11 18:59:28 +02:00
|
|
|
text={<>
|
|
|
|
|
<Icon icon={ICON_MAPPINGS[viewType]} />
|
|
|
|
|
{VIEW_TYPE_MAPPINGS[viewType]}
|
|
|
|
|
</>}
|
2025-12-11 18:53:48 +02:00
|
|
|
>
|
|
|
|
|
{Object.entries(VIEW_TYPE_MAPPINGS).map(([ key, label ]) => (
|
|
|
|
|
<FormListItem
|
|
|
|
|
key={key}
|
|
|
|
|
onClick={() => setViewType(key)}
|
2025-12-11 18:59:28 +02:00
|
|
|
selected={viewType === key}
|
|
|
|
|
disabled={viewType === key}
|
|
|
|
|
icon={ICON_MAPPINGS[key as ViewTypeOptions]}
|
2025-12-11 18:53:48 +02:00
|
|
|
>{label}</FormListItem>
|
|
|
|
|
))}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-11 19:17:23 +02:00
|
|
|
|
|
|
|
|
function ViewOptions({ note }: { note: FNote }) {
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown
|
|
|
|
|
buttonClassName="bx bx-cog icon-action"
|
|
|
|
|
hideToggleArrow
|
|
|
|
|
>
|
|
|
|
|
<ViewProperty note={note} property={{
|
|
|
|
|
type: "checkbox",
|
|
|
|
|
label: t("book_properties.include_archived_notes"),
|
|
|
|
|
bindToLabel: "includeArchived"
|
|
|
|
|
} as CheckBoxProperty} />
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {
|
|
|
|
|
switch (property.type) {
|
|
|
|
|
case "checkbox":
|
|
|
|
|
return <CheckBoxPropertyView note={note} property={property} />;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CheckBoxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) {
|
|
|
|
|
const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel);
|
|
|
|
|
return (
|
|
|
|
|
<FormListToggleableItem
|
|
|
|
|
title={property.label}
|
|
|
|
|
currentValue={value}
|
|
|
|
|
onChange={setValue}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|