[ui] remember widget choice per object
parent
d21dbebd66
commit
2614fbdec2
|
@ -6,15 +6,23 @@
|
|||
import type { UpEntry } from "upend";
|
||||
import Icon from "./utils/Icon.svelte";
|
||||
import IconButton from "./utils/IconButton.svelte";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let entries: UpEntry[];
|
||||
export let type: UpType | undefined = undefined;
|
||||
export let title: string | undefined = undefined;
|
||||
export let editable = false;
|
||||
export let reverse = false;
|
||||
export let initialWidget: string | undefined = undefined;
|
||||
|
||||
let currentWidget: string | undefined;
|
||||
|
||||
function switchWidget(widget: string) {
|
||||
currentWidget = widget;
|
||||
dispatch("widgetSwitched", currentWidget);
|
||||
}
|
||||
|
||||
let availableWidgets: Widget[] = [];
|
||||
$: {
|
||||
availableWidgets = [
|
||||
|
@ -32,7 +40,11 @@
|
|||
if (type?.widgetInfo.length > 0) {
|
||||
availableWidgets = [...type.widgetInfo, ...availableWidgets];
|
||||
}
|
||||
currentWidget = availableWidgets[0].name;
|
||||
if (availableWidgets.map((w) => w.name).includes(initialWidget)) {
|
||||
currentWidget = initialWidget;
|
||||
} else {
|
||||
currentWidget = availableWidgets[0].name;
|
||||
}
|
||||
}
|
||||
|
||||
let components: Component[] = [];
|
||||
|
@ -71,7 +83,7 @@
|
|||
name={widget.icon || "question-diamond"}
|
||||
active={widget.name === currentWidget}
|
||||
--active-color="var(--foreground)"
|
||||
on:click={() => (currentWidget = widget.name)}
|
||||
on:click={() => switchWidget(widget.name)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
|
||||
$: filteredUntypedAttributes = untypedAttributes.filter(
|
||||
(entry) =>
|
||||
!["IS", "LBL", "NOTE", "LAST_VISITED", "NUM_VISITED"].includes(
|
||||
!["IS", "LBL", "NOTE", "LAST_VISITED", "NUM_VISITED", "LAST_ATTRIBUTE_WIDGET"].includes(
|
||||
entry.attribute
|
||||
)
|
||||
);
|
||||
|
@ -189,6 +189,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function onAttributeWidgetSwitch(ev: CustomEvent<string>) {
|
||||
await putEntityAttribute(address, "LAST_ATTRIBUTE_WIDGET", {
|
||||
t: "String",
|
||||
c: ev.detail,
|
||||
});
|
||||
}
|
||||
|
||||
$: entity.subscribe(async (object) => {
|
||||
if (object) {
|
||||
await putEntityAttribute(object.address, "LAST_VISITED", {
|
||||
|
@ -255,6 +262,8 @@
|
|||
type={allTypes[typeAddr]}
|
||||
{editable}
|
||||
on:change={onChange}
|
||||
initialWidget={String($entity.get("LAST_ATTRIBUTE_WIDGET"))}
|
||||
on:widgetSwitched={onAttributeWidgetSwitch}
|
||||
/>
|
||||
{/each}
|
||||
|
||||
|
|
Loading…
Reference in New Issue