diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 4f059f9c..1388b892 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -50,21 +50,17 @@ dev.description.toLowerCase().includes(searchQuery.toLowerCase()) ); - function devicesWithoutGroups() { - return filteredDevices.filter((dev) => dev.groups.length === 0); - } + $: devicesWithoutGroups = filteredDevices.filter((dev) => dev.groups.length === 0); - function devicesWithGroup() { - return filteredDevices.reduce( - (groups, dev) => { - dev.expand?.groups?.forEach((group: Group) => { - groups[group.id] = [...(groups[group.id] || []), dev]; - }); - return groups; - }, - {} as Record - ); - } + $: devicesWithGroup = filteredDevices.reduce( + (groups, dev) => { + dev.expand?.groups?.forEach((group: Group) => { + groups[group.id] = [...(groups[group.id] || []), dev]; + }); + return groups; + }, + {} as Record + ); function getAllDevices() { $pocketbase @@ -97,7 +93,12 @@ orderByGroups = localStorage.getItem('orderByGroups') !== 'false'; getAllDevices(); ['devices', 'ports', 'permissions'].forEach((collection) => - $pocketbase.collection(collection).subscribe('*', getAllDevices) + $pocketbase + .collection(collection) + .subscribe('*', getAllDevices) + .then(() => { + console.log('Subscribed to changes in collection:', collection); + }) ); }); @@ -164,14 +165,14 @@ {#if orderByGroups}
- {#if devicesWithoutGroups().length > 0} + {#if devicesWithoutGroups.length > 0}
- {#each devicesWithoutGroups().sort( (a, b) => a[orderBy].localeCompare( b[orderBy], $localeStore, { numeric: true } ) ) as device (device.id)} + {#each structuredClone(devicesWithoutGroups).sort( (a, b) => a[orderBy].localeCompare( b[orderBy], $localeStore, { numeric: true } ) ) as device (device.id)} {/each}
{/if} - {#each Object.entries(devicesWithGroup()).sort( ([a], [b]) => a.localeCompare( b, $localeStore, { numeric: true } ) ) as [group, groupDevices], i (i)} + {#each Object.entries(devicesWithGroup).sort( ([a], [b]) => a.localeCompare( b, $localeStore, { numeric: true } ) ) as [group, groupDevices], i (i)}

{groupDevices[0].expand.groups.find((grp) => grp.id === group)?.name ||