aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/FFXIVWorldSelector.tsx
blob: 63eff07f80ee2ae47a4766409a3d71a716389e41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage