This commit is contained in:
Henry Dollman
2024-07-08 18:44:07 -04:00
parent 86ddb0ac12
commit 309bbf1fba
3 changed files with 82 additions and 31 deletions

View File

@@ -6,32 +6,39 @@ import { DataTable } from '../server-table/data-table'
export function Home() {
const [systems, setSystems] = useState([] as SystemRecord[])
useEffect(() => {
document.title = 'Home'
}, [])
useEffect(() => {
pb.collection<SystemRecord>('systems')
.getList(1, 20)
.then(({ items }) => {
.getFullList({
sort: 'name',
})
.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 = [...curSystems]
newSystems[i] = e.record
return newSystems
} else {
return [...curSystems, e.record]
}
})
})
return () => pb.collection('systems').unsubscribe('*')
// pb.collection<SystemRecord>('systems').subscribe('*', (e) => {
// setSystems((curSystems) => {
// const i = curSystems.findIndex((s) => s.id === e.record.id)
// if (i > -1) {
// const newSystems = [...curSystems]
// newSystems[i] = e.record
// return newSystems
// } else {
// return [...curSystems, e.record]
// }
// })
// })
// return () => pb.collection('systems').unsubscribe('*')
}, [])
// if (!systems.length) return <>Loading...</>
return (
<>
<h1 class="my-5">Dashboard</h1>
{systems.length && <DataTable data={systems} />}
<DataTable data={systems} />
{/* <pre>{JSON.stringify(systems, null, 2)}</pre> */}
</>
)

View File

@@ -1,12 +1,28 @@
import { useEffect } from 'preact/hooks'
import { pb } from '@/lib/stores'
import { SystemRecord } from '@/types'
import { useEffect, useState } from 'preact/hooks'
import { useRoute } from 'wouter-preact'
export function ServerDetail() {
const [_, params] = useRoute('/server/:name')
const [node, setNode] = useState({} as SystemRecord)
useEffect(() => {
document.title = `Server: ${params!.name}`
document.title = params!.name
}, [])
return <>Info for {params!.name}</>
useEffect(() => {
pb.collection<SystemRecord>('systems')
.getFirstListItem(`name="${params!.name}"`)
.then((record) => {
setNode(record)
})
})
return (
<>
<h1>{node.name}</h1>
<pre>{JSON.stringify(node, null, 2)}</pre>
</>
)
}