2024-01-21 11:31:15 -06:00
|
|
|
import { Handlers, PageProps } from '$fresh/server.ts'
|
2024-01-21 14:23:45 -06:00
|
|
|
import { Task } from '@homeman/models.ts'
|
2024-01-21 11:31:15 -06:00
|
|
|
import { Routine } from '@homeman/islands/Routine.tsx'
|
2024-01-21 18:11:25 -06:00
|
|
|
import { kv } from '@homeman/db.ts'
|
2024-01-21 11:31:15 -06:00
|
|
|
// 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 })
|
2024-01-21 11:31:15 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Page(props: PageProps<Data>) {
|
2024-01-21 14:23:45 -06:00
|
|
|
return <Routine tasks={props.data.tasks} />
|
2024-01-21 11:31:15 -06:00
|
|
|
}
|