From 6217d314633aeafcf73c01c6fdf71cafa9fbecd2 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Tue, 24 Sep 2024 17:51:15 +0900
Subject: [PATCH 01/18] pull
---
src/Component/Game/Rank/rankBox.tsx | 4 +-
src/util/gameUtil.ts | 66 ++++++++++++++---------------
2 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/src/Component/Game/Rank/rankBox.tsx b/src/Component/Game/Rank/rankBox.tsx
index 7c91040..644f466 100644
--- a/src/Component/Game/Rank/rankBox.tsx
+++ b/src/Component/Game/Rank/rankBox.tsx
@@ -3,7 +3,7 @@ import * as S from "./rankBoxStyle";
import gold from "../../../img/goldMedal.png";
import silver from "../../../img/silverMedal.png";
import bronze from "../../../img/bronzeMedal.png";
-import { formatPrice, formatRate } from "../../../util/util";
+import { formatPrice, formatChangeRateFrom } from "../../../util/gameUtil";
const RankBox: React.FC = ({
nickname,
@@ -24,7 +24,7 @@ const RankBox: React.FC = ({
{nickname}
{formatPrice(total)}
- {formatRate(profitRate)} %
+ {profitRate} %
);
diff --git a/src/util/gameUtil.ts b/src/util/gameUtil.ts
index bf5af11..1405fc6 100644
--- a/src/util/gameUtil.ts
+++ b/src/util/gameUtil.ts
@@ -1,48 +1,48 @@
import React from "react";
export const formatPrice = (num: number): string => {
- if (num === 0) {
- return "-";
- }
+ if (num === 0) {
+ return "-";
+ }
- return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
export const formatChangeRate = (changeRate: number): string => {
- if (changeRate === 0) {
- return "-";
- }
+ if (changeRate === 0) {
+ return "-";
+ }
- const formattedRate = `${Math.abs(changeRate).toFixed()}%`; // 소수점 2자리까지 표시
- if (changeRate > 0) {
- return `▲ + ${formattedRate}`;
- } else if (changeRate < 0) {
- return `▼ - ${formattedRate}`;
- } else {
- return formattedRate;
- }
+ const formattedRate = `${Math.abs(changeRate).toFixed(1)}%`; // 소수점 2자리까지 표시
+ if (changeRate > 0) {
+ return `▲ ${formattedRate}`;
+ } else if (changeRate < 0) {
+ return `▼ ${formattedRate}`;
+ } else {
+ return formattedRate;
+ }
};
interface ChangeRateResult {
- format: string;
- color: string;
+ format: string;
+ color: string;
}
export const formatChangeRateFrom = (changeRate: number): ChangeRateResult => {
- if (changeRate > 0) {
- return {
- format: `+ ${changeRate}%`,
- color: "red",
- };
- } else if (changeRate < 0) {
- return {
- format: `- ${changeRate}`,
- color: "blue",
- };
- } else {
- return {
- format: "-",
- color: "black",
- };
- }
+ if (changeRate > 0) {
+ return {
+ format: `+ ${changeRate}%`,
+ color: "red",
+ };
+ } else if (changeRate < 0) {
+ return {
+ format: `- ${changeRate}`,
+ color: "blue",
+ };
+ } else {
+ return {
+ format: "-",
+ color: "black",
+ };
+ }
};
From 6e766353234548ad6c28746e40dca6e16fc6b529 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Thu, 26 Sep 2024 15:52:07 +0900
Subject: [PATCH 02/18] pull
---
src/index.tsx | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/index.tsx b/src/index.tsx
index d97ca1d..c7cbae3 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,4 +1,3 @@
-import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
From b73e949209896394ce650c3233bf78536699fbf1 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Fri, 27 Sep 2024 14:21:22 +0900
Subject: [PATCH 03/18] =?UTF-8?q?Fix=20:=20=EB=9E=AD=ED=82=B9=20=EB=93=B1?=
=?UTF-8?q?=EB=A1=9D=20=EB=B2=84=ED=8A=BC=20nav=20=EC=82=AD=EC=A0=9C,=20?=
=?UTF-8?q?=EB=93=B1=EB=A1=9D=20=ED=99=95=EC=9D=B8=20=EB=AA=A8=EB=8B=AC=20?=
=?UTF-8?q?=EB=9D=84=EC=9A=B0=EA=B8=B0=EB=A1=9C=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Pages/game/totalResult.tsx | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/Pages/game/totalResult.tsx b/src/Pages/game/totalResult.tsx
index fb5be86..e0034ef 100644
--- a/src/Pages/game/totalResult.tsx
+++ b/src/Pages/game/totalResult.tsx
@@ -106,7 +106,13 @@ const TotalResult = () => {
)
.then((res) => {
if (res.status === 200) {
- nav("/game/rank");
+ {
+ swal({
+ title: "랭킹 등록 완료!",
+ text: "랭킹이 등록되었습니다.",
+ icon: "success",
+ });
+ }
} else {
{
swal({
From 50b7a47f0e7bf9ab3c38ee22d40049adf22087b2 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Fri, 27 Sep 2024 14:23:38 +0900
Subject: [PATCH 04/18] =?UTF-8?q?Fix=20:=20=EA=B2=8C=EC=9E=84=20=ED=97=A4?=
=?UTF-8?q?=EB=8D=94=EC=97=90=20=EB=A3=B0=20=EC=84=A4=EB=AA=85=20=EB=8B=AC?=
=?UTF-8?q?=EB=A6=AC=EB=8A=94=20=EA=B1=B0=20=EA=B2=8C=EC=9E=84=EC=A4=91?=
=?UTF-8?q?=EC=97=90=EB=A7=8C=20=EB=8B=AC=EB=A6=AC=EB=8F=84=EB=A1=9D=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Component/Game/GameHeader.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Component/Game/GameHeader.tsx b/src/Component/Game/GameHeader.tsx
index 3dc22af..54add40 100644
--- a/src/Component/Game/GameHeader.tsx
+++ b/src/Component/Game/GameHeader.tsx
@@ -21,7 +21,7 @@ const GameHeader: React.FC = ({ text }) => {
return (
<>{text}>
-
+ {text.length < 4 ? : <>>}
);
};
From b883d08b58efe93086dc67038cc9e1c85b9e5c70 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Fri, 27 Sep 2024 14:40:55 +0900
Subject: [PATCH 05/18] =?UTF-8?q?Fix=20:=20=EB=9E=AD=ED=82=B9=20=EB=B0=95?=
=?UTF-8?q?=EC=8A=A4=20=ED=95=AD=EB=AA=A9=20=EC=B6=94=EA=B0=80=20#222?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Pages/game/rank.tsx | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/Pages/game/rank.tsx b/src/Pages/game/rank.tsx
index 72c8eab..c57bb67 100644
--- a/src/Pages/game/rank.tsx
+++ b/src/Pages/game/rank.tsx
@@ -4,7 +4,15 @@ import { RankDataProps, RankListProps } from "../../constants/interface";
import axios from "axios";
import RankList from "../../Component/Game/Rank/rankList";
import BentoBar from "../../Game/Main/BentoBar/bentoBar";
-import swal from "sweetalert";
+import styled from "styled-components";
+
+const TitleContainer = styled.div`
+ display: flex;
+ flex-direction: row;
+ margin-top: 1rem;
+ border-bottom: 1px solid black;
+ padding-bottom: 0.5rem;
+`;
const Rank = () => {
const [rankList, setRankList] = useState([]);
@@ -29,6 +37,12 @@ const Rank = () => {
return (
+
+ 순위
+ 닉네임
+ 수익금
+ 수익률
+
From 0434ff922d4217710f5aac9056fb96ef8ee552a6 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Fri, 27 Sep 2024 14:53:32 +0900
Subject: [PATCH 06/18] =?UTF-8?q?Style=20:=20=EC=B5=9C=EC=A2=85=20?=
=?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=88=98?=
=?UTF-8?q?=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Pages/game/rank.tsx | 4 ++--
src/Pages/game/totalResult.tsx | 8 +++-----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/Pages/game/rank.tsx b/src/Pages/game/rank.tsx
index c57bb67..e180aaf 100644
--- a/src/Pages/game/rank.tsx
+++ b/src/Pages/game/rank.tsx
@@ -39,8 +39,8 @@ const Rank = () => {
순위
- 닉네임
- 수익금
+ 닉네임
+ 수익금
수익률
diff --git a/src/Pages/game/totalResult.tsx b/src/Pages/game/totalResult.tsx
index e0034ef..d0ca08b 100644
--- a/src/Pages/game/totalResult.tsx
+++ b/src/Pages/game/totalResult.tsx
@@ -22,6 +22,7 @@ const SkrrContainer = styled.div`
display: flex;
flex-direction: row;
position: relative;
+ margin-top: 1.5rem;
`;
const ImgStyle = styled.img`
@@ -38,9 +39,9 @@ const BtnBox = styled.div`
flex-direction: row;
align-items: center;
gap: 1rem;
- margin-top: 0.5rem;
margin-left: auto;
margin-right: 2.5rem;
+ margin-top: 1rem;
`;
const NickBox = styled.div`
@@ -134,10 +135,7 @@ const TotalResult = () => {
-
- {user}
- 의 점수를
-
+ {user}
diff --git a/src/Game/Loading/progressBar.tsx b/src/Game/Loading/progressBar.tsx
index a3e0e89..940ab2c 100644
--- a/src/Game/Loading/progressBar.tsx
+++ b/src/Game/Loading/progressBar.tsx
@@ -1,9 +1,11 @@
import styled from "styled-components";
const Container = styled.div`
- width: 100%;
+ width: 70%;
max-width: 400px;
- margin: 15px auto;
+ /* margin: 15px auto; */
+ margin: 0.1rem 1rem 1rem 0.5rem;
+
background-color: rgba(255, 255, 255, 0.1);
border-radius: 50px;
padding: 5px;
@@ -28,6 +30,7 @@ const Text = styled.span`
font-weight: bold;
z-index: 1;
font-size: 12px;
+ margin-left: 0%.8;
`;
interface ProgressBarProps {
diff --git a/src/Game/Tutorial/rule.tsx b/src/Game/Tutorial/rule.tsx
index 64df4e5..5a308cb 100644
--- a/src/Game/Tutorial/rule.tsx
+++ b/src/Game/Tutorial/rule.tsx
@@ -10,7 +10,7 @@ const Overlay = styled.div`
left: 0;
width: 100vw;
height: 100vh;
- background-color: rgba(0, 0, 0, 0.8); /* 반투명한 검정색 배경 */
+ background-color: rgba(163, 152, 152, 0.8); /* 반투명한 검정색 배경 */
z-index: 10; /* 모달 뒤에 위치, 모달보다 낮은 z-index */
`;
@@ -67,10 +67,20 @@ const RuleModal = () => {
return (
setOnModal(true)}>
-
+
룰 설명
-
+
{onModal && (
diff --git a/src/Pages/game/playPage.tsx b/src/Pages/game/playPage.tsx
index ec36cca..9678c29 100644
--- a/src/Pages/game/playPage.tsx
+++ b/src/Pages/game/playPage.tsx
@@ -16,156 +16,154 @@ import { usePortfolioStore } from "../../store/usePortfolioStore";
import ProgressBar from "../../Game/Loading/progressBar";
const Container = styled.div`
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- text-align: center;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ text-align: center;
`;
const PlayPage = () => {
- const { year } = useParams<{ year: string }>();
- const { stockData, setStockData } = useStock();
- const nav = useNavigate();
- const yearValue = year || "2014";
- const [isTradeModalVisible, setIsTradeModalVisible] = useState(false);
- const [isPassModalVisible, setIsPassModalVisible] = useState(false);
- const [isHappyNewYearModal, setIsHappyNewYearModal] = useState(false);
- const [budget, setBudget] = useState(0);
- const [loading, setLoading] = useState(false);
-
- const check = usePortfolioStore((state) => state.check);
- const setCheck = usePortfolioStore((state) => state.setCheck);
-
- const startYear = 2014;
- const lastYear = 2023;
-
- // 년도 진행률 표시
- const calculateProgress = () => {
- return (
- ((parseInt(yearValue, 10) - startYear) / (lastYear - startYear)) *
- 100
- );
- };
-
- const [progress, setProgress] = useState(calculateProgress);
-
- // 거래하기 모달 핸들러
- const openTradeModal = () => {
- setIsTradeModalVisible(true);
- };
-
- const closeTradeModal = () => {
- setIsTradeModalVisible(false);
- };
-
- // 넘어가기 모달 핸들러
- const openPassModal = () => {
- setIsPassModalVisible(true);
- };
-
- const closePassModal = () => {
- setIsPassModalVisible(false);
- };
-
- // 넘어가기 버튼 누르면 중간결과 호출
- const handleConfirmPass = async () => {
- try {
- setLoading(true);
- setIsHappyNewYearModal(true);
- setIsPassModalVisible(false);
-
- if (year === "2023") {
- console.log("게임 끝");
- nav("/game/result/total");
- } else {
- const response = await axios.get(
- `${process.env.REACT_APP_API_URL}/v1/game/interim`,
- {
- withCredentials: true,
- headers: {
- "Content-Type": "application/json",
- },
- }
- );
- if (response.status === 200) {
- if (
- (parseInt(yearValue, 10) + 1).toString() ===
- response.data.year.toString()
- ) {
- const updatedStockList = response.data.stockList;
- setStockData(updatedStockList);
- }
-
- // API 완료 후 모달 닫고 페이지 이동
- setIsHappyNewYearModal(false);
- const nextYear = (parseInt(yearValue, 10) + 1).toString();
- nav(`/game/play/${nextYear}`);
- setCheck(!check);
- setProgress(
- ((parseInt(nextYear, 10) - startYear) /
- (lastYear - startYear)) *
- 100
- );
- }
- }
- } catch (error) {
- console.error(error);
- } finally {
- setLoading(false);
- closePassModal();
- }
- };
-
+ const { year } = useParams<{ year: string }>();
+ const { stockData, setStockData } = useStock();
+ const nav = useNavigate();
+ const yearValue = year || "2014";
+ const [isTradeModalVisible, setIsTradeModalVisible] = useState(false);
+ const [isPassModalVisible, setIsPassModalVisible] = useState(false);
+ const [isHappyNewYearModal, setIsHappyNewYearModal] = useState(false);
+ const [budget, setBudget] = useState(0);
+ const [loading, setLoading] = useState(false);
+
+ const check = usePortfolioStore((state) => state.check);
+ const setCheck = usePortfolioStore((state) => state.setCheck);
+
+ const startYear = 2014;
+ const lastYear = 2023;
+
+ // 년도 진행률 표시
+ const calculateProgress = () => {
return (
-
-
-
-
-
-
-
-
-
-
-
+ ((parseInt(yearValue, 10) - startYear) / (lastYear - startYear)) * 100
);
+ };
+
+ const [progress, setProgress] = useState(calculateProgress);
+
+ // 거래하기 모달 핸들러
+ const openTradeModal = () => {
+ setIsTradeModalVisible(true);
+ };
+
+ const closeTradeModal = () => {
+ setIsTradeModalVisible(false);
+ };
+
+ // 넘어가기 모달 핸들러
+ const openPassModal = () => {
+ setIsPassModalVisible(true);
+ };
+
+ const closePassModal = () => {
+ setIsPassModalVisible(false);
+ };
+
+ // 넘어가기 버튼 누르면 중간결과 호출
+ const handleConfirmPass = async () => {
+ try {
+ setLoading(true);
+ setIsHappyNewYearModal(true);
+ setIsPassModalVisible(false);
+
+ if (year === "2023") {
+ console.log("게임 끝");
+ nav("/game/result/total");
+ } else {
+ const response = await axios.get(
+ `${process.env.REACT_APP_API_URL}/v1/game/interim`,
+ {
+ withCredentials: true,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
+ if (response.status === 200) {
+ if (
+ (parseInt(yearValue, 10) + 1).toString() ===
+ response.data.year.toString()
+ ) {
+ const updatedStockList = response.data.stockList;
+ setStockData(updatedStockList);
+ }
+
+ // API 완료 후 모달 닫고 페이지 이동
+ setIsHappyNewYearModal(false);
+ const nextYear = (parseInt(yearValue, 10) + 1).toString();
+ nav(`/game/play/${nextYear}`);
+ setCheck(!check);
+ setProgress(
+ ((parseInt(nextYear, 10) - startYear) / (lastYear - startYear)) *
+ 100
+ );
+ }
+ }
+ } catch (error) {
+ console.error(error);
+ } finally {
+ setLoading(false);
+ closePassModal();
+ }
+ };
+
+ return (
+
+
+
+
+ {/*
*/}
+ {/*
+ 게임 진행도
+
*/}
+ {/*
*/}
+
+
+
+
+
+
+
+
+
+ );
};
export default PlayPage;
From 57c3872ff35357fae88f754917bed44ace5861da Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Sat, 28 Sep 2024 21:05:41 +0900
Subject: [PATCH 15/18] =?UTF-8?q?Fix=20:=20=EC=A0=95=EB=B3=B4=EA=B1=B0?=
=?UTF-8?q?=EB=9E=98=EC=86=8C=EC=97=90=EC=84=9C=20=EB=A3=B0=EC=84=A4?=
=?UTF-8?q?=EB=AA=85=20=EC=95=88=EB=B3=B4=EC=9D=B4=EA=B2=8C=20=EC=88=98?=
=?UTF-8?q?=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Component/Game/GameHeader.tsx | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/Component/Game/GameHeader.tsx b/src/Component/Game/GameHeader.tsx
index 26f5c21..be93bc4 100644
--- a/src/Component/Game/GameHeader.tsx
+++ b/src/Component/Game/GameHeader.tsx
@@ -25,7 +25,10 @@ const GameHeader: React.FC = ({ text }) => {
return (
<>{text}>
- {rule === "gameStocks" || rule === "total" || rule === "rank" ? (
+ {rule === "gameStocks" ||
+ rule === "total" ||
+ rule === "rank" ||
+ rule === "info" ? (
<>>
) : (
From 674751b4d317b8d158431dcefdf25e8216e8d8ad Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Sat, 28 Sep 2024 21:48:53 +0900
Subject: [PATCH 16/18] =?UTF-8?q?Style=20:=20=EC=A0=95=EB=B3=B4=20?=
=?UTF-8?q?=EA=B1=B0=EB=9E=98=EC=86=8C=20=EB=89=B4=EC=8A=A4=20=EB=82=B4?=
=?UTF-8?q?=EC=9A=A9=20=EA=B8=B8=EB=A9=B4=20css=20=EA=B9=A8=EC=A7=80?=
=?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Game/Shop/shop.tsx | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/Game/Shop/shop.tsx b/src/Game/Shop/shop.tsx
index 5dc6b2b..b4d90b4 100644
--- a/src/Game/Shop/shop.tsx
+++ b/src/Game/Shop/shop.tsx
@@ -174,39 +174,54 @@ const Shop: React.FC = ({ selectedStock, budget, setBudget }) => {
) : (
-
+
Skrr News
-
+
{selectedStockData ? selectedStockData.name : ""}{" "}
{""}
{selectedTab.level}
@@ -216,7 +231,7 @@ const Shop: React.FC = ({ selectedStock, budget, setBudget }) => {
Date: Sat, 28 Sep 2024 21:58:19 +0900
Subject: [PATCH 17/18] =?UTF-8?q?Docs:=20=EC=9E=90=EC=9E=98=ED=95=9C?=
=?UTF-8?q?=EA=B1=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Component/Game/GameHeader.tsx | 2 +-
src/Component/Game/Rank/rankBox.tsx | 4 +++-
src/Pages/game/rank.tsx | 2 +-
src/util/gameUtil.ts | 19 ++++++++-----------
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/Component/Game/GameHeader.tsx b/src/Component/Game/GameHeader.tsx
index be93bc4..b96e231 100644
--- a/src/Component/Game/GameHeader.tsx
+++ b/src/Component/Game/GameHeader.tsx
@@ -26,7 +26,7 @@ const GameHeader: React.FC = ({ text }) => {
<>{text}>
{rule === "gameStocks" ||
- rule === "total" ||
+ rule === "result" ||
rule === "rank" ||
rule === "info" ? (
<>>
diff --git a/src/Component/Game/Rank/rankBox.tsx b/src/Component/Game/Rank/rankBox.tsx
index 65aec36..d3fdf31 100644
--- a/src/Component/Game/Rank/rankBox.tsx
+++ b/src/Component/Game/Rank/rankBox.tsx
@@ -24,7 +24,9 @@ const RankBox: React.FC = ({
{nickname}
{formatPrice(total)}
- {profitRate} %
+
+ {profitRate.toFixed(1)} %
+
);
diff --git a/src/Pages/game/rank.tsx b/src/Pages/game/rank.tsx
index e180aaf..1a17210 100644
--- a/src/Pages/game/rank.tsx
+++ b/src/Pages/game/rank.tsx
@@ -40,7 +40,7 @@ const Rank = () => {
순위
닉네임
- 수익금
+ 수익금
수익률
diff --git a/src/util/gameUtil.ts b/src/util/gameUtil.ts
index ba33680..1ff9aa8 100644
--- a/src/util/gameUtil.ts
+++ b/src/util/gameUtil.ts
@@ -1,23 +1,20 @@
-import React from "react";
-import { P } from "../Component/GoogleLogin/loginStyle";
-
export const formatPrice = (num: number): string => {
if (num === 0) {
- return "-";
+ return "0";
}
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
export const formatPriceWithYear = (num: number, year: string): string => {
- if (num === 0 && year !== "2014") {
- return "상장폐지";
- }
- if (num === 0) {
- return "-";
- }
+ if (num === 0 && year !== "2014") {
+ return "상장폐지";
+ }
+ if (num === 0) {
+ return "-";
+ }
- return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
export const formatChangeRate = (changeRate: number): string => {
From 3237e81d2f15b0d83f9f1e432d5d680cff9ab832 Mon Sep 17 00:00:00 2001
From: lucy726j
Date: Sat, 28 Sep 2024 22:41:06 +0900
Subject: [PATCH 18/18] =?UTF-8?q?Feat=20:=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?=
=?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20->=20url?=
=?UTF-8?q?=EC=97=90=20=EB=85=84=EB=8F=84=20=EC=9E=85=EB=A0=A5=ED=95=B4?=
=?UTF-8?q?=EC=84=9C=20=EC=A0=91=EC=86=8D=ED=95=98=EB=8A=94=20=EA=B2=BD?=
=?UTF-8?q?=EC=9A=B0=20=EC=A0=95=EC=83=81=EC=A0=81=EC=9D=B8=20=EC=A0=91?=
=?UTF-8?q?=EA=B7=BC=20=EA=B2=BD=EB=A1=9C=EA=B0=80=20=EC=95=84=EB=8B=99?=
=?UTF-8?q?=EB=8B=88=EB=8B=A4=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B3=B4?=
=?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Component/Game/GameMoney.tsx | 269 ++++++++++++++++---------------
src/Pages/404/noUser.tsx | 2 -
src/Pages/game/infoPage.tsx | 50 +++++-
src/Pages/game/playPage.tsx | 122 +++++++++-----
src/store/useGameStore.ts | 15 ++
5 files changed, 276 insertions(+), 182 deletions(-)
create mode 100644 src/store/useGameStore.ts
diff --git a/src/Component/Game/GameMoney.tsx b/src/Component/Game/GameMoney.tsx
index f89a1bc..f9cef8f 100644
--- a/src/Component/Game/GameMoney.tsx
+++ b/src/Component/Game/GameMoney.tsx
@@ -4,162 +4,167 @@ import { holding } from "../../constants/interface";
import { useState, useEffect } from "react";
import axios from "axios";
import { usePortfolioStore } from "../../store/usePortfolioStore";
+import { useGameStore } from "../../store/useGameStore";
import { useNavigate } from "react-router-dom";
import GameViewTab from "./gameViewTab";
const GameMoney = ({
- setBudget,
- budget,
+ setBudget,
+ budget,
}: {
- setBudget: (budget: number) => void;
- budget: number;
+ setBudget: (budget: number) => void;
+ budget: number;
}) => {
- const nav = useNavigate();
-
- const [nickname, setNickname] = useState(""); // 닉네임
- const [total, setTotal] = useState(0); // 총 평가금액
- const [changeFromLast, setChangeFromLast] = useState(0); // 작년 대비 금액
- const [changeFromStart, setChangeFromStart] = useState(0); // 전체 대비 금액
- const [changeRateFromLast, setChangeRateFromLast] = useState(0); // 작년 대비 변동률
- const [changeRateFromStart, setChangeRateFromStart] = useState(0); // 전체 대비 변동률
- const [holdingList, setHoldingList] = useState([]); // 20xx년 주식가격
- const [showTable, setShowTable] = useState(false);
-
- const check = usePortfolioStore((state) => state.check);
-
- useEffect(() => {
- axios
- .get(`${process.env.REACT_APP_API_URL}/v1/game/user`, {
- withCredentials: true,
- headers: {
- "Content-Type": "application/json",
- },
- })
- .then((res) => {
- if (res.status === 200) {
- setNickname(res.data.nickname);
- setBudget(res.data.budget);
- setTotal(res.data.total);
- setChangeFromLast(res.data.changeFromLast);
- setChangeFromStart(res.data.changeFromStart);
- setChangeRateFromLast(res.data.changeRateFromLast);
- setChangeRateFromStart(res.data.changeRateFromStart);
- setHoldingList(res.data.holdingList);
- } else if (res.status === 401) {
- alert("401");
- }
- })
- .catch((e) => {
- nav("/error");
- });
- }, [check]);
-
- const handleShowTable = () => {
- setShowTable((prev) => !prev);
- };
-
- return (
-
-
- {nickname} 님의 계좌잔고 💰
-
-
- 거래가능금액
- {formatPrice(budget)} 원
-
-
-
- 총 평가금액
- {formatPrice(total)} 원
-
-
- 작년 대비
- 0
- ? "red"
- : changeRateFromLast < 0
- ? "blue"
- : "black",
- }}
- >
- {formatPrice(changeFromLast)} 원 ({changeRateFromLast}%)
-
-
-
- 전체 대비
- 0
- ? "red"
- : changeRateFromStart < 0
- ? "blue"
- : "black",
- }}
- >
- {formatPrice(changeFromStart)} 원 ({changeRateFromStart}%)
-
-
-
-
-
-
- {showTable && }
-
- );
+ const nav = useNavigate();
+
+ const [nickname, setNickname] = useState(""); // 닉네임
+ const [total, setTotal] = useState(0); // 총 평가금액
+ const [changeFromLast, setChangeFromLast] = useState(0); // 작년 대비 금액
+ const [changeFromStart, setChangeFromStart] = useState(0); // 전체 대비 금액
+ const [changeRateFromLast, setChangeRateFromLast] = useState(0); // 작년 대비 변동률
+ const [changeRateFromStart, setChangeRateFromStart] = useState(0); // 전체 대비 변동률
+ const [holdingList, setHoldingList] = useState([]); // 20xx년 주식가격
+ const [showTable, setShowTable] = useState(false);
+
+ const check = usePortfolioStore((state) => state.check);
+
+ // 페이지 유효성 검사
+ const setCheckYear = useGameStore((state) => state.setCheckYear);
+
+ useEffect(() => {
+ axios
+ .get(`${process.env.REACT_APP_API_URL}/v1/game/user`, {
+ withCredentials: true,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ })
+ .then((res) => {
+ if (res.status === 200) {
+ setCheckYear(res.data.year);
+ setNickname(res.data.nickname);
+ setBudget(res.data.budget);
+ setTotal(res.data.total);
+ setChangeFromLast(res.data.changeFromLast);
+ setChangeFromStart(res.data.changeFromStart);
+ setChangeRateFromLast(res.data.changeRateFromLast);
+ setChangeRateFromStart(res.data.changeRateFromStart);
+ setHoldingList(res.data.holdingList);
+ } else if (res.status === 401) {
+ alert("401");
+ }
+ })
+ .catch((e) => {
+ nav("/error");
+ });
+ }, [check]);
+
+ const handleShowTable = () => {
+ setShowTable((prev) => !prev);
+ };
+
+ return (
+
+
+ {nickname} 님의 계좌잔고 💰
+
+
+ 거래가능금액
+ {formatPrice(budget)} 원
+
+
+
+ 총 평가금액
+ {formatPrice(total)} 원
+
+
+ 작년 대비
+ 0
+ ? "red"
+ : changeRateFromLast < 0
+ ? "blue"
+ : "black",
+ }}
+ >
+ {formatPrice(changeFromLast)} 원 ({changeRateFromLast}%)
+
+
+
+ 전체 대비
+ 0
+ ? "red"
+ : changeRateFromStart < 0
+ ? "blue"
+ : "black",
+ }}
+ >
+ {formatPrice(changeFromStart)} 원 ({changeRateFromStart}%)
+
+
+
+
+
+
+ {showTable && }
+
+ );
};
const GameMoneyContainer = styled.div`
- width: 85%;
- height: auto;
- border-radius: 20px;
- box-shadow: 3px 3px 3px rgb(213, 213, 213);
- padding: 20px 10px;
- position: relative;
- margin-top: 20px;
- margin-bottom: 20px;
+ width: 85%;
+ height: auto;
+ border-radius: 20px;
+ box-shadow: 3px 3px 3px rgb(213, 213, 213);
+ padding: 20px 10px;
+ position: relative;
+ margin-top: 20px;
+ margin-bottom: 20px;
`;
const GameMoneyTitle = styled.div`
- margin-bottom: 30px;
+ margin-bottom: 30px;
`;
const GameMoneyBalance = styled.div`
- display: flex;
- margin: 15px 0;
- flex-direction: row;
+ display: flex;
+ margin: 15px 0;
+ flex-direction: row;
`;
const BalanceDetailButton = styled.div`
- position: absolute;
- top: 118px;
- right: 20px;
+ position: absolute;
+ top: 118px;
+ right: 20px;
`;
const BalanceTitle = styled.div`
- color: #6c6c6c;
- width: 110px;
+ color: #6c6c6c;
+ width: 110px;
`;
const Button = styled.button`
- width: 78px;
- height: 40px;
- border-radius: 50px;
- border: none;
- background-color: #f1f1f1;
- cursor: pointer;
-
- &:hover {
- background-color: #615efc;
- color: white;
- font-weight: 600;
- }
+ width: 78px;
+ height: 40px;
+ border-radius: 50px;
+ border: none;
+ background-color: #f1f1f1;
+ cursor: pointer;
+
+ &:hover {
+ background-color: #615efc;
+ color: white;
+ font-weight: 600;
+ }
`;
export default GameMoney;
diff --git a/src/Pages/404/noUser.tsx b/src/Pages/404/noUser.tsx
index 296e704..e323774 100644
--- a/src/Pages/404/noUser.tsx
+++ b/src/Pages/404/noUser.tsx
@@ -2,8 +2,6 @@ import { useNavigate } from "react-router-dom";
import styled from "styled-components";
import { GoAlert } from "react-icons/go";
import { Colors } from "../../Styles/Colors";
-import Header from "../../Component/Layout/Header/Header";
-import NavBar from "../../Component/Layout/NavBar/NavBar";
const Box = styled.div`
height: 60vh;
diff --git a/src/Pages/game/infoPage.tsx b/src/Pages/game/infoPage.tsx
index 3ad2be0..a086451 100644
--- a/src/Pages/game/infoPage.tsx
+++ b/src/Pages/game/infoPage.tsx
@@ -1,14 +1,54 @@
-import { useParams } from "react-router-dom";
+import { useParams, useNavigate } from "react-router-dom";
import ExchangeStoreMain from "../../Game/Shop/exchangeStoreMain";
import GameHeader from "../../Component/Game/GameHeader";
+import { GoAlert } from "react-icons/go";
+import { Colors } from "../../Styles/Colors";
+import Button from "../../Component/Button/button";
+import { useGameStore } from "../../store/useGameStore";
const InfoPage = () => {
const { year } = useParams<{ year: string }>();
+ const yearValue = year || "2014";
+ const yearNumber = parseInt(yearValue, 10);
+ const checkYear = useGameStore((state) => state.checkYear);
+ const nav = useNavigate();
+
return (
-
-
-
-
+ <>
+ {yearNumber !== checkYear ? (
+
+
+
정상적인 접근 경로가 아닙니다
+
+ ) : (
+
+
+
+
+ )}
+ >
);
};
diff --git a/src/Pages/game/playPage.tsx b/src/Pages/game/playPage.tsx
index 9678c29..c904916 100644
--- a/src/Pages/game/playPage.tsx
+++ b/src/Pages/game/playPage.tsx
@@ -1,5 +1,4 @@
-import { useNavigate, useParams, useLocation } from "react-router-dom";
-import { useEffect } from "react";
+import { useNavigate, useParams } from "react-router-dom";
import GameButtons from "../../Component/Game/GameButtons";
import GameHeader from "../../Component/Game/GameHeader";
import GameMoney from "../../Component/Game/GameMoney";
@@ -13,7 +12,11 @@ import "./gameStyle.css";
import HappyNewYearModal from "./HappyNewYearModal";
import { useStock } from "../../store/stockContext";
import { usePortfolioStore } from "../../store/usePortfolioStore";
+import { useGameStore } from "../../store/useGameStore";
import ProgressBar from "../../Game/Loading/progressBar";
+import { GoAlert } from "react-icons/go";
+import { Colors } from "../../Styles/Colors";
+import Button from "../../Component/Button/button";
const Container = styled.div`
display: flex;
@@ -24,16 +27,19 @@ const Container = styled.div`
`;
const PlayPage = () => {
- const { year } = useParams<{ year: string }>();
+ const { year } = useParams<{ year?: string }>();
const { stockData, setStockData } = useStock();
const nav = useNavigate();
const yearValue = year || "2014";
+ // 페이지 유효성 검사를 위한 변수
+ const yearNumber = parseInt(yearValue, 10);
const [isTradeModalVisible, setIsTradeModalVisible] = useState(false);
const [isPassModalVisible, setIsPassModalVisible] = useState(false);
const [isHappyNewYearModal, setIsHappyNewYearModal] = useState(false);
const [budget, setBudget] = useState(0);
const [loading, setLoading] = useState(false);
+ const checkYear = useGameStore((state) => state.checkYear);
const check = usePortfolioStore((state) => state.check);
const setCheck = usePortfolioStore((state) => state.setCheck);
@@ -75,7 +81,6 @@ const PlayPage = () => {
setIsPassModalVisible(false);
if (year === "2023") {
- console.log("게임 끝");
nav("/game/result/total");
} else {
const response = await axios.get(
@@ -116,20 +121,49 @@ const PlayPage = () => {
};
return (
-
-
-
-
- {/*
*/}
- {/*
+ {yearNumber !== checkYear ? (
+
+
+
정상적인 접근 경로가 아닙니다
+
+ ) : (
+
+
+
+
+ {/*
*/}
+ {/*
{
>
게임 진행도
*/}
- {/*
*/}
-
-
-
-
-
-
-
-
-
+ {/*
*/}
+
+
+
+
+
+
+
+
+
+ )}
+ >
);
};
diff --git a/src/store/useGameStore.ts b/src/store/useGameStore.ts
new file mode 100644
index 0000000..5bd84a5
--- /dev/null
+++ b/src/store/useGameStore.ts
@@ -0,0 +1,15 @@
+import { create } from "zustand";
+import { PortfolioProps, StockProps } from "../constants/interface";
+
+interface GameState {
+ checkYear: number;
+ setCheckYear: (checkYear: number) => void;
+}
+
+export const useGameStore = create((set) => ({
+ checkYear: 2014,
+
+ setCheckYear(checkYear) {
+ set({ checkYear });
+ },
+}));