diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2024-08-25 11:27:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-25 11:27:31 -0700 |
| commit | d34d0c77820ba40082fd6e8cd73477404eaf4715 (patch) | |
| tree | fbf83cfb5a00d7056d9fcdb43e30ba5a06db0f39 /src/components/FFXIVWorldSelector.tsx | |
| parent | 471bd1f064766c33ee62b4789ca097da4d57978f (diff) | |
| parent | 070a21e5a3d7b342c9a3cafe9cef2c5e34b31145 (diff) | |
Merge pull request #1 from pinapelz/ffxiv-gil-making
XIV Gil Post
Diffstat (limited to 'src/components/FFXIVWorldSelector.tsx')
| -rw-r--r-- | src/components/FFXIVWorldSelector.tsx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/components/FFXIVWorldSelector.tsx b/src/components/FFXIVWorldSelector.tsx new file mode 100644 index 0000000..63eff07 --- /dev/null +++ b/src/components/FFXIVWorldSelector.tsx @@ -0,0 +1,62 @@ +import React, { useState, useEffect } from 'react'; +import '../styles/ffxiv-selector.css'; +interface World { + id: number; + name: string; +} + +interface FFXIVWorldSelectorProps { + message: string; +} + +const FFXIVWorldSelector: React.FC<FFXIVWorldSelectorProps> = ({ message = "Select a World" }) => { + const [worlds, setWorlds] = useState<World[]>([]); + const [selectedWorld, setSelectedWorld] = useState<string | null>(null); + + useEffect(() => { + const fetchWorlds = async () => { + try { + const response = await fetch('https://universalis.app/api/v2/worlds'); + const data = await response.json(); + setWorlds(data); + } catch (error) { + console.error('Error fetching worlds:', error); + } + }; + + fetchWorlds(); + + // Load selected world from localStorage + const savedWorld = localStorage.getItem('selectedWorld'); + if (savedWorld) { + setSelectedWorld(savedWorld); + } + }, []); + + const handleWorldChange = (event: React.ChangeEvent<HTMLSelectElement>) => { + const selectedWorld = event.target.value; + setSelectedWorld(selectedWorld); + localStorage.setItem('selectedWorld', selectedWorld); // Save to localStorage + }; + + const handleApplyClick = () => { + window.location.reload(); // Refresh the page + }; + + return ( + <div className="ffxiv-container"> + <label htmlFor="world-select" className="ffxiv-label">{message}</label> + <select id="world-select" onChange={handleWorldChange} value={selectedWorld || ''} className="ffxiv-select"> + <option value="">--Please choose an option--</option> + {worlds.map((world) => ( + <option key={world.id} value={world.name}> + {world.name} + </option> + ))} + </select> + <button onClick={handleApplyClick} className="ffxiv-button">Apply</button> + </div> + ); +}; + +export default FFXIVWorldSelector;
\ No newline at end of file |
