Skip to content

Commit

Permalink
Merge pull request #203 from 100-hours-a-week/feature/elle
Browse files Browse the repository at this point in the history
Feature/elle
  • Loading branch information
lucy726j authored Sep 17, 2024
2 parents 3453722 + 87b34cf commit b2a631f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 44 deletions.
45 changes: 24 additions & 21 deletions src/Component/Game/GameTradeSwipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,34 @@ const GameTradeSwipe = ({
}, 700);
};

const selectedStockName = stockData?.find(
(stock) => stock.stockId === selectedStock?.stockId
);

// 로컬스토리지에서 종목 갖고오기
useEffect(() => {
const stock2014 = localStorage.getItem("stock2014");
const stockListData = localStorage.getItem("stockListData");
// stockData가 변경될 때 stockOptions를 업데이트
if (stockData) {
const options = stockData.map((stock) => ({
stockId: stock.stockId,
name: stock.name,
}));
setStockOptions(options);

if (stock2014) {
const parsedStock2014 = JSON.parse(stock2014);
setStockOptions(parsedStock2014);
if (!selectedStock) {
setSelectedStock(parsedStock2014[0]); // 첫 번째 종목을 기본값으로 설정
}
} else if (stockListData) {
const parsedStockListData = JSON.parse(stockListData);
setStockOptions(parsedStockListData);
if (!selectedStock) {
setSelectedStock(parsedStockListData[0]); // 첫 번째 종목을 기본값으로 설정
// selectedStock 설정
if (!selectedStock && options.length > 0) {
setSelectedStock(options[0]);
setCurrentPrice(stockData[0].current);
}
} else {
console.log("로컬 스토리지에서 주식 데이터를 찾을 수 없습니다.");
}
}, []);

// selectedStock이 변경될 때마다 가격 업데이트
if (selectedStock && stockData) {
const selectedStockData = stockData.find(
(stock) => stock.stockId === selectedStock.stockId
);
setCurrentPrice(selectedStockData?.current || null);
}
}, [stockData, selectedStock]);

const selectedStockName = stockData?.find(
(stock) => stock.stockId === selectedStock?.stockId
);

return (
<div className="GameTradeSwipe">
Expand Down
29 changes: 6 additions & 23 deletions src/Pages/game/playPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ExSAm from "../../Game/Tutorial/ex";
import { StockYearProps } from "../../constants/interface";
import HappyNewYearModal from "./HappyNewYearModal";
import { useStock } from "../../store/stockContext";
import { usePortfolioStore } from "../../store/usePortfolioStore";

const Container = styled.div`
display: flex;
Expand All @@ -35,6 +36,9 @@ const PlayPage = () => {
const [isHappyNewYearModal, setIsHappyNewYearModal] = useState(false);
const [budget, setBudget] = useState(0);

const check = usePortfolioStore((state) => state.check);
const setCheck = usePortfolioStore((state) => state.setCheck);

// 튜토리얼을 볼지 결정하는 상태 (첫 번째 튜토리얼 단계 관리)
const [fir, setFir] = useState(true); // 처음엔 true로 설정하여 튜토리얼 표시
const [sec, setSec] = useState(false); // 두 번째 튜토리얼 단계를 위한 상태
Expand Down Expand Up @@ -87,10 +91,6 @@ const PlayPage = () => {
console.log(response);
setStockData(updatedStockList);

// 중간 결과를 로컬 스토리지에 저장
localStorage.setItem("stockListData", JSON.stringify(updatedStockList));
setStockListData(updatedStockList);

// 새해 모달을 먼저 보여줌
setIsHappyNewYearModal(true);

Expand All @@ -99,8 +99,9 @@ const PlayPage = () => {
const nextYear = (parseInt(yearValue, 10) + 1).toString();
nav(`/game/play/${nextYear}`);
setIsHappyNewYearModal(false);
setCheck(!check);
// window.location.reload();
}, 4000); // 4초 동안 모달을 보여줌
}, 3000); // 4초 동안 모달을 보여줌
}
} catch (error) {
console.error(error);
Expand All @@ -109,24 +110,6 @@ const PlayPage = () => {
}
};

// 새로고침하면 로컬스토리지에서 불러와지도록
useEffect(() => {
const savedData = localStorage.getItem("stockListData");
if (savedData) {
setStockListData(JSON.parse(savedData));
} else if (yearValue === "2014") {
const stock2014 = localStorage.getItem("stock2014");
if (stock2014) {
setStockListData(JSON.parse(stock2014));
} else {
setIsHappyNewYearModal(true);
setTimeout(() => {
setIsHappyNewYearModal(false);
}, 4000);
}
}
}, []);

return (
<Container>
<GameHeader text={year || "Default"} />
Expand Down

0 comments on commit b2a631f

Please sign in to comment.