Decks: save a typed tag when the bulk Tag dialog's Done is clicked
Some checks failed
ci/woodpecker/push/check Pipeline was successful
ci/woodpecker/manual/manual Pipeline was successful
ci/woodpecker/deployment/release Pipeline was canceled

This commit is contained in:
2026-11-10 21:56:25 -06:00
parent 39c81cccc3
commit a39098ada9
2 changed files with 26 additions and 3 deletions

View File

@@ -720,13 +720,24 @@ export function TagInput({
onChange,
suggestions,
placeholder,
text: textProp,
onTextChange,
}: {
values: string[];
onChange: (values: string[]) => void;
suggestions: string[];
placeholder?: string;
/** The typed, not yet added text, for a parent that wants to act on it
* (say, add it when its dialog is confirmed). Uncontrolled if omitted. */
text?: string;
onTextChange?: (text: string) => void;
}) {
const [text, setText] = useState("");
const [ownText, setOwnText] = useState("");
const text = textProp ?? ownText;
const setText = (t: string) => {
setOwnText(t);
onTextChange?.(t);
};
const [sel, setSel] = useState(0);
const query = fold(text.trim());

View File

@@ -552,6 +552,7 @@ function TagCardsDialog({
}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [pending, setPending] = useState("");
const counts = new Map<string, { tag: string; n: number }>();
for (const e of entries) {
for (const t of e.tags) {
@@ -562,18 +563,27 @@ function TagCardsDialog({
}
const used = [...counts.values()].sort((a, b) => a.tag.localeCompare(b.tag));
async function apply(add: string[], remove: string[]) {
async function apply(add: string[], remove: string[]): Promise<boolean> {
setBusy(true);
setError(null);
try {
await onChange(add, remove);
return true;
} catch (e) {
setError(String(e));
return false;
} finally {
setBusy(false);
}
}
// A tag typed but not yet added with Enter is still meant for the cards.
async function done() {
const tag = pending.trim();
if (tag && !(await apply([tag], []))) return;
onClose();
}
return (
<DialogFrame title={`Tag ${entries.length} ${entries.length === 1 ? "card" : "cards"}`} onCancel={onClose}>
{used.length > 0 && (
@@ -602,11 +612,13 @@ function TagCardsDialog({
onChange={(next) => next.length > 0 && apply(next, [])}
suggestions={suggestions}
placeholder="New tag…"
text={pending}
onTextChange={setPending}
/>
</label>
{error && <p className="dialog-error">{error}</p>}
<div className="dialog-actions">
<button className="primary" onClick={onClose}>
<button className="primary" onClick={done} disabled={busy}>
Done
</button>
</div>