1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-26 09:16:24 +00:00
This commit is contained in:
Elvy 2025-01-06 15:01:43 +01:00
parent 3d444c9a12
commit 01b9be63b9
2 changed files with 43 additions and 37 deletions

View file

@ -225,12 +225,14 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) {
} }
export function migrateSettingsToArrays(pluginName: string, settings: string[], stringSeparator: string = ",") { export function migrateSettingsToArrays(pluginName: string, settings: string[], stringSeparator: string = ",") {
const { plugins } = SettingsStore.plain;
for (const setting of settings) { for (const setting of settings) {
if (SettingsStore.plain.plugins[pluginName] === undefined || typeof SettingsStore.plain.plugins[pluginName][setting] !== "string") continue; if (plugins[pluginName] === undefined || typeof plugins[pluginName][setting] !== "string") continue;
logger.info(`Migrating setting ${setting} from ${pluginName} to list`); logger.info(`Migrating setting ${setting} from ${pluginName} to list`);
// @ts-ignore // @ts-ignore
if (SettingsStore.plain.plugins[pluginName][setting] === "") SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].default ?? []; if (plugins[pluginName][setting] === "") plugins[pluginName][setting] = plugins[pluginName][setting].default ?? [];
else SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].split(stringSeparator); else plugins[pluginName][setting] = plugins[pluginName][setting].split(stringSeparator);
} }
} }

View file

@ -60,6 +60,21 @@ export function SettingArrayComponent({
const [items, setItems] = useState<string[]>([]); const [items, setItems] = useState<string[]>([]);
const [text, setText] = useState<string>(""); const [text, setText] = useState<string>("");
useEffect(() => {
if (text === "") {
setError(null);
} else if (!isNaN(Number(text))) {
if (text.length >= 18 && text.length <= 19) {
setError(null);
} else {
setError("Invalid ID");
}
} else {
setError(null);
}
}, [text]);
useEffect(() => { useEffect(() => {
pluginSettings[id] = items; pluginSettings[id] = items;
onChange(items); onChange(items);
@ -373,21 +388,6 @@ export function SettingArrayComponent({
} }
function handleSubmit() { function handleSubmit() {
if (text === "") {
return;
}
if (option.type !== OptionType.ARRAY) {
if (isNaN(Number(text))) {
openSearchModal(text);
setText("");
return;
}
if (!(text.length >= 18 && text.length <= 19)) {
setError("Invalid ID");
return;
}
}
if (items.includes(text)) { if (items.includes(text)) {
setError("This item is already added"); setError("This item is already added");
setText(""); setText("");
@ -437,29 +437,33 @@ export function SettingArrayComponent({
> >
<TextInput <TextInput
type="text" type="text"
placeholder="Add Item (ID or Name)" placeholder="Enter text or ID"
id={cl("input")} id={cl("input")}
onChange={v => setText(v)} onChange={v => setText(v)}
value={text} value={text}
/> />
<Button {text === "" ? null :
size={Button.Sizes.MIN} !isNaN(Number(text)) ?
id={cl("add-button")} <Button
onClick={handleSubmit} size={Button.Sizes.MIN}
style={{ background: "none" }} id={cl("add-button")}
> onClick={handleSubmit}
<CheckMarkIcon /> style={{ background: "none" }}
</Button> disabled={text.length < 18 || text.length > 19}
<Button >
id={cl("search-button")} <CheckMarkIcon />
size={Button.Sizes.MIN} </Button> :
onClick={() => openSearchModal(text)} < Button
style={ id={cl("search-button")}
{ background: "none" } size={Button.Sizes.MIN}
} onClick={() => openSearchModal(text)}
> style={
<SearchIcon /> { background: "none" }
</Button> }
>
<SearchIcon />
</Button>
}
</Flex> </Flex>
</ErrorBoundary> </ErrorBoundary>
{error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>} {error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>}