From 45ef4e569bbd176e2c748e73e448588855cea80d Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 26 Feb 2022 15:55:20 -0800 Subject: [PATCH] Add flat raid list and callbacks The flat raid list is so that we can quickly find which raid was selected, since otherwise they're in option groups --- components/RaidDropdown/index.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/components/RaidDropdown/index.tsx b/components/RaidDropdown/index.tsx index 4a6bc3d0..61a1372d 100644 --- a/components/RaidDropdown/index.tsx +++ b/components/RaidDropdown/index.tsx @@ -1,20 +1,26 @@ -import { group } from 'console' import React, { useEffect, useState } from 'react' import { useCookies } from 'react-cookie' + +import { appState } from '~utils/appState' import api from '~utils/api' import './index.scss' // Props -interface Props {} +interface Props { + selected?: string + onBlur: (event: React.ChangeEvent) => void +} -const RaidDropdown = (props: Props) => { +const RaidDropdown = React.forwardRef(function fieldSet(props, ref) { const [cookies, _] = useCookies(['user']) const headers = (cookies.user != null) ? { headers: { 'Authorization': `Bearer ${cookies.user.access_token}` } } : {} const [raids, setRaids] = useState() + const [flatRaids, setFlatRaids] = useState() + const raidGroups = [ 'Assorted', 'Omega', @@ -42,7 +48,10 @@ const RaidDropdown = (props: Props) => { function fetchRaids() { api.endpoints.raids.getAll(headers) .then((response) => { - organizeRaids(response.data.map((r: any) => r.raid)) + const raids = response.data.map((r: any) => r.raid) + + appState.raids = raids + organizeRaids(raids) }) } @@ -70,15 +79,15 @@ const RaidDropdown = (props: Props) => { {options} ) - } - + } + return ( - { Array.from(Array(raids?.length)).map((x, i) => { return raidGroup(i) })} ) -} +}) export default RaidDropdown