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
This commit is contained in:
Justin Edmund 2022-02-26 15:55:20 -08:00
parent 68a6e037f2
commit 45ef4e569b

View file

@ -1,20 +1,26 @@
import { group } from 'console'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { useCookies } from 'react-cookie' import { useCookies } from 'react-cookie'
import { appState } from '~utils/appState'
import api from '~utils/api' import api from '~utils/api'
import './index.scss' import './index.scss'
// Props // Props
interface Props {} interface Props {
selected?: string
onBlur: (event: React.ChangeEvent<HTMLSelectElement>) => void
}
const RaidDropdown = (props: Props) => { const RaidDropdown = React.forwardRef<HTMLSelectElement, Props>(function fieldSet(props, ref) {
const [cookies, _] = useCookies(['user']) const [cookies, _] = useCookies(['user'])
const headers = (cookies.user != null) ? { const headers = (cookies.user != null) ? {
headers: { 'Authorization': `Bearer ${cookies.user.access_token}` } headers: { 'Authorization': `Bearer ${cookies.user.access_token}` }
} : {} } : {}
const [raids, setRaids] = useState<Raid[][]>() const [raids, setRaids] = useState<Raid[][]>()
const [flatRaids, setFlatRaids] = useState<Raid[]>()
const raidGroups = [ const raidGroups = [
'Assorted', 'Assorted',
'Omega', 'Omega',
@ -42,7 +48,10 @@ const RaidDropdown = (props: Props) => {
function fetchRaids() { function fetchRaids() {
api.endpoints.raids.getAll(headers) api.endpoints.raids.getAll(headers)
.then((response) => { .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} {options}
</optgroup> </optgroup>
) )
} }
return ( return (
<select> <select key={props.selected} defaultValue={props.selected} onBlur={props.onBlur} ref={ref}>
{ Array.from(Array(raids?.length)).map((x, i) => { { Array.from(Array(raids?.length)).map((x, i) => {
return raidGroup(i) return raidGroup(i)
})} })}
</select> </select>
) )
} })
export default RaidDropdown export default RaidDropdown