From 53c7ce959b5c72002c5444b7d6e5b458331a4275 Mon Sep 17 00:00:00 2001
From: Pinapelz <yukais@pinapelz.com>
Date: Tue, 27 Aug 2024 01:05:43 -0700
Subject: Initial commit

---
 src/components/FFXIVWorldSelector.tsx | 61 +++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 src/components/FFXIVWorldSelector.tsx

(limited to 'src/components/FFXIVWorldSelector.tsx')

diff --git a/src/components/FFXIVWorldSelector.tsx b/src/components/FFXIVWorldSelector.tsx
new file mode 100644
index 0000000..d078640
--- /dev/null
+++ b/src/components/FFXIVWorldSelector.tsx
@@ -0,0 +1,61 @@
+import React, { useState, useEffect } from 'react';
+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
-- 
cgit v1.2.3

