progress on client site

This commit is contained in:
Henry Dollman
2024-07-08 15:53:12 -04:00
parent 93e94bdec6
commit 89b06d00aa
35 changed files with 1312 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
import { useEffect, useState } from 'preact/hooks'
import { pb } from '@/lib/stores'
import { SystemRecord } from '@/types'
import { DataTable } from '../server-table/data-table'
export function Home() {
const [systems, setSystems] = useState([] as SystemRecord[])
useEffect(() => {
pb.collection<SystemRecord>('systems')
.getList(1, 20)
.then(({ items }) => {
setSystems(items)
})
pb.collection<SystemRecord>('systems').subscribe('*', (e) => {
setSystems((curSystems) => {
const i = curSystems.findIndex((s) => s.id === e.record.id)
if (i > -1) {
const newSystems = [...systems]
newSystems[i] = e.record
return newSystems
} else {
return [...curSystems, e.record]
}
})
})
return () => pb.collection('systems').unsubscribe('*')
}, [])
return (
<>
<h1>Dashboard</h1>
{systems.length && <DataTable data={systems} />}
<pre>{JSON.stringify(systems, null, 2)}</pre>
</>
)
}

View File

@@ -0,0 +1,12 @@
import { useEffect } from 'preact/hooks'
import { useRoute } from 'wouter-preact'
export function ServerDetail() {
const [_, params] = useRoute('/server/:name')
useEffect(() => {
document.title = `Server: ${params!.name}`
}, [])
return <>Info for {params!.name}</>
}