diff --git a/src/components/coin-analytics.tsx b/src/components/coin-analytics.tsx index 4f7d03f..30c8efe 100644 --- a/src/components/coin-analytics.tsx +++ b/src/components/coin-analytics.tsx @@ -73,7 +73,6 @@ const App = ({ const pageSize = 20; const [dataPage, setDataPage] = useState(0); - const [maxDataPage, setMaxDataPage] = useState(0); const [actions, setActions] = useState([]); const [latestAsset, setLatestAsset] = useState(); @@ -116,11 +115,12 @@ const App = ({ setWalletAliasMap(wam); }); - // update max page + }, [actions]); + + const maxDataPage = useMemo(() => { // - 0.000000000001 is for float number precision const mp = Math.floor(actions.length / pageSize - 0.000000000001); - // set max data page - setMaxDataPage(mp >= 0 ? mp : 0); + return mp >= 0 ? mp : 0; }, [actions]); const breakevenPrice = useMemo( diff --git a/src/components/comparison.tsx b/src/components/comparison.tsx index cba9173..c5c69ec 100644 --- a/src/components/comparison.tsx +++ b/src/components/comparison.tsx @@ -360,7 +360,7 @@ const App = ({ currency }: { currency: CurrencyRateDetail }) => {
- + diff --git a/src/components/historical-data/index.tsx b/src/components/historical-data/index.tsx index 69a0264..9a62e31 100644 --- a/src/components/historical-data/index.tsx +++ b/src/components/historical-data/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { deleteHistoricalDataByUUID, deleteHistoricalDataDetailById, @@ -24,6 +24,18 @@ import ImageStack from "../common/image-stack"; import { getImageApiPath } from "@/utils/app"; import UnknownLogo from "@/assets/icons/unknown-logo.svg"; import bluebird from "bluebird"; +import { Button } from "../ui/button"; +import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "../ui/select"; +import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"; type RankData = { id: number; @@ -53,22 +65,23 @@ const App = ({ const wsize = useWindowSize(); - const [pageNum, setPageNum] = useState(1); + const [dataPage, setDataPage] = useState(0); + const pageSize = 10; useEffect(() => { const symbols = _(data) .map((d) => d.assets) .flatten() - .sortBy(d=>d.createdAt) + .sortBy((d) => d.createdAt) .reverse() - .uniqBy(d=>d.symbol) - .map(d=>({ + .uniqBy((d) => d.symbol) + .map((d) => ({ symbol: d.symbol, price: d.price, })) .value(); - + downloadCoinLogos(symbols); getLogoMap(data).then((m) => setLogoMap(m)); @@ -78,6 +91,12 @@ const App = ({ loadAllData(); }, []); + const maxDataPage = useMemo(() => { + // - 0.000000000001 is for float number precision + const mp = Math.floor(data.length / pageSize - 0.000000000001); + return mp >= 0 ? mp : 0; + }, [data]); + async function getLogoMap(d: HistoricalData[]) { const acd = await getAppCacheDir(); const kvs = await bluebird.map( @@ -183,104 +202,136 @@ const App = ({ return p; } + function renderHistoricalDataListV2() { + return ( + data + .map((d, idx) => { + return ( + + + +
+
+ {timestampToDate(new Date(d.createdAt).getTime(), true)} +
+
+ {currency.symbol + + prettyNumberToLocaleString( + currencyWrapper(currency)(d.total) + )} +
+
+
+
+ +
+
todo
+
+
0 ? "green" : "red", + }} + > + {idx < data.length - 1 + ? getUpOrDown(d.total - data[idx + 1].total) + + currency.symbol + + prettyNumberToLocaleString( + currencyWrapper(currency)( + Math.abs(d.total - data[idx + 1].total) + ) + ) + : ""} +
+
+
+
+
+ ); + }) + // TODO: slice first for better performance + .slice(dataPage * pageSize, (dataPage + 1) * pageSize) + ); + } + function renderHistoricalDataList() { // split data into pages - const idx = (pageNum - 1) * pageSize; - return _(data) - .map((d, idx) => { - return ( -
onRowClick(d.id)} - > -
-
- {timestampToDate(new Date(d.createdAt).getTime(), true)} -
-
- {currency.symbol + - prettyNumberToLocaleString( - currencyWrapper(currency)(d.total) - )} + return ( + _(data) + .map((d, idx) => { + return ( +
onRowClick(d.id)} + > +
+
+ {timestampToDate(new Date(d.createdAt).getTime(), true)} +
+
+ {currency.symbol + + prettyNumberToLocaleString( + currencyWrapper(currency)(d.total) + )} +
-
-
-
- onHistoricalDataDeleteClick(d.id)}> - delete + +
+ logoMap[a.symbol] || UnknownLogo) + .value()} + imageWidth={25} + imageHeight={25} /> - -
-
- logoMap[a.symbol] || UnknownLogo) - .value()} - imageWidth={25} - imageHeight={25} - /> -
-
0 ? "green" : "red", - }} - > - {idx < data.length - 1 - ? getUpOrDown(d.total - data[idx + 1].total) + - currency.symbol + - prettyNumberToLocaleString( - currencyWrapper(currency)( - Math.abs(d.total - data[idx + 1].total) +
+
0 ? "green" : "red", + }} + > + {idx < data.length - 1 + ? getUpOrDown(d.total - data[idx + 1].total) + + currency.symbol + + prettyNumberToLocaleString( + currencyWrapper(currency)( + Math.abs(d.total - data[idx + 1].total) + ) ) - ) - : ""} + : ""} +
-
- ); - }) - .slice(idx, idx + pageSize) - .value(); - } - - function page() { - return _(data.length / pageSize) - .range() - .map((i) => { - const curPageNum = i + 1; - - return ( - setPageNum(curPageNum)} - style={{ - color: curPageNum === pageNum ? "black" : "gray", - marginRight: 10, - }} - > - {curPageNum} - - ); - }) - .value(); + ); + }) + // TODO: slice first for better performance + .slice(dataPage * pageSize, (dataPage + 1) * pageSize) + .value() + ); } function renderDetailPage(data: RankData[]) { @@ -421,28 +472,48 @@ const App = ({
-
- (pageNum > 1 ? setPageNum(pageNum - 1) : null)} - style={{ - marginRight: 10, - color: "gray", - }} - > - {"<"} - - {page()} - - pageNum < data.length / pageSize ? setPageNum(pageNum + 1) : null - } - style={{ - color: "gray", - }} - > - {">"} - +
+
+ +
+ +
+ +
+ {/*
{renderHistoricalDataListV2()}
*/}
{renderHistoricalDataList()}
); diff --git a/src/components/latest-assets-percentage.tsx b/src/components/latest-assets-percentage.tsx index 8db6ca2..a16c59b 100644 --- a/src/components/latest-assets-percentage.tsx +++ b/src/components/latest-assets-percentage.tsx @@ -5,7 +5,7 @@ import { } from "@/middlelayers/types"; import { Card, CardContent } from "./ui/card"; import _ from "lodash"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { appCacheDir as getAppCacheDir } from "@tauri-apps/api/path"; import { Table, TableBody, TableCell, TableRow } from "./ui/table"; import { getImageApiPath } from "@/utils/app"; @@ -31,7 +31,6 @@ const App = ({ data: LatestAssetsPercentageData; }) => { const [dataPage, setDataPage] = useState(0); - const [maxDataPage, setMaxDataPage] = useState(0); const [logoMap, setLogoMap] = useState<{ [x: string]: string }>({}); const pageSize = 5; const navigate = useNavigate(); @@ -57,15 +56,16 @@ const App = ({ .value() ); - // - 0.000000000001 is for float number precision - const mp = Math.floor(data.length / pageSize - 0.000000000001) - // set max data page - setMaxDataPage(mp >= 0 ? mp : 0); - // set logo map getLogoMap(data).then((m) => setLogoMap(m)); }, [data]); + const maxDataPage = useMemo(() => { + // - 0.000000000001 is for float number precision + const mp = Math.floor(data.length / pageSize - 0.000000000001); + return mp >= 0 ? mp : 0; + }, [data]); + async function getLogoMap(d: LatestAssetsPercentageData) { const acd = await getAppCacheDir(); const kvs = await bluebird.map(d, async (coin) => {