From 8dca5645dfcd7128a9abb44bdba18043d4d8e839 Mon Sep 17 00:00:00 2001 From: ioj4 <69911332+ioj4@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:31:48 +0100 Subject: [PATCH] [text-replacements] make modal behavior a bit more intuitive (#15) * [text-replacements] make modal behavior a bit more intuitive - remove delete button in editing modal - when creating a new regex and cancelling don't store an empty regex * [text-replacements] forgot semicolon --- plugins/text-replacements/settings.tsx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugins/text-replacements/settings.tsx b/plugins/text-replacements/settings.tsx index 2377e3d..67d0614 100644 --- a/plugins/text-replacements/settings.tsx +++ b/plugins/text-replacements/settings.tsx @@ -25,9 +25,9 @@ const { createSignal } = shelter.solid; // @ts-expect-error const { store } = shelter.plugin; -const openEditDialog = (idx: number, isAdd?: boolean) => +const openEditDialog = (idx?: number) => openModal((props) => { - const initial = store.regexes[idx]; + const initial = idx ? store.regexes[idx]: ["", "", "gi", ""]; const [name, setName] = createSignal(initial[0]); const [regexp, setRegexp] = createSignal(initial[1]); const [flags, setFlags] = createSignal(initial[2]); @@ -36,7 +36,7 @@ const openEditDialog = (idx: number, isAdd?: boolean) => return ( - {isAdd ? "Adding" : "Editing"} "{name()}" + {idx ? "Editing" : "Adding"} "{name()}"
Name
@@ -66,26 +66,22 @@ const openEditDialog = (idx: number, isAdd?: boolean) =>
{ - store.regexes.splice(idx, 1); - // save! - store.regexes = store.regexes; - }} onConfirm={() => { - store.regexes[idx] = [name(), regexp(), flags(), replace()]; + const newRegex = [name(), regexp(), flags(), replace()]; + if (idx) { + store.regexes[idx] = newRegex; + } else { + store.regexes.push(newRegex); + } // save! store.regexes = store.regexes; }} confirmText="Save" - cancelText="Delete" />
); }); -const add = () => - openEditDialog(store.regexes.push(["", "", "gi", ""]) - 1, true); - function swap(idx1: number, idx2: number) { const tmp = store.regexes[idx1]; store.regexes[idx1] = store.regexes[idx2]; @@ -108,7 +104,7 @@ export const settings: Component = () => ( Actions - {store.regexes.map(([name, regexp, flags, replace], idx) => ( + {store.regexes.map(([name], idx) => ( <>
{name}
@@ -177,7 +173,7 @@ export const settings: Component = () => ( -