From ba51582e825477bec23c2aa37ba43bd6482a2a29 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 23 Aug 2024 15:53:38 -0700 Subject: implement itemprice component --- src/components/AnotherComponent.tsx | 28 ------------ src/components/FFXIVItemPrice.tsx | 83 +++++++++++++++++++++++++++++++++++ src/components/FFXIVWorldSelector.tsx | 17 ++++--- 3 files changed, 93 insertions(+), 35 deletions(-) delete mode 100644 src/components/AnotherComponent.tsx create mode 100644 src/components/FFXIVItemPrice.tsx (limited to 'src/components') diff --git a/src/components/AnotherComponent.tsx b/src/components/AnotherComponent.tsx deleted file mode 100644 index f74e924..0000000 --- a/src/components/AnotherComponent.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React, { useState, useEffect } from 'react'; - -const AnotherComponent: React.FC = () => { - const [selectedWorld, setSelectedWorld] = useState(null); - - useEffect(() => { - // Load selected world from localStorage - const savedWorld = localStorage.getItem('selectedWorld'); - if (savedWorld) { - setSelectedWorld(savedWorld); - } - }, []); - - return ( -
-

Selected World: {selectedWorld}

- -
- ); -}; - -export default AnotherComponent; \ No newline at end of file diff --git a/src/components/FFXIVItemPrice.tsx b/src/components/FFXIVItemPrice.tsx new file mode 100644 index 0000000..8f265fc --- /dev/null +++ b/src/components/FFXIVItemPrice.tsx @@ -0,0 +1,83 @@ +import React, { useState, useEffect } from 'react'; + +interface FFXIVItemPriceProps { + itemId: number; + itemName: string; + itemImageUrl: string; +} + +const FFXIVItemPrice: React.FC = ({ itemId = 5530, itemName="Coke", itemImageUrl="https://xivapi.com/i/021000/021462_hr1.png"}) => { + const [selectedWorld, setSelectedWorld] = useState(null); + const [dailySaleVelocity, setDailySaleVelocity] = useState(null); + const [averageSalePrice, setAverageSalePrice] = useState(null); + const [inputQuantity, setInputQuantity] = useState(0); + const [potentialGil, setPotentialGil] = useState(0); + + useEffect(() => { + const savedWorld = localStorage.getItem('selectedWorld'); + if (savedWorld) { + setSelectedWorld(savedWorld); + } else { + 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)); + }, [itemId, selectedWorld]); + + const handleInputChange = (e: React.ChangeEvent) => { + const quantity = parseInt(e.target.value, 10); + setInputQuantity(quantity); + setPotentialGil(quantity * (averageSalePrice || 0)); + }; + + const formatNumber = (number: number | null) => { + return number !== null ? new Intl.NumberFormat().format(number) : 'N/A'; + }; + + return ( +
+
+

{itemName}

+ {itemName} +
+ + + + + + + + + + + + + + + + + + + +
Daily Sale Velocity:{formatNumber(dailySaleVelocity)} items
Average Price/Item:{formatNumber(averageSalePrice)} gil
Enter Quantity: + +
Potential Gil Earnings:{formatNumber(potentialGil)} gil
+
{selectedWorld} Marketboard Data provided by Universalis API
+
+ ); +}; + +export default FFXIVItemPrice; \ No newline at end of file diff --git a/src/components/FFXIVWorldSelector.tsx b/src/components/FFXIVWorldSelector.tsx index f2dc4cc..63eff07 100644 --- a/src/components/FFXIVWorldSelector.tsx +++ b/src/components/FFXIVWorldSelector.tsx @@ -1,11 +1,15 @@ import React, { useState, useEffect } from 'react'; - +import '../styles/ffxiv-selector.css'; interface World { id: number; name: string; } -const FFXIVWorldSelector: React.FC = () => { +interface FFXIVWorldSelectorProps { + message: string; +} + +const FFXIVWorldSelector: React.FC = ({ message = "Select a World" }) => { const [worlds, setWorlds] = useState([]); const [selectedWorld, setSelectedWorld] = useState(null); @@ -40,9 +44,9 @@ const FFXIVWorldSelector: React.FC = () => { }; return ( -
- - {worlds.map((world) => ( ))} - {selectedWorld &&

Selected World: {selectedWorld}

} - +
); }; -- cgit v1.2.3