Skip to content

Commit

Permalink
add icon list in historical data page (#135)
Browse files Browse the repository at this point in the history
* add icon list in historical data page

* fix height and width
  • Loading branch information
domechn committed Oct 29, 2023
1 parent a2abed2 commit b423bab
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/components/common/image-stack/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.image-stack {
position: relative;
overflow: hidden;
}

.image-stack-child {
position: absolute;
transition: left 0.5s ease-in-out;
}

.image-stack-child img {
border-radius: 50%;
box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.3);
transition: width 0.5s ease-in-out, height 0.5s ease-in-out;
}
53 changes: 53 additions & 0 deletions src/components/common/image-stack/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useState } from "react";
import "./index.css";

const ImageStack = ({
imageSrcs,
imageWidth,
imageHeight,
}: {
imageSrcs: string[];
imageWidth: number;
imageHeight: number;
}) => {
const [expanded, setExpanded] = useState(false);

const handleMouseEnter = () => {
setExpanded(true);
};

const handleMouseLeave = () => {
setExpanded(false);
};

return (
<div
className="image-stack"
style={{
height: imageHeight,
width: imageWidth * 1.05 * imageSrcs.length
}}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{imageSrcs.map((image, index) => (
<div
className="image-stack-child"
style={{ left: expanded ? index * imageWidth * 1.05 : index * imageWidth * 0.7 }}
key={index}
>
<img
src={image}
alt={`Image ${index + 1}`}
style={{
width: imageWidth,
height: imageHeight,
}}
/>
</div>
))}
</div>
);
};

export default ImageStack;
43 changes: 34 additions & 9 deletions src/components/historical-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { downloadCoinLogos } from "../../middlelayers/data";
import { appCacheDir as getAppCacheDir } from "@tauri-apps/api/path";
import { convertFileSrc } from "@tauri-apps/api/tauri";
import { useWindowSize } from "../../utils/hook";
import ImageStack from "../common/image-stack";

type RankData = {
id: number;
Expand Down Expand Up @@ -217,6 +218,23 @@ const App = ({
/>
</a>
</div>
<div
style={{
position: "absolute",
left: '30%',
}}
>
<ImageStack
imageSrcs={_(d.assets)
.sortBy("value")
.reverse()
.take(7)
.map((a) => getImageApiPath(a.symbol))
.value()}
imageWidth={25}
imageHeight={25}
/>
</div>
<div
className="historical-data-card-bottom-changes"
style={{
Expand Down Expand Up @@ -264,11 +282,15 @@ const App = ({
.value();
}

function detailPage(data: RankData[]) {
function getImageApiPath(symbol: string) {
const filePath = `${appCacheDir}assets/coins/${symbol.toLowerCase()}.png`;
return convertFileSrc(filePath);
}

function renderDetailPage(data: RankData[]) {
return _(data)
.map((d) => {
const filePath = `${appCacheDir}assets/coins/${d.symbol.toLowerCase()}.png`;
const apiPath = convertFileSrc(filePath);
const apiPath = getImageApiPath(d.symbol);
return (
<tr key={d.id}>
<td>
Expand All @@ -292,7 +314,10 @@ const App = ({
}}
>
<p className="historical-data-detail-row">
{currency.symbol + prettyPriceNumberToLocaleString(currencyWrapper(currency)(d.price))}
{currency.symbol +
prettyPriceNumberToLocaleString(
currencyWrapper(currency)(d.price)
)}
</p>
</td>
<td
Expand Down Expand Up @@ -349,7 +374,7 @@ const App = ({
</th>
<th
style={{
width: '30%',
width: "30%",
minWidth: 180,
textAlign: "start",
}}
Expand All @@ -358,31 +383,31 @@ const App = ({
</th>
<th
style={{
width: '20%',
width: "20%",
textAlign: "end",
}}
>
Price
</th>
<th
style={{
width: '25%',
width: "25%",
textAlign: "end",
}}
>
Amount
</th>
<th
style={{
width: '20%',
width: "20%",
textAlign: "end",
}}
>
Value
</th>
</tr>
</thead>
<tbody>{detailPage(rankData)}</tbody>
<tbody>{renderDetailPage(rankData)}</tbody>
</table>
</div>
</Modal>
Expand Down
7 changes: 5 additions & 2 deletions src/components/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const App = ({
topCoinsRankData,
topCoinsPercentageChangeData,
}: {
currency: CurrencyRateDetail,
currency: CurrencyRateDetail;
totalValueData: {
totalValue: number;
changePercentage: number;
Expand All @@ -43,7 +43,10 @@ const App = ({
<hr className="nice-hr" />
<AssetChange currency={currency} data={assetChangeData} />
<hr className="nice-hr" />
<CoinsAmountAndValueChange currency={currency} data={coinsAmountAndValueChangeData} />
<CoinsAmountAndValueChange
currency={currency}
data={coinsAmountAndValueChangeData}
/>
<hr className="nice-hr" />
<TopCoinsRank data={topCoinsRankData} />
<hr className="nice-hr" />
Expand Down

0 comments on commit b423bab

Please sign in to comment.