import { Mutex } from "async-mutex" import { useState } from "react" import styled from "styled-components" import useAsyncEffect from "use-async-effect" import { GetItemHistory } from "../client/controllers" import { ItemHistoryResponse } from "../client/response" type ItemHistoryTableProps = { itemId: number } const ItemHistoryTableStyle = styled.table` width: 100% ` const ItemHistoryTableHead = styled.thead` background-color: #34067eff ` const ItemHistoryTableItem = styled.td` align: center ` const ItemHistoryTH = styled.th` align: center ` const ItemHistoryTableBody = styled.tbody` > :nth-child(even) { background-color: #410041ff; } > :hover { background-color: #707070ff; } ` const ItemHistoryTableRow = styled.tr` ` const itemHistoryMutex = new Mutex() export const ItemHistoryTable = ({itemId}: ItemHistoryTableProps) => { const [itemPriceHistory, setItemPriceHistory] = useState([]) useAsyncEffect(async () => { if(itemPriceHistory.length === 0) { const release = await itemHistoryMutex.acquire() setItemPriceHistory(await GetItemHistory(itemId)) await release() } }, []) console.log(itemPriceHistory) return ( item price valid from valid to {itemPriceHistory.map((iph) => ( {iph.ItemName} {Math.trunc(parseInt(iph.ItemPrice) * 100) / 100} {new Date(iph.ValidFrom).toLocaleDateString()} {new Date(iph.ValidTo).toLocaleDateString()} ))} ) }