From c1bcfe62c5beb2986f4016e05717264f669f7515 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 16 Jun 2023 17:17:10 -0700 Subject: [PATCH] Remove RaidDropdown component --- components/RaidDropdown/index.scss | 0 components/RaidDropdown/index.tsx | 144 ----------------------------- 2 files changed, 144 deletions(-) delete mode 100644 components/RaidDropdown/index.scss delete mode 100644 components/RaidDropdown/index.tsx diff --git a/components/RaidDropdown/index.scss b/components/RaidDropdown/index.scss deleted file mode 100644 index e69de29b..00000000 diff --git a/components/RaidDropdown/index.tsx b/components/RaidDropdown/index.tsx deleted file mode 100644 index e3d6b70d..00000000 --- a/components/RaidDropdown/index.tsx +++ /dev/null @@ -1,144 +0,0 @@ -import React, { useCallback, useEffect, useState } from 'react' -import { useRouter } from 'next/router' - -import Select from '~components/common/Select' -import SelectItem from '~components/common/SelectItem' -import SelectGroup from '~components/common/SelectGroup' - -import api from '~utils/api' -import organizeRaids from '~utils/organizeRaids' -import { appState } from '~utils/appState' -import { raidGroups } from '~data/raidGroups' - -import './index.scss' - -// Props -interface Props { - showAllRaidsOption: boolean - currentRaid?: string - defaultRaid?: string - onChange?: (slug?: string) => void - onBlur?: (event: React.ChangeEvent) => void -} - -// Set up empty raid for "All raids" -const allRaidsOption = { - id: '0', - name: { - en: 'All raids', - ja: '全て', - }, - slug: 'all', - level: 0, - group: 0, - element: 0, -} - -const RaidDropdown = React.forwardRef( - function useFieldSet(props, ref) { - // Set up router for locale - const router = useRouter() - const locale = router.locale || 'en' - - // Set up local states for storing raids - const [open, setOpen] = useState(false) - const [currentRaid, setCurrentRaid] = useState(undefined) - const [raids, setRaids] = useState() - const [sortedRaids, setSortedRaids] = useState() - - function openRaidSelect() { - setOpen(!open) - } - - // Organize raids into groups on mount - const organizeAllRaids = useCallback( - (raids: Raid[]) => { - let { sortedRaids } = organizeRaids(raids) - - if (props.showAllRaidsOption) { - raids.unshift(allRaidsOption) - sortedRaids[0].unshift(allRaidsOption) - } - - setRaids(raids) - setSortedRaids(sortedRaids) - appState.raids = raids - }, - [props.showAllRaidsOption] - ) - - // Fetch all raids on mount - useEffect(() => { - api.endpoints.raids - .getAll() - .then((response) => organizeAllRaids(response.data)) - }, [organizeRaids]) - - // Set current raid on mount - useEffect(() => { - if (raids && props.currentRaid) { - const raid = raids.find((raid) => raid.slug === props.currentRaid) - if (raid) setCurrentRaid(raid) - } - }, [raids, props.currentRaid]) - - // Enable changing select value - function handleChange(value: string) { - if (props.onChange) props.onChange(value) - - if (raids) { - const raid = raids.find((raid) => raid.slug === value) - setCurrentRaid(raid) - } - } - - // Render JSX for each raid option, sorted into optgroups - function renderRaidGroup(index: number) { - const options = - sortedRaids && - sortedRaids.length > 0 && - sortedRaids[index].length > 0 && - sortedRaids[index] - .sort((a, b) => { - if (a.element > 0 && b.element > 0) return a.element - b.element - else if (a.name.en.includes('NM') && b.name.en.includes('NM')) - return a.level < b.level ? -1 : 1 - else return a.name.en < b.name.en ? -1 : 1 - }) - .map((item, i) => ( - - {item.name[locale]} - - )) - - return ( - - {options} - - ) - } - - return ( - - - - ) - } -) - -export default RaidDropdown