moar stuff.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts" context="module">
|
||||
import { fetchUIState } from "$lib/client/lucifer";
|
||||
import type { IconName } from "$lib/components/DeviceIcon.svelte";
|
||||
import type { DeviceIconName } from "$lib/components/DeviceIcon.svelte";
|
||||
import type Assignment from "$lib/models/assignment";
|
||||
import type Device from "$lib/models/device";
|
||||
import type { UIStatePatch } from "$lib/models/uistate";
|
||||
import type UIState from "$lib/models/uistate";
|
||||
@@ -14,6 +15,7 @@
|
||||
state: Readable<UIState>
|
||||
error: Readable<string | null>
|
||||
deviceList: Readable<Device[]>
|
||||
assignmentList: Readable<Assignment[]>
|
||||
roomList: Readable<{name: string, groups: {name: string, devices: Device[]}[], devices: Device[]}[]>
|
||||
}
|
||||
|
||||
@@ -42,6 +44,17 @@
|
||||
.sort((a,b) => a.name.localeCompare(b.name));
|
||||
});
|
||||
|
||||
const assignmentList = derived(state, state => {
|
||||
if (state == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.keys(state.assignments)
|
||||
.map(k => state.assignments[k])
|
||||
.sort((a,b) => a.id.localeCompare(b.id));
|
||||
});
|
||||
|
||||
|
||||
const roomList = derived(state, state => {
|
||||
const roomMap: Record<string, Device[]> = {};
|
||||
const groupMap: Record<string, string> = {};
|
||||
@@ -129,7 +142,7 @@
|
||||
patch.name = patch.addAlias.slice("lucifer:name:".length)
|
||||
}
|
||||
if (patch.addAlias.startsWith("lucifer:icon:")) {
|
||||
patch.icon = patch.addAlias.slice("lucifer:icon:".length) as IconName
|
||||
patch.icon = patch.addAlias.slice("lucifer:icon:".length) as DeviceIconName
|
||||
}
|
||||
|
||||
if (exclExisting) {
|
||||
@@ -170,6 +183,28 @@
|
||||
const assignments = {...s.assignments};
|
||||
delete assignments[patch.assignment.id];
|
||||
s = {...s, assignments};
|
||||
} else if (patch.assignment.addDeviceId) {
|
||||
s = {
|
||||
...s,
|
||||
assignments: {
|
||||
...s.assignments,
|
||||
[patch.assignment.id]: {
|
||||
...s.assignments[patch.assignment.id],
|
||||
deviceIds: [...s.assignments[patch.assignment.id].deviceIds || [], patch.assignment.addDeviceId],
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (patch.assignment.removeDeviceId) {
|
||||
s = {
|
||||
...s,
|
||||
assignments: {
|
||||
...s.assignments,
|
||||
[patch.assignment.id]: {
|
||||
...s.assignments[patch.assignment.id],
|
||||
deviceIds: s.assignments[patch.assignment.id].deviceIds.map(id => id === patch.assignment.removeDeviceId ? "" : id),
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s = {
|
||||
...s,
|
||||
@@ -257,6 +292,7 @@
|
||||
error: { subscribe: error.subscribe },
|
||||
state: { subscribe: state.subscribe },
|
||||
deviceList,
|
||||
assignmentList,
|
||||
roomList,
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user