import "./HomePage.css" import { ActionMenu } from "./components/ActionMenu" import { LogoIcon } from "./components/icons/LogoIcon" import { MoreIcon } from "./components/icons/MoreIcon" import { JsonUtils } from "./idb" import { useGlobal } from "./state/global" import { Board } from "./types" import { Link, useState } from "kaioken" function readFile(file: Blob): Promise { return new Promise((resolve) => { const reader = new FileReader() reader.addEventListener("load", () => resolve(reader.result as string)) reader.readAsText(file, "UTF-8") }) } export function HomePage() { const [showArchived, setShowArchived] = useState(false) const [menuOpen, setMenuOpen] = useState(false) const { boards, addBoard } = useGlobal() const activeBoards = boards?.filter((b) => !b.archived) ?? [] const archivedBoards = boards?.filter((b) => b.archived) ?? [] return (

Kaioban

setMenuOpen(false)} items={[ { text: `${showArchived ? "Hide" : "Show"} archived boards`, onclick: () => { setShowArchived((prev) => !prev) setMenuOpen(false) }, }, { text: "Export data", onclick: async () => { const data = await JsonUtils.export() const dateStr = new Date() .toLocaleString() .split(",")[0] .replaceAll("/", "-") const a = document.createElement("a") const file = new Blob([data], { type: "application/json" }) a.href = URL.createObjectURL(file) a.download = `kaioban-export-${dateStr}.json` a.click() setMenuOpen(false) }, }, { text: "Import data", onclick: () => { const confirmOverwrite = confirm( "Continuing will overwrite your existing data. Are you sure you want to continue?" ) if (!confirmOverwrite) return const input = Object.assign(document.createElement("input"), { type: "file", accept: ".json", onchange: async () => { const file = input.files?.[0] if (!file) return const data = await readFile(file) console.log("IMPORT", data) await JsonUtils.import(data) const newLoc = new Location() newLoc.replace("/") window.location = newLoc }, }) input.click() }, }, ]} />

Boards

{activeBoards.length > 0 && (
{activeBoards.map((board) => ( ))}
)}
{showArchived && ( <>

Archived Boards

{archivedBoards.length > 0 ? ( archivedBoards.map((board) => ) ) : (
No archived boards
)}
)}
) } function BoardCard({ board }: { board: Board }) { return ( {board.title || "(Unnamed board)"} ) }