diff --git a/src/components/tag-input.tsx b/src/components/tag-input.tsx new file mode 100644 index 0000000..5ebc512 --- /dev/null +++ b/src/components/tag-input.tsx @@ -0,0 +1,69 @@ +import { createSignal, For, Show } from "solid-js"; +import { TextInput } from "./text-input"; + +export const TagInput = (props: { + name: string; + placeholder?: string; + initialValues?: string[]; +}) => { + const [tags, setTags] = createSignal(props.initialValues ?? []); + const [inputValue, setInputValue] = createSignal(""); + + const addTag = () => { + const value = inputValue().trim(); + if (value && !tags().includes(value)) { + setTags([...tags(), value]); + setInputValue(""); + } + }; + + const removeTag = (index: number) => { + setTags(tags().filter((_, i) => i !== index)); + }; + + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Enter") { + e.preventDefault(); + addTag(); + } + }; + + return ( +
+ +
+ setInputValue(e.currentTarget.value)} + onKeyDown={onKeyDown} + placeholder={props.placeholder} + class="min-w-0 grow" + /> + +
+ 0}> +
+ + {(tag, index) => ( + + )} + +
+
+
+ ); +}; diff --git a/src/components/text-input.tsx b/src/components/text-input.tsx index b54a5ae..1529e4d 100644 --- a/src/components/text-input.tsx +++ b/src/components/text-input.tsx @@ -10,6 +10,7 @@ export interface TextInputProps { spellcheck?: boolean; value?: string | string[]; onInput?: (ev: InputEvent & { currentTarget: HTMLInputElement }) => void; + onKeyDown?: (ev: KeyboardEvent & { currentTarget: HTMLInputElement }) => void; } export const TextInput = (props: TextInputProps) => { @@ -29,6 +30,7 @@ export const TextInput = (props: TextInputProps) => { props.class } onInput={props.onInput} + onKeyDown={props.onKeyDown} /> ); }; diff --git a/src/views/labels.tsx b/src/views/labels.tsx index 1ff5c02..d320fb7 100644 --- a/src/views/labels.tsx +++ b/src/views/labels.tsx @@ -7,6 +7,7 @@ import { createMemo, createSignal, For, onMount, Show } from "solid-js"; import { Button } from "../components/button.jsx"; import DidHoverCard from "../components/hover-card/did.jsx"; import RecordHoverCard from "../components/hover-card/record.jsx"; +import { TagInput } from "../components/tag-input.jsx"; import { TextInput } from "../components/text-input.jsx"; import { canHover } from "../layout.jsx"; import { getPDS, labelerCache, resolveHandle } from "../lib/api.js"; @@ -129,12 +130,7 @@ export const LabelView = () => { const fetchLabels = async (formData: FormData, reset?: boolean) => { let did = formData.get("did")?.toString()?.trim() || DEFAULT_LABELER_DID; - const uriPatterns = formData.get("uriPatterns")?.toString()?.trim(); - - if (!uriPatterns) { - setError("Please provide both DID and URI patterns"); - return; - } + const uriPatterns = formData.get("uriPatterns")?.toString()?.trim() || "*"; if (reset) { setLabels([]); @@ -219,16 +215,16 @@ export const LabelView = () => {