From c8df5e044b56c48caffa1920efa7e75dc401ac2e Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:22:33 -0600 Subject: [PATCH] update keyword notify --- src/plugins/keywordNotify/index.tsx | 77 +++++++++++++++++++++++------ src/plugins/keywordNotify/style.css | 9 ++++ 2 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 src/plugins/keywordNotify/style.css diff --git a/src/plugins/keywordNotify/index.tsx b/src/plugins/keywordNotify/index.tsx index 3633a0db5..9eee42d45 100644 --- a/src/plugins/keywordNotify/index.tsx +++ b/src/plugins/keywordNotify/index.tsx @@ -16,35 +16,81 @@ * along with this program. If not, see . */ -import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { TextArea, useState, Forms } from "@webpack/common"; -import { definePluginSettings } from "@api/Settings"; import { DataStore } from "@api/index"; +import { definePluginSettings } from "@api/Settings"; +import { DeleteIcon } from "@components/Icons"; +import { Devs } from "@utils/constants"; +import { Flex } from "@components/Flex"; +import { TextInput, useState, Forms, Button } from "@webpack/common"; +import { useForceUpdater } from "@utils/react"; +import "./style.css"; let regexes = []; -async function setRegexes(regs: string) { - regexes = regs.split("\n"); +async function setRegexes(idx: number, reg: string) { + regexes[idx] = reg; await DataStore.set("KeywordNotify_rules", regexes); } +async function removeRegex(idx: number, updater: () => void) { + regexes.splice(idx, 1); + await DataStore.set("KeywordNotify_rules", regexes); + updater(); +} + +async function addRegex(updater: () => void) { + regexes.push(""); + await DataStore.set("KeywordNotify_rules", regexes); + updater(); +} + const settings = definePluginSettings({ replace: { type: OptionType.COMPONENT, description: "", component: () => { - const [value, setValue] = useState(regexes.join("\n")); + const update = useForceUpdater(); + const [values, setValues] = useState(regexes); + + const elements = regexes.map((a, i) => { + const setValue = (v: string) => { + let valuesCopy = [...values]; + valuesCopy[i] = v; + setValues(valuesCopy); + } + + return ( + <> + Keyword Regex {i + 1} + + +
+ setRegexes(i, values[i])} + /> +
+ + +
+ + ) + }); + return ( <> - Keyword Regexes (newline-separated) -