mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-25 00:36:23 +00:00
thimgs
This commit is contained in:
parent
3d444c9a12
commit
01b9be63b9
2 changed files with 43 additions and 37 deletions
|
@ -225,12 +225,14 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) {
|
|||
}
|
||||
|
||||
export function migrateSettingsToArrays(pluginName: string, settings: string[], stringSeparator: string = ",") {
|
||||
const { plugins } = SettingsStore.plain;
|
||||
|
||||
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`);
|
||||
// @ts-ignore
|
||||
if (SettingsStore.plain.plugins[pluginName][setting] === "") SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].default ?? [];
|
||||
else SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].split(stringSeparator);
|
||||
if (plugins[pluginName][setting] === "") plugins[pluginName][setting] = plugins[pluginName][setting].default ?? [];
|
||||
else plugins[pluginName][setting] = plugins[pluginName][setting].split(stringSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,21 @@ export function SettingArrayComponent({
|
|||
const [items, setItems] = 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(() => {
|
||||
pluginSettings[id] = items;
|
||||
onChange(items);
|
||||
|
@ -373,21 +388,6 @@ export function SettingArrayComponent({
|
|||
}
|
||||
|
||||
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)) {
|
||||
setError("This item is already added");
|
||||
setText("");
|
||||
|
@ -437,29 +437,33 @@ export function SettingArrayComponent({
|
|||
>
|
||||
<TextInput
|
||||
type="text"
|
||||
placeholder="Add Item (ID or Name)"
|
||||
placeholder="Enter text or ID"
|
||||
id={cl("input")}
|
||||
onChange={v => setText(v)}
|
||||
value={text}
|
||||
/>
|
||||
<Button
|
||||
size={Button.Sizes.MIN}
|
||||
id={cl("add-button")}
|
||||
onClick={handleSubmit}
|
||||
style={{ background: "none" }}
|
||||
>
|
||||
<CheckMarkIcon />
|
||||
</Button>
|
||||
<Button
|
||||
id={cl("search-button")}
|
||||
size={Button.Sizes.MIN}
|
||||
onClick={() => openSearchModal(text)}
|
||||
style={
|
||||
{ background: "none" }
|
||||
}
|
||||
>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
{text === "" ? null :
|
||||
!isNaN(Number(text)) ?
|
||||
<Button
|
||||
size={Button.Sizes.MIN}
|
||||
id={cl("add-button")}
|
||||
onClick={handleSubmit}
|
||||
style={{ background: "none" }}
|
||||
disabled={text.length < 18 || text.length > 19}
|
||||
>
|
||||
<CheckMarkIcon />
|
||||
</Button> :
|
||||
< Button
|
||||
id={cl("search-button")}
|
||||
size={Button.Sizes.MIN}
|
||||
onClick={() => openSearchModal(text)}
|
||||
style={
|
||||
{ background: "none" }
|
||||
}
|
||||
>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
}
|
||||
</Flex>
|
||||
</ErrorBoundary>
|
||||
{error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>}
|
||||
|
|
Loading…
Reference in a new issue