diff --git a/package.json b/package.json index ebd916c..52215ad 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "dependencies": { - "@colonydb/anthill": "0.2.0-13", + "@colonydb/anthill": "0.2.0-14", "jsdom": "^26.0.0", "next": "15.2.1", "react": "^19.0.0", "react-dom": "^19.0.0", "swr": "^2.3.3", - "uuid": "^11.1.0" + "uuid": "^11.1.0", + "valibot": "^1.1.0" }, "devDependencies": { "@biomejs/biome": "2.1.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 520535c..71adfc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@colonydb/anthill': - specifier: 0.2.0-13 - version: 0.2.0-13(@types/react@19.1.9)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(valibot@1.1.0(typescript@5.9.2)) + specifier: 0.2.0-14 + version: 0.2.0-14(@types/react@19.1.9)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(valibot@1.1.0(typescript@5.9.2)) jsdom: specifier: ^26.0.0 version: 26.1.0 @@ -29,6 +29,9 @@ importers: uuid: specifier: ^11.1.0 version: 11.1.0 + valibot: + specifier: ^1.1.0 + version: 1.1.0(typescript@5.9.2) devDependencies: '@biomejs/biome': specifier: 2.1.4 @@ -110,8 +113,8 @@ packages: cpu: [x64] os: [win32] - '@colonydb/anthill@0.2.0-13': - resolution: {integrity: sha512-soPF9RXIKocRXrTrYzYzZEv8aikcu4yvrZvyQjn2lMGYeZrkJBI0dOVGsLqKGq5WndhuS6WyNvt+fSbiYdAr4A==} + '@colonydb/anthill@0.2.0-14': + resolution: {integrity: sha512-6cOqJWlAiHdtPWIjgOyoXCFFBfPzCdXqpV/eWzIM49dFhH3guEsKVpwpOnvak+wI4mFmWu8lseRRzCSR+e0mTw==} peerDependencies: react: ^19.0.0 react-dom: ^19.0.0 @@ -931,7 +934,7 @@ snapshots: '@biomejs/cli-win32-x64@2.1.4': optional: true - '@colonydb/anthill@0.2.0-13(@types/react@19.1.9)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(valibot@1.1.0(typescript@5.9.2))': + '@colonydb/anthill@0.2.0-14(@types/react@19.1.9)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(valibot@1.1.0(typescript@5.9.2))': dependencies: '@haydn/universal': 0.0.4 clsx: 2.1.1 diff --git a/src/app/ListForm.tsx b/src/app/ListForm.tsx index 6e8bb2d..0d2e5a0 100644 --- a/src/app/ListForm.tsx +++ b/src/app/ListForm.tsx @@ -1,6 +1,7 @@ import { Button } from "@colonydb/anthill/Button"; import { RegularField } from "@colonydb/anthill/RegularField"; import { Stack } from "@colonydb/anthill/Stack"; +import { StringInput } from "@colonydb/anthill/StringInput"; import { useState } from "react"; import type { ListConfig } from "."; import List from "./List"; @@ -21,97 +22,73 @@ const ListForm = ({ list: initialList, onSubmit }: Props) => { > - { - setList({ ...list, name: event.target.value }); - }} - size={100} + { + setList({ ...list, name }); + }} + value={list.name} /> - { - setList({ ...list, url: event.target.value }); - }} - size={100} + { + setList({ ...list, url }); + }} + value={list.url} /> - { - setList({ ...list, itemSelector: event.target.value }); - }} - size={100} + { + setList({ ...list, itemSelector }); + }} + value={list.itemSelector} /> - { - setList({ ...list, titleSelector: event.target.value }); - }} - size={100} + { + setList({ ...list, titleSelector }); + }} + value={list.titleSelector} /> - { - setList({ ...list, linkSelector: event.target.value }); - }} - size={100} + { + setList({ ...list, linkSelector }); + }} + value={list.linkSelector} /> - { - setList({ ...list, include: event.target.value }); - }} - size={100} + { + setList({ ...list, include }); + }} + value={list.include} /> - { - setList({ ...list, exclude: event.target.value }); - }} - size={100} + { + setList({ ...list, exclude }); + }} + value={list.exclude} /> {list.name.trim() === "" || diff --git a/src/app/page.tsx b/src/app/page.tsx index 76a312a..43efd3b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,6 @@ "use client"; +import { ActionSet } from "@colonydb/anthill/ActionSet"; import { Button } from "@colonydb/anthill/Button"; import { Card } from "@colonydb/anthill/Card"; import { CardContent } from "@colonydb/anthill/CardContent"; @@ -7,10 +8,11 @@ import { Dialog } from "@colonydb/anthill/Dialog"; import { Header } from "@colonydb/anthill/Header"; import { Heading } from "@colonydb/anthill/Heading"; import { Icon } from "@colonydb/anthill/Icon"; +import { MutliColumnStack } from "@colonydb/anthill/MutliColumnStack"; import { Section } from "@colonydb/anthill/Section"; -import { Stack } from "@colonydb/anthill/Stack"; import useSWR from "swr/immutable"; import { v4 as uuid } from "uuid"; +import * as v from "valibot"; import type { ListConfig } from "."; // import Dialog from "./Dialog"; import List from "./List"; @@ -33,6 +35,19 @@ const HomePage = () => { const addList = (list: ListConfig) => mutate( async (current) => { + v.parse( + v.object({ + exclude: v.optional(v.string()), + id: v.string(), + include: v.optional(v.string()), + itemSelector: v.pipe(v.string(), v.nonEmpty()), + linkSelector: v.optional(v.string()), + name: v.pipe(v.string(), v.nonEmpty()), + titleSelector: v.optional(v.string()), + url: v.pipe(v.string(), v.nonEmpty(), v.url()), + }), + list, + ); const value = current ? [...current, list] : [list]; localStorage.setItem("lists", JSON.stringify(value)); return value; @@ -94,6 +109,7 @@ const HomePage = () => { )} + width="medium" > Add list @@ -103,82 +119,88 @@ const HomePage = () => { } > -
- - {(lists ?? []) - .sort((a, b) => a.name.localeCompare(b.name)) - .map((list) => ( -
- - } - render={(closeDialog) => ( - Remove List} - footer={ - <> - + + + } + > + Are you sure you want to remove this list? + + )} + width="narrow" + > + Remove list + + ), + key: "remove", + }, + { + content: ( + } + render={(closeDialog) => ( + Edit List}> + + { + updateList(list); closeDialog(); }} - submit - > - Confirm - - - - } - > - Are you sure you want to remove this list? - - )} - width="narrow" - > - Remove list - - } - render={(closeDialog) => ( - Edit List}> - - { - updateList(list); - closeDialog(); - }} - /> - - - )} - > - Edit list - -
- } - {...list} + /> + + + )} + width="medium" + > + Edit list + + ), + key: "edit", + }, + ]} + title="Edit" /> -
- ))} -
- + } + key={list.id} + {...list} + /> + ))} + ); };