Skip to content

Commit 65c31a2

Browse files
committed
fix: 코인 링크를 누르면 사이드바가 닫히도록 수정
1 parent ab7fb6f commit 65c31a2

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

src/app/routes/trade.$ticker.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as cookie from 'cookie';
22
import { AnimatePresence } from 'motion/react';
3-
import { Suspense, lazy, useState } from 'react';
3+
import { Suspense, lazy, useMemo, useState } from 'react';
44
import { Outlet, redirect } from 'react-router';
55

66
import { CoinPriceWithName, api as coinApi } from '~/entities/coin';
@@ -49,11 +49,16 @@ export default function TradeRouteComponent({
4949
useTradeNotification(userId ?? 0);
5050
const [isMenuOpen, setIsMenuOpen] = useState(false);
5151
const { coinInfo, coinList, isLoggedIn } = loaderData;
52-
const coinListWithIcon = coinList.map((coinInfo) => ({
53-
...coinInfo,
54-
coinIcon: <span>🪙</span>,
55-
to: `/trade/${coinInfo.ticker}`,
56-
}));
52+
const coinListWithIcon = useMemo(
53+
() =>
54+
coinList.map((coinInfo) => ({
55+
...coinInfo,
56+
coinIcon: <span>🪙</span>,
57+
to: `/trade/${coinInfo.ticker}`,
58+
onClick: () => setIsMenuOpen(false),
59+
})),
60+
[coinList],
61+
);
5762

5863
const handleOpenMenu = () => {
5964
setIsMenuOpen(true);
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, type LinkProps } from 'react-router';
1+
import { type LinkProps, useNavigate } from 'react-router';
22

33
import {
44
CoinWithIconAndName,
@@ -9,48 +9,51 @@ import { formatCurrencyKR } from '~/shared/utils';
99

1010
export type CoinListItemProps = {
1111
to: LinkProps['to'];
12+
onClick?: () => void;
1213
} & CoinWithIconAndNameProps;
1314

1415
export default function CoinListItem({
1516
name,
1617
ticker,
1718
coinIcon: CoinIcon,
1819
to,
20+
onClick,
1921
}: Readonly<CoinListItemProps>) {
22+
const navigate = useNavigate();
2023
const currentPriceData = useCurrentPrice(ticker);
2124
const isBull = currentPriceData && currentPriceData.changeRate > 0;
2225
const formatedPrice = `${formatCurrencyKR(
2326
+(currentPriceData?.currentPrice ?? 0).toFixed(2),
2427
)}원`;
2528

29+
const handleClickCoinItem = async () => {
30+
onClick?.();
31+
await navigate(to);
32+
};
33+
2634
return (
27-
<Link to={to} className="block px-2">
28-
<button
29-
type="button"
30-
className="flex w-[max(300px,100%)] cursor-pointer items-center py-1"
31-
>
32-
<div className="flex-1">
33-
<CoinWithIconAndName
34-
name={name}
35-
ticker={ticker}
36-
coinIcon={CoinIcon}
37-
/>
38-
</div>
39-
<div className="flex-1 text-right text-sm">
40-
<span className={isBull ? 'text-red-600' : 'text-blue-700'}>
41-
{formatedPrice}
42-
</span>
43-
</div>
44-
<div className="flex-1 text-right text-sm">
45-
<span className={isBull ? 'text-red-600' : 'text-blue-700'}>
46-
{(currentPriceData?.changeRate ?? 0).toFixed(2)}%
47-
</span>
48-
</div>
49-
<div className="flex-1 text-right text-sm">
50-
{/* TODO: 거래량 API가 나오면 추가할 것 */}
51-
<span>{0}</span>
52-
</div>
53-
</button>
54-
</Link>
35+
<button
36+
type="button"
37+
className="flex w-[max(300px,100%)] cursor-pointer items-center py-1"
38+
onClick={handleClickCoinItem}
39+
>
40+
<div className="flex-1">
41+
<CoinWithIconAndName name={name} ticker={ticker} coinIcon={CoinIcon} />
42+
</div>
43+
<div className="flex-1 text-right text-sm">
44+
<span className={isBull ? 'text-red-600' : 'text-blue-700'}>
45+
{formatedPrice}
46+
</span>
47+
</div>
48+
<div className="flex-1 text-right text-sm">
49+
<span className={isBull ? 'text-red-600' : 'text-blue-700'}>
50+
{(currentPriceData?.changeRate ?? 0).toFixed(2)}%
51+
</span>
52+
</div>
53+
<div className="flex-1 text-right text-sm">
54+
{/* TODO: 거래량 API가 나오면 추가할 것 */}
55+
<span>{0}</span>
56+
</div>
57+
</button>
5558
);
5659
}

0 commit comments

Comments
 (0)