diff --git a/src/components/PluginSettings/components/SettingArrayComponent.tsx b/src/components/PluginSettings/components/SettingArrayComponent.tsx index 81aba533c..47c0166d2 100644 --- a/src/components/PluginSettings/components/SettingArrayComponent.tsx +++ b/src/components/PluginSettings/components/SettingArrayComponent.tsx @@ -6,20 +6,22 @@ import { classNameFactory } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; -import { Flex } from "@components/Flex"; import { debounce } from "@shared/debounce"; import { Margins } from "@utils/margins"; import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { wordsFromCamel, wordsToTitle } from "@utils/text"; import { OptionType, PluginOptionList } from "@utils/types"; import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { Avatar, Button, ChannelStore, Forms, GuildStore, IconUtils, React, Text, TextInput, useCallback, useEffect, useRef, useState } from "@webpack/common"; +import { Avatar, Button, ChannelStore, Flex, Forms, GuildStore, Heading, IconUtils, React, Text, TextInput, useCallback, useEffect, useRef, useState } from "@webpack/common"; import { Channel, Guild } from "discord-types/general"; import { ISettingElementProps } from "."; const cl = classNameFactory("vc-plugin-modal-"); + +// TODO add interfaces for the stuff from the modal instead of using any + const UserMentionComponent = findComponentByCodeLazy(".USER_MENTION)"); const getDMChannelIcon = findByCodeLazy(".getChannelIconURL({"); const GroupDMAvatars = findComponentByCodeLazy(".AvatarSizeSpecs[", "getAvatarURL"); @@ -60,8 +62,13 @@ export function SettingArrayComponent({ useEffect(() => { pluginSettings[id] = items; + onChange(items); }, [items, pluginSettings, id]); + useEffect(() => { + onError(error !== null); + }, [error]); + if (items.length === 0 && pluginSettings[id].length !== 0) { setItems(pluginSettings[id]); } @@ -79,6 +86,11 @@ export function SettingArrayComponent({ "guilds": [], "users": [] }); + const [selected, setSelected] = useState([]); + + const onConfirm = () => { + + }; const searchHandlerRef = useRef(null); @@ -114,13 +126,21 @@ export function SettingArrayComponent({ return ( - - Search for { - option.type === OptionType.USERS ? "Users" : option.type === OptionType.CHANNELS ? "Channels" : "Guilds" - } - - - + +
+
+ Search for { + option.type === OptionType.USERS ? "Users" : option.type === OptionType.CHANNELS ? "Channels" : "Guilds" + } + All selected items will be added to {wordsToTitle(wordsFromCamel(id))} +
+ +
+
+ + - - + + -
+ ); } @@ -342,11 +376,16 @@ export function SettingArrayComponent({ if (text === "") { return; } - if (option.type !== OptionType.ARRAY && !(text.length >= 18 && text.length <= 19 && !isNaN(Number(text)))) { - openSearchModal(); - setText(""); - // FIXME - 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)) { @@ -398,7 +437,7 @@ export function SettingArrayComponent({ > setText(v)} value={text} @@ -414,7 +453,7 @@ export function SettingArrayComponent({