Skip to content

Commit

Permalink
optimize historical data list
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn committed Dec 10, 2023
1 parent e11c57c commit e7b1e3d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/components/historical-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
SelectTrigger,
SelectValue,
} from "../ui/select";
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";

type RankData = {
id: number;
Expand Down Expand Up @@ -201,6 +202,58 @@ const App = ({
return p;
}

function renderHistoricalDataListV2() {
return (
data
.map((d, idx) => {
return (
<Card className="group" key={"historical-card-" + idx}>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pt-3">
<CardTitle className="text-sm font-medium pt-0">
<div className="grid gap-4 grid-cols-12">
<div className="col-span-10">
{timestampToDate(new Date(d.createdAt).getTime(), true)}
</div>
<div className="col-span-1 text-xl text-right">
{currency.symbol +
prettyNumberToLocaleString(
currencyWrapper(currency)(d.total)
)}
</div>
</div>
</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-4">
<div className="col-span-2">todo</div>
<div className="col-span-2">
<div
style={{
color:
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)
)
)
: ""}
</div>
</div>
</div>
</CardContent>
</Card>
);
})
// TODO: slice first for better performance
.slice(dataPage * pageSize, (dataPage + 1) * pageSize)
);
}

function renderHistoricalDataList() {
// split data into pages
return (
Expand Down Expand Up @@ -460,6 +513,7 @@ const App = ({
</Button>
</div>
</div>
{/* <div>{renderHistoricalDataListV2()}</div> */}
<div className="historical-data">{renderHistoricalDataList()}</div>
</div>
);
Expand Down

0 comments on commit e7b1e3d

Please sign in to comment.