mirror of
https://github.com/fankes/beszel.git
synced 2025-10-22 03:19:22 +08:00
updates
This commit is contained in:
@@ -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> */}
|
||||
</>
|
||||
)
|
||||
|
@@ -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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user