homeman-deno/routes/routine.tsx

27 lines
721 B
TypeScript
Raw Permalink Normal View History

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