From 83c0290549e43b9ef140f3aea5fa46348675930b Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EepyElvyra@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:12:46 +0100 Subject: [PATCH] stuff --- src/components/PluginSettings/PluginModal.tsx | 2 +- .../components/SettingListComponent.tsx | 134 +++++++++++------- src/plugins/loadingQuotes/index.ts | 19 +-- src/plugins/textReplace/index.tsx | 4 +- src/utils/types.ts | 6 +- 5 files changed, 98 insertions(+), 67 deletions(-) diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index b8d01276a..64dad2a70 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -83,7 +83,7 @@ const Components: Record { ; }; +const CheckMarkIcon = () => { + return + + ; +}; + + interface UserMentionComponentProps { id: string; channelId: string; @@ -52,30 +59,21 @@ export function SettingListComponent({ const [error, setError] = useState(null); const [items, setItems] = useState([]); - const [newItem, setNewItem] = useState(""); - - const addItem = () => { - if (newItem.trim() !== "") { - setItems([...items, newItem]); - setNewItem(""); - } - pluginSettings[id] = items; - }; if (items.length === 0 && pluginSettings[id].length !== 0) { setItems(pluginSettings[id]); } const removeItem = (index: number) => { + if (items.length === 1) { + setItems([]); + pluginSettings[id] = []; + return; + } setItems(items.filter((_, i) => i !== index)); pluginSettings[id] = items; }; - - function handleChange(newValue) { - onChange(newValue); - } - function wrapChannel(id: string) { const channel = ChannelStore.getChannel(id) as Channel; if (!channel) { @@ -84,48 +82,86 @@ export function SettingListComponent({ return (GuildStore.getGuild(channel.guild_id)?.name ?? "Unknown Guild") + " - " + channel.name; } + /* Pseudocode for handling submit */ + function handleSubmit() { + // Handle the submit action for the specific item + // This could involve updating the state, making an API call, etc. + // Clear the input field after submission + const inputElement = document.getElementById(`vc-plugin-modal-input-${option.type === OptionType.CHANNELS ? "channel" : option.type === OptionType.GUILDS ? "guild" : option.type === OptionType.USERS ? "user" : "string"}`); + if (!inputElement || inputElement.value === "") { + return; + } + // TODO add searching for users, channels, and guilds lol + setItems([...items, inputElement.value]); + pluginSettings[id] = items; + inputElement.value = ""; + } + + // FIXME make channels and guilds nicer! + // TODO make string type work return ( {wordsToTitle(wordsFromCamel(id))} {option.description} - {items.map((item, index) => ( - - - {option.type === OptionType.USERS ? ( - - ) : option.type === OptionType.CHANNELS ? ( - {wrapChannel(item)} - ) : option.type === OptionType.GUILDS ? ( - - {GuildStore.getGuild(item)?.name || "Unknown Guild"} - - // TODO add logo to guild and channel? - ) : ( - {item} - )} - + {option.type === OptionType.USERS ? ( + + ) : option.type === OptionType.CHANNELS ? ( + {wrapChannel(item)} + ) : option.type === OptionType.GUILDS ? ( + + {GuildStore.getGuild(item)?.name || "Unknown Guild"} + + // TODO add logo to guild and channel? + ) : ( + {item} + )} + - - ))} - + ))} + + {/* Add a single input field */} + + {/* Add a submit button */} + + + diff --git a/src/plugins/loadingQuotes/index.ts b/src/plugins/loadingQuotes/index.ts index 9bfc88a73..395f1d06e 100644 --- a/src/plugins/loadingQuotes/index.ts +++ b/src/plugins/loadingQuotes/index.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { definePluginSettings } from "@api/Settings"; +import { definePluginSettings, migrateSettingsToArrays } from "@api/Settings"; import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; @@ -25,6 +25,8 @@ import presetQuotesText from "file://quotes.txt"; const presetQuotes = presetQuotesText.split("\n").map(quote => /^\s*[^#\s]/.test(quote) && quote.trim()).filter(Boolean) as string[]; const noQuotesQuote = "Did you really disable all loading quotes? What a buffoon you are..."; +migrateSettingsToArrays("LoadingQuotes", ["additionalQuotes"], "|"); + const settings = definePluginSettings({ replaceEvents: { description: "Should this plugin also apply during events with special event themed quotes? (e.g. Halloween)", @@ -42,14 +44,8 @@ const settings = definePluginSettings({ default: false }, additionalQuotes: { - description: "Additional custom quotes to possibly appear, separated by the below delimiter", - type: OptionType.STRING, - default: "", - }, - additionalQuotesDelimiter: { - description: "Delimiter for additional quotes", - type: OptionType.STRING, - default: "|", + description: "Additional custom quotes to possibly appear", + type: OptionType.ARRAY, }, }); @@ -79,16 +75,15 @@ export default definePlugin({ mutateQuotes(quotes: string[]) { try { - const { enableDiscordPresetQuotes, additionalQuotes, additionalQuotesDelimiter, enablePluginPresetQuotes } = settings.store; + const { enableDiscordPresetQuotes, additionalQuotes, enablePluginPresetQuotes } = settings.store; if (!enableDiscordPresetQuotes) quotes.length = 0; - if (enablePluginPresetQuotes) quotes.push(...presetQuotes); - quotes.push(...additionalQuotes.split(additionalQuotesDelimiter).filter(Boolean)); + quotes.push(...additionalQuotes); if (!quotes.length) quotes.push(noQuotesQuote); diff --git a/src/plugins/textReplace/index.tsx b/src/plugins/textReplace/index.tsx index 4d98d4bb2..04500b746 100644 --- a/src/plugins/textReplace/index.tsx +++ b/src/plugins/textReplace/index.tsx @@ -72,12 +72,12 @@ const settings = definePluginSettings({ } }, stringRules: { - type: OptionType.LIST, + type: OptionType.ARRAY, hidden: true, description: "" }, regexRules: { - type: OptionType.LIST, + type: OptionType.ARRAY, hidden: true, description: "" }, diff --git a/src/utils/types.ts b/src/utils/types.ts index 1254f04ca..b4aff0fa5 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -167,7 +167,7 @@ export const enum OptionType { SELECT, SLIDER, COMPONENT, - LIST, + ARRAY, USERS, // List of users CHANNELS, // List of channels GUILDS, // List of guilds @@ -265,7 +265,7 @@ export interface PluginSettingSliderDef { } export interface PluginSettingListDef{ - type: OptionType.LIST | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS; + type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS; popoutText?: string; hidePopout?: boolean; } @@ -305,7 +305,7 @@ type PluginSettingType = O extends PluginSettingStri O extends PluginSettingComponentDef ? any : O extends PluginSettingListDef ? any[] : never; -type PluginSettingDefaultType = O extends PluginSettingSelectDef ? ( +type PluginSettingDefaultType = O extends PluginSettingListDef ? any[] : O extends PluginSettingSelectDef ? ( O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined ) : O extends { default: infer T; } ? T : undefined;