rename MapDropDown to MapChooser, move css
This commit is contained in:
parent
1c5e14cd47
commit
3a3906f178
1 changed files with 14 additions and 13 deletions
|
|
@ -1,28 +0,0 @@
|
|||
import { ChangeEvent, useEffect, useState } from "react";
|
||||
import { getMaps, postMaps } from "./serverCalls";
|
||||
|
||||
export default function MapDropDown() {
|
||||
const [mapList, setMaps] = useState<string[] | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let aborted = false;
|
||||
async function startFetch() {
|
||||
const response = await getMaps();
|
||||
if (!aborted && response.ok && response.successResult)
|
||||
setMaps(response.successResult);
|
||||
}
|
||||
startFetch();
|
||||
return () => { aborted = true };
|
||||
}, []);
|
||||
|
||||
const onChange = (event: ChangeEvent<HTMLSelectElement>) => {
|
||||
postMaps(event.target.options[event.target.selectedIndex].value);
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
return <select value="maps" className='DropDown' onChange={onChange}>
|
||||
<option value="" defaultValue={""} >Choose map</option>
|
||||
{mapList?.map(m =>
|
||||
<option key={m} value={m}>{m}</option>)}
|
||||
</select>
|
||||
}
|
||||
Reference in a new issue