brf/client/public/components/objects_page.tsx

40 lines
1.1 KiB
TypeScript

import { h, type FunctionComponent } from 'preact'
import { useState } from 'preact/hooks'
import rek from 'rek'
import type { Object as ObjectType } from '../../../shared/types.ts'
import usePromise from '../../shared/hooks/use_promise.ts'
import Head from './head.ts'
import Object from './object.tsx'
import s from './results_page.module.scss'
const ObjectsPage: FunctionComponent = () => {
const objects = usePromise<ObjectType[]>(() => rek('/api/objects'))
const [currentObject, setCurrentObject] = useState<ObjectType | null>(null)
return (
<section>
<Head>
<title> : Objects</title>
</Head>
<h1>Objects</h1>
<div className={s.objects}>
{objects.map((object) => (
<button onClick={() => setCurrentObject(object)}>
{object.dimensionName}: {object.name}
</button>
))}
</div>
{currentObject ? (
<div>
<h2>{currentObject}</h2>
<Object objectId={currentObject.id} />
</div>
) : null}
</section>
)
}
export default ObjectsPage