mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
do it nicer
This commit is contained in:
parent
1553751287
commit
f36e5a3a81
1 changed files with 7 additions and 9 deletions
|
@ -11,7 +11,7 @@ import { Margins } from "@utils/margins";
|
||||||
import { wordsFromCamel, wordsToTitle } from "@utils/text";
|
import { wordsFromCamel, wordsToTitle } from "@utils/text";
|
||||||
import { OptionType, PluginOptionList } from "@utils/types";
|
import { OptionType, PluginOptionList } from "@utils/types";
|
||||||
import { findByCodeLazy, findComponentByCodeLazy } from "@webpack";
|
import { findByCodeLazy, findComponentByCodeLazy } from "@webpack";
|
||||||
import { Avatar, Button, ChannelStore, Forms, GuildStore, IconUtils, React, Text, TextInput, useState } from "@webpack/common";
|
import { Avatar, Button, ChannelStore, Forms, GuildStore, IconUtils, React, Text, TextInput, useEffect, useState } from "@webpack/common";
|
||||||
import { Channel, Guild } from "discord-types/general";
|
import { Channel, Guild } from "discord-types/general";
|
||||||
import { JSX } from "react";
|
import { JSX } from "react";
|
||||||
|
|
||||||
|
@ -52,9 +52,12 @@ export function SettingArrayComponent({
|
||||||
id
|
id
|
||||||
}: ISettingElementProps<PluginOptionList>) {
|
}: ISettingElementProps<PluginOptionList>) {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [items, setItems] = useState<string[]>([]);
|
const [items, setItems] = useState<string[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
pluginSettings[id] = items;
|
||||||
|
}, [items, pluginSettings, id]);
|
||||||
|
|
||||||
if (items.length === 0 && pluginSettings[id].length !== 0) {
|
if (items.length === 0 && pluginSettings[id].length !== 0) {
|
||||||
setItems(pluginSettings[id]);
|
setItems(pluginSettings[id]);
|
||||||
}
|
}
|
||||||
|
@ -89,9 +92,7 @@ export function SettingArrayComponent({
|
||||||
pluginSettings[id] = [];
|
pluginSettings[id] = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newItems = items.filter((_, i) => i !== index);
|
setItems(items.filter((_, i) => i !== index));
|
||||||
setItems(newItems);
|
|
||||||
pluginSettings[id] = newItems;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderGuildView() {
|
function renderGuildView() {
|
||||||
|
@ -254,11 +255,8 @@ export function SettingArrayComponent({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newItems = [...items, inputElement.value];
|
setItems([...items, inputElement.value]);
|
||||||
|
|
||||||
setItems(newItems);
|
|
||||||
|
|
||||||
pluginSettings[id] = newItems;
|
|
||||||
inputElement.value = "";
|
inputElement.value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue