From 18835326bd8db10850456a95a763b8adecc3c967 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 24 Aug 2024 03:56:06 -0700 Subject: ffxiv-gil-making: add dungeon section --- src/components/FFXIVItemPrice.tsx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/components') diff --git a/src/components/FFXIVItemPrice.tsx b/src/components/FFXIVItemPrice.tsx index 2a6cab8..bcf5900 100644 --- a/src/components/FFXIVItemPrice.tsx +++ b/src/components/FFXIVItemPrice.tsx @@ -13,6 +13,22 @@ const FFXIVItemPrice: React.FC = ({ itemId = 5530, itemName const [inputQuantity, setInputQuantity] = useState(0); const [potentialGil, setPotentialGil] = useState(0); + const fetchData = (attempt: number = 1) => { + fetch(`https://universalis.app/api/v2/aggregated/${selectedWorld}/${itemId}`) + .then(response => response.json()) + .then(data => { + const result = data.results[0]; + setDailySaleVelocity(Math.round(result.nq.dailySaleVelocity.world.quantity)); + setAverageSalePrice(Math.round(result.nq.averageSalePrice.world.price)); + }) + .catch(error => { + console.error(`Error fetching data (attempt ${attempt}):`, error); + if (attempt < 3) { + setTimeout(() => fetchData(attempt + 1), 5000); + } + }); + }; + useEffect(() => { const savedWorld = localStorage.getItem('selectedWorld'); if (savedWorld) { @@ -21,14 +37,7 @@ const FFXIVItemPrice: React.FC = ({ itemId = 5530, itemName setSelectedWorld('Midgardsormr'); } - fetch(`https://universalis.app/api/v2/aggregated/${selectedWorld}/${itemId}`) - .then(response => response.json()) - .then(data => { - const result = data.results[0]; - setDailySaleVelocity(Math.round(result.nq.dailySaleVelocity.world.quantity)); - setAverageSalePrice(Math.round(result.nq.averageSalePrice.world.price)); - }) - .catch(error => console.error('Error fetching data:', error)); + fetchData(); }, [itemId, selectedWorld]); const handleInputChange = (e: React.ChangeEvent) => { @@ -75,7 +84,10 @@ const FFXIVItemPrice: React.FC = ({ itemId = 5530, itemName -
{selectedWorld} Marketboard Data provided by Universalis API
+ ); }; -- cgit v1.2.3