Skip to content

Commit 0fe0f3a

Browse files
authored
Merge pull request #114 from codestates-seb/dev-client#19/watchList
[FE] 보유종목 구현 Dev client#19/watch list
2 parents 3dca958 + f273193 commit 0fe0f3a

23 files changed

+261
-176
lines changed
19.7 KB
Loading

client/src/components/CentralChartMenu/Index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CompareChartBtn from "./CompareChartBtn";
1010
const UpperMenuBar = () => {
1111
const companyId = useSelector((state: StateProps) => state.companyId);
1212

13-
console.log(localStorage.getItem("authToken"));
13+
console.log(localStorage.getItem("accessToken"));
1414

1515
return (
1616
<Container>

client/src/components/EntireList/EntireList.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from 'styled-components';
33
import Header from './Header';
44
import StockItem from './StockItem';
55
import useCompanyData from '../../hooks/useCompanyData';
6+
import { useGetCash } from '../../hooks/useCash'; // 훅 가져오기
67

78
const EntireList: React.FC<EntireListProps> = ({ currentListType, onChangeListType }) => {
89
const [isMenuOpen, setMenuOpen] = useState(false);
@@ -14,6 +15,11 @@ const EntireList: React.FC<EntireListProps> = ({ currentListType, onChangeListTy
1415
// 'companies'가 'undefined'인 경우를 처리하기 위해 빈 배열로 초기화
1516
const companiesList = companies || [];
1617

18+
// 현금 보유량 가져오기
19+
const moneyId = localStorage.getItem('moneyId');
20+
const { data: cashData } = useGetCash(moneyId);
21+
const holdingsAmount = cashData?.data?.money || "0";
22+
1723
return (
1824
<WatchListContainer>
1925
<Header
@@ -23,7 +29,7 @@ const EntireList: React.FC<EntireListProps> = ({ currentListType, onChangeListTy
2329
setMenuOpen={setMenuOpen}
2430
/>
2531
<Divider1 />
26-
<EvaluationProfit>평가 수익금: +5,000,000원</EvaluationProfit> {/* 임의의 평가 수익금 */}
32+
<HoldingsAmount>현금 보유량: {holdingsAmount}</HoldingsAmount> {/* 현금 보유량 표시 */}
2733
<Divider2 />
2834
<StockList>
2935
{isLoading ? (
@@ -68,6 +74,15 @@ flex-direction: row;
6874
border-bottom: 1px solid #2f4f4f;
6975
`;
7076

77+
const HoldingsAmount = styled.div`
78+
font-size: 16px;
79+
font-weight: bold;
80+
margin: 8px 12px ;
81+
text-align: center;
82+
color: darkslategray // 현금 보유량을 파란색으로 표시
83+
`;
84+
85+
7186
const Divider2 = styled.div`
7287
margin:0px;
7388
padding:0px;
@@ -78,15 +93,6 @@ flex-direction: row;
7893
border-bottom: 1px solid #2f4f4f;
7994
`;
8095

81-
82-
83-
const EvaluationProfit = styled.div`
84-
font-size: 16px;
85-
font-weight: bold;
86-
margin: 8px 0;
87-
text-align: center;
88-
color: red; // 수익금이 플러스일 경우 초록색으로 표시
89-
`;
9096
const StockList = styled.div`
9197
width: 100%;
9298
max-height: 740px; /* 스크롤이 발생할 최대 높이를 지정하세요 */

client/src/components/EntireList/StockItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import logo from '../../asset/logos/SK_logo.png';
3+
import logo from '../../asset/images/StockHolmImage.png';
44

55
const StockItem: React.FC<StockItemProps> = ({ company, setShowChangePrice, showChangePrice }) => {
66
const isPositiveChange = parseFloat(company.stockChangeRate) > 0;

client/src/components/Headers/LoginHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const LoginHeader: React.FC<LoginHeaderProps> = () => {
3535

3636
const handleLogout = () => {
3737
dispatch(setLogoutState()); // 전역변수에서 로그아웃 상태로 설정
38-
localStorage.removeItem("Authorization"); // 엑세스 토큰 제거
39-
localStorage.removeItem("Refresh-token"); // 리프레시 토큰 제거
38+
localStorage.removeItem("accessToken"); // 엑세스 토큰 제거
39+
localStorage.removeItem("refreshToken"); // 리프레시 토큰 제거
4040
};
4141

4242
return (

client/src/components/HoldingList/Header.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const Icon = styled.img`
4646
height: 24px;
4747
cursor: pointer;
4848
margin-right: 10px;
49+
margin-left:10px;
4950
`;
5051

5152
const HeaderText = styled.span`

client/src/components/HoldingList/HoldingList.tsx

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import React, { useState } from 'react';
22
import styled from 'styled-components';
33
import Header from './Header';
44
import StockItem from './StockItem';
5+
import useGetStockHolds from '../../hooks/useGetStockholds';
6+
import { StockItemProps } from './StockItem';
57
import useCompanyData from '../../hooks/useCompanyData';
68

7-
const WatchList: React.FC<WatchListProps> = ({ currentListType, onChangeListType }) => {
9+
const HoldingList: React.FC<WatchListProps> = ({ currentListType, onChangeListType }) => {
810
const [isMenuOpen, setMenuOpen] = useState(false);
911
const [showChangePrice, setShowChangePrice] = useState(false);
1012

11-
// useCompanyData 훅 사용하여 데이터 가져오기
12-
const { data: companies, isLoading, isError } = useCompanyData(1, 14);
13+
const { stockHolds, stockHoldsLoading: isLoading, stockHoldsError: isError } = useGetStockHolds();
14+
const { data: companyData, isLoading: isCompanyDataLoading, isError: isCompanyDataError } = useCompanyData(1, 14);
1315

14-
// 'companies'가 'undefined'인 경우를 처리하기 위해 빈 배열로 초기화
15-
const companiesList = companies || [];
16+
// 모든 stockReturn의 합을 계산합니다.
17+
let totalEvaluationProfit = 0;
18+
19+
if (stockHolds) {
20+
totalEvaluationProfit = stockHolds.reduce((sum:number, stockHold: StockItemProps['stockData']) => sum + stockHold.stockReturn, 0);
21+
}
1622

1723
return (
1824
<WatchListContainer>
@@ -23,74 +29,75 @@ const WatchList: React.FC<WatchListProps> = ({ currentListType, onChangeListType
2329
setMenuOpen={setMenuOpen}
2430
/>
2531
<Divider1 />
26-
<EvaluationProfit>평가 수익금: +5,000,000원</EvaluationProfit> {/* 임의의 평가 수익금 */}
32+
<EvaluationProfit>평가 수익금: {totalEvaluationProfit.toLocaleString()}</EvaluationProfit>
2733
<Divider2 />
2834
<StockList>
29-
{isLoading ? (
35+
{isLoading || isCompanyDataLoading ? (
3036
<div>Loading...</div>
31-
) : isError ? (
37+
) : isError || isCompanyDataError ? (
3238
<div>Error fetching data</div>
3339
) : (
34-
companiesList.map((company) => (
35-
<StockItem
36-
key={company.companyId}
37-
company={company}
38-
setShowChangePrice={setShowChangePrice}
39-
showChangePrice={showChangePrice}
40-
/>
40+
stockHolds.map((stockHold: StockItemProps['stockData']) => (
41+
companyData ? (
42+
<StockItem
43+
key={stockHold.companyId}
44+
stockData={stockHold}
45+
companyData={companyData}
46+
setShowChangePrice={setShowChangePrice}
47+
showChangePrice={showChangePrice}
48+
/>
49+
) : null
4150
))
4251
)}
4352
</StockList>
4453
</WatchListContainer>
4554
);
4655
};
4756

48-
// Props와 상태에 대한 타입 정의
57+
export default HoldingList;
58+
4959
type WatchListProps = {
5060
currentListType: '전체종목' | '관심종목' | '보유종목';
5161
onChangeListType: (type: '전체종목' | '관심종목' | '보유종목') => void;
62+
5263
};
5364

54-
// WatchList 컴포넌트에 대한 스타일드 컴포넌트 정의
5565
const WatchListContainer = styled.div`
5666
display: flex;
5767
flex-direction: column;
5868
align-items: flex-start;
5969
`;
6070

6171
const Divider1 = styled.div`
62-
margin:0px;
63-
padding:0px;
64-
width: 100%;
65-
height: 10px;
66-
display: flex;
67-
flex-direction: row;
68-
border-bottom: 1px solid #2f4f4f;
72+
margin: 0px;
73+
padding: 0px;
74+
width: 100%;
75+
height: 10px;
76+
display: flex;
77+
flex-direction: row;
78+
border-bottom: 1px solid #2f4f4f;
79+
`;
80+
const EvaluationProfit = styled.div`
81+
font-size: 16px;
82+
font-weight: bold;
83+
margin: 8px 12px;
84+
text-align: center;
85+
color: red;
6986
`;
7087

7188
const Divider2 = styled.div`
72-
margin:0px;
73-
padding:0px;
74-
width: 100%;
75-
height: 4.5px;
76-
display: flex;
77-
flex-direction: row;
78-
border-bottom: 1px solid #2f4f4f;
89+
margin: 0px;
90+
padding: 0px;
91+
width: 100%;
92+
height: 4.5px;
93+
display: flex;
94+
flex-direction: row;
95+
border-bottom: 1px solid #2f4f4f;
7996
`;
8097

8198

82-
83-
const EvaluationProfit = styled.div`
84-
font-size: 16px;
85-
font-weight: bold;
86-
margin: 8px 0;
87-
text-align: center;
88-
color: red; // 수익금이 플러스일 경우 초록색으로 표시
89-
`;
9099
const StockList = styled.div`
91100
width: 90%;
92-
max-height: 800px; /* 스크롤이 발생할 최대 높이를 지정하세요 */
93-
overflow-y: auto; /* 세로 스크롤을 활성화합니다 */
101+
max-height: 800px;
102+
overflow-y: auto;
94103
`;
95-
96-
export default WatchList;

0 commit comments

Comments
 (0)