diff --git a/components/common/ChakraSelect.tsx b/components/common/ChakraSelect.tsx new file mode 100644 index 000000000..04bb01b34 --- /dev/null +++ b/components/common/ChakraSelect.tsx @@ -0,0 +1,30 @@ +import { Select } from "@chakra-ui/react"; + +interface Props { + value: string; + setValue: (value?: string) => void; + placeholder?: string; + name?: string; + children: React.ReactNode; +} + +const ChakraSelect: React.FC = ({ + value, + setValue, + placeholder, + children, + name, +}) => ( + +); + +export default ChakraSelect; diff --git a/components/common/GearSelector.tsx b/components/common/GearSelector.tsx new file mode 100644 index 000000000..cebc0ff02 --- /dev/null +++ b/components/common/GearSelector.tsx @@ -0,0 +1,52 @@ +import { Box, Flex } from "@chakra-ui/react"; +import { useLingui } from "@lingui/react"; +import { gear } from "lib/lists/gear"; +import { components } from "react-select"; +import GearImage from "./GearImage"; +import MySelect from "./MySelect"; + +interface WeaponSelectorProps { + value?: string; + setValue: (value: string) => void; + slot: "head" | "clothing" | "shoes"; +} + +const GearSelector: React.FC = ({ + value, + setValue, + slot, +}) => { + const { i18n } = useLingui(); + const singleOption = (props: any) => ( + + + + + + {props.label} + + + ); + + return ( + ({ + label: i18n._(category.brand), + options: category[slot].map((gear) => ({ + value: gear, + label: i18n._(gear), + })), + }))} + value={value ? { value, label: i18n._(value) } : undefined} + setValue={setValue} + isClearable + isSearchable + components={{ + IndicatorSeparator: () => null, + Option: singleOption, + }} + /> + ); +}; + +export default GearSelector; diff --git a/components/u/BuildModal.tsx b/components/u/BuildModal.tsx index b5aa0acfe..ebc193f43 100644 --- a/components/u/BuildModal.tsx +++ b/components/u/BuildModal.tsx @@ -15,7 +15,6 @@ import { ModalFooter, ModalHeader, ModalOverlay, - Select, Stack, Textarea, useToast, @@ -24,9 +23,9 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { t, Trans } from "@lingui/macro"; import { Ability } from "@prisma/client"; import ViewSlots from "components/builds/ViewSlots"; +import GearSelector from "components/common/GearSelector"; import WeaponSelector from "components/common/WeaponSelector"; import { getToastOptions } from "lib/getToastOptions"; -import { gear } from "lib/lists/gear"; import { sendData } from "lib/postData"; import { Unpacked } from "lib/types"; import useUser from "lib/useUser"; @@ -36,7 +35,7 @@ import { TITLE_CHARACTER_LIMIT, } from "lib/validators/build"; import { GetBuildsByUserData } from "prisma/queries/getBuildsByUser"; -import { Fragment, useState } from "react"; +import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { FiTrash } from "react-icons/fi"; import { mutate } from "swr"; @@ -297,18 +296,7 @@ const BuildModal: React.FC = ({ onClose, build }) => { control={control} defaultValue="" render={({ onChange, value, name }) => ( - + )} /> @@ -319,19 +307,12 @@ const BuildModal: React.FC = ({ onClose, build }) => { name="clothingGear" control={control} defaultValue="" - render={({ onChange, value, name }) => ( - + render={({ onChange, value }) => ( + )} /> @@ -343,20 +324,11 @@ const BuildModal: React.FC = ({ onClose, build }) => { control={control} defaultValue="" render={({ onChange, value, name }) => ( - + )} /> diff --git a/components/u/ProfileModal.tsx b/components/u/ProfileModal.tsx index e338b9767..886001a64 100644 --- a/components/u/ProfileModal.tsx +++ b/components/u/ProfileModal.tsx @@ -19,9 +19,9 @@ import { import { zodResolver } from "@hookform/resolvers/zod"; import { t, Trans } from "@lingui/macro"; import { useLingui } from "@lingui/react"; +import ChakraSelect from "components/common/ChakraSelect"; import MarkdownTextarea from "components/common/MarkdownTextarea"; import WeaponSelector from "components/common/MultiWeaponSelector"; -import MySelect from "components/common/MySelect"; import { countries } from "countries-list"; import { getToastOptions } from "lib/getToastOptions"; import { sendData } from "lib/postData"; @@ -230,7 +230,7 @@ const ProfileModal: React.FC = ({ onClose, user }) => { control={control} defaultValue={""} render={({ onChange, value }) => ( - = ({ onClose, user }) => { {countries[countryCode].name} ))} - + )} /> @@ -270,7 +270,7 @@ const ProfileModal: React.FC = ({ onClose, user }) => { name="sensStick" control={control} render={({ onChange, value, name }) => ( - = ({ onClose, user }) => { {sens} ))} - + )} /> @@ -293,7 +293,7 @@ const ProfileModal: React.FC = ({ onClose, user }) => { name="sensMotion" control={control} render={({ onChange, value, name }) => ( - = ({ onClose, user }) => { {sens} ))} - + )} />