← Public packages
@kody/example-habit-log
A small habit log app built from the app starter: indigo theme, mobile layout, sign-in, and saved entries.
Files
import { packageStorage } from 'kody:runtime'
export type Item = { id: string; text: string; createdAt: string }
function keyFor(userId: string) {
return `items:${userId}`
}
/** Each signed-in person gets their own list in package storage. */
export async function listItems(userId: string): Promise<Array<Item>> {
const stored = await packageStorage().get(keyFor(userId))
return Array.isArray(stored) ? (stored as Array<Item>) : []
}
export async function addItem(userId: string, text: string) {
const item: Item = {
id: crypto.randomUUID(),
text,
createdAt: new Date().toISOString(),
}
await packageStorage().set(keyFor(userId), [item, ...(await listItems(userId))])
return item
}
export async function deleteItem(userId: string, id: string) {
const items = await listItems(userId)
await packageStorage().set(
keyFor(userId),
items.filter((item) => item.id !== id),
)
}