import { html, list, attribute, hydrate } from 'wirejs-dom/v2';
import { AuthenticatedContent } from 'wirejs-components';
import { todos, Todo } from 'internal-api';
import { Main } from '../layouts/main.js';
function Todos() {
const remove = (todo: Todo) => {
self.data.todos = self.data.todos.filter(t => t.id !== todo.id);
todos.remove(null, todo.id);
}
const newid = () => crypto.randomUUID();
const self = html`
Your Todos
${list('todos', (todo: Todo) => html`-
${todo.text} : remove(todo)}
>X
`)}
`.onadd(async self => {
self.data.todos = await todos.read(null, 'default');
});
return self;
}
async function App() {
const self = html`
${await AuthenticatedContent({
authenticated: () => Todos(),
unauthenticated: () => html`
You need to sign in to add your todo list.
`
})}
`;
return self;
}
export async function generate() {
return Main({
pageTitle: 'Todo App',
content: await App(),
});
}
export function onload() {
hydrate('app', App as any);
}