diff --git a/package.json b/package.json index 8b6db1b..c04d7f9 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@nostr-dev-kit/ndk": "^0.0.13", "@solidjs/meta": "^0.28.4", "@solidjs/router": "^0.8.2", + "@thisbeyond/solid-select": "^0.14.0", "class-variance-authority": "^0.4.0", "nostr-tools": "^1.10.1", "qr-scanner": "^1.4.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68ba590..28f100e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,6 +28,9 @@ dependencies: '@solidjs/router': specifier: ^0.8.2 version: 0.8.2(solid-js@1.7.3) + '@thisbeyond/solid-select': + specifier: ^0.14.0 + version: 0.14.0(solid-js@1.7.3) class-variance-authority: specifier: ^0.4.0 version: 0.4.0(typescript@4.9.5) @@ -1971,6 +1974,14 @@ packages: tslib: 2.5.0 dev: false + /@thisbeyond/solid-select@0.14.0(solid-js@1.7.3): + resolution: {integrity: sha512-ecq4U3Vnc/nJbU84ARuPg2scNuYt994ljF5AmBlzuZW87x43mWiGJ5hEWufIJJMpDT6CcnCIx/xbrdDkaDEHQw==} + peerDependencies: + solid-js: ^1.5 + dependencies: + solid-js: 1.7.3 + dev: false + /@types/babel__core@7.20.0: resolution: {integrity: sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==} dependencies: diff --git a/src/components/TagEditor.tsx b/src/components/TagEditor.tsx new file mode 100644 index 0000000..284ebba --- /dev/null +++ b/src/components/TagEditor.tsx @@ -0,0 +1,84 @@ +import { Select, createOptions } from "@thisbeyond/solid-select"; +import { For, createSignal } from "solid-js"; +import "~/styles/solid-select.css" +import { SmallHeader } from "./layout"; + + +// take two arrays, subtract the second from the first, then return the first +function subtract(a: T[], b: T[]) { + const set = new Set(b); + return a.filter(x => !set.has(x)); +}; + +// combine two arrays and keep only the items that are unique +function combineUnique(a: T[], b: T[]) { + const set = new Set([...a, ...b]); + return [...set]; +}; + +// simple math.random based id generator +const createUniqueId = () => Math.random().toString(36).substr(2, 9); + +type Contact = { + id: string; + name: string; +} + +const fakeContacts: Contact[] = [ + { id: createUniqueId(), name: "👤 Alice" }, + { id: createUniqueId(), name: "👤 Tony" }, + { id: createUniqueId(), name: "👤 @benthecarman" }, + { id: createUniqueId(), name: "👀 Uknown" } +] + +const createValue = (name: string) => { + return { id: createUniqueId(), name }; +}; + +export function TagEditor() { + const candidates = [...fakeContacts]; + + const [values, setValues] = createSignal(candidates); + const [selectedValues, setSelectedValues] = createSignal([]); + + const onChange = (selected: Contact[]) => { + setSelectedValues(selected); + + const lastValue = selected[selected.length - 1]; + if (lastValue && !values().includes(lastValue)) { + setValues([...values(), lastValue]); + } + }; + + const props = createOptions(values, { + key: "name", + disable: (value) => selectedValues().includes(value), + filterable: true, // Default + createable: createValue, + }); + + return ( +
+ Tag the origin +