homeman-deno/routes/routine.tsx

27 lines
721 B
TypeScript

import { Handlers, PageProps } from '$fresh/server.ts'
import { Task } from '@homeman/models.ts'
import { Routine } from '@homeman/islands/Routine.tsx'
import { kv } from '@homeman/db.ts'
// import { db, kv, Todo, UserWithTodos } from '@homeman/models.ts'
interface Data {
tasks: Task[]
}
export const handler: Handlers = {
async GET(req, ctx) {
const tasks = (await Array.fromAsync(kv.list({ prefix: ['task'] }))).map(
(r) => r.value,
)
const accept = req.headers.get('accept')
if (accept === 'application/json') {
return new Response(JSON.stringify(tasks))
}
return ctx.render({ tasks })
},
}
export default function Page(props: PageProps<Data>) {
return <Routine tasks={props.data.tasks} />
}