Skip to content

Commit 6407b7c

Browse files
committed
로그인 후 bingo 판 생성하고 /bingo로 이동
1 parent 4675a7e commit 6407b7c

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

src/modules/Bingo/BingoContainer.tsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect } from "react";
22
import BingoPresenter from "./BingoPresenter";
3-
import { useLocation } from 'react-router-dom';
3+
import { useLocation } from "react-router-dom";
44
import {
55
getBingoBoard,
66
getSelectedWords,
@@ -10,7 +10,7 @@ import {
1010
singUpUser,
1111
createUserBingoInteraction,
1212
getUserLatestInteraction,
13-
getUserName
13+
getUserName,
1414
} from "../../api/bingo_api.ts";
1515
import {
1616
defafultBingoBoard,
@@ -25,10 +25,9 @@ const useInput = (initialValue: string) => {
2525
return { value, onChange };
2626
};
2727

28-
const BingoContainer = () => {
28+
const BingoContainer = () => {
2929
const location = useLocation();
30-
if (location.search === "?logout")
31-
{
30+
if (location.search === "?logout") {
3231
localStorage.setItem("myWordList", "");
3332
localStorage.setItem("recentWords", "");
3433
localStorage.setItem("recentSendUser", "");
@@ -49,8 +48,12 @@ const BingoContainer = () => {
4948
{ value: string; status: number }[]
5049
>([]);
5150
const [opponentID, setOpponentID] = useState("");
52-
const [recentWords, setRecentWords] = useState(localStorage.getItem("recentWords") || "");
53-
const [recentSendUser, setRecentSendUser] = useState(localStorage.getItem("recentSendUser") || "");
51+
const [recentWords, setRecentWords] = useState(
52+
localStorage.getItem("recentWords") || ""
53+
);
54+
const [recentSendUser, setRecentSendUser] = useState(
55+
localStorage.getItem("recentSendUser") || ""
56+
);
5457
const MyID = useInput(localStorage.getItem("myID") || "");
5558
const [userSelectedWords, setUserSelectedWords] = useState<string[]>([]);
5659
const initBingoBoard = async () => {
@@ -61,24 +64,35 @@ const BingoContainer = () => {
6164
bingoBoard.forEach((item, index) => {
6265
return (boardData[index] = {
6366
value: item.value,
64-
status: [myWord1, myWord2, myWord3, myWord4].includes(item.value) ? 1 : 0,
65-
selected: [myWord1, myWord2, myWord3, myWord4].includes(item.value) ? 1 : 0,
67+
status: [myWord1, myWord2, myWord3, myWord4].includes(item.value)
68+
? 1
69+
: 0,
70+
selected: [myWord1, myWord2, myWord3, myWord4].includes(item.value)
71+
? 1
72+
: 0,
6673
});
6774
});
68-
localStorage.setItem("myWordList", [myWord1, myWord2, myWord3, myWord4].join("|"));
75+
localStorage.setItem(
76+
"myWordList",
77+
[myWord1, myWord2, myWord3, myWord4].join("|")
78+
);
6979

7080
if (MyID.value != "") {
7181
const result = await singUpUser(MyID.value);
72-
if (result === false && !confirm("이미 누군가 사용중인 계정입니다. 정말 로그인하시겠습니까?") && !confirm("정말 로그인하시겠습니까???"))
73-
{
82+
if (
83+
result === false &&
84+
!confirm("이미 누군가 사용중인 계정입니다. 정말 로그인하시겠습니까?") &&
85+
!confirm("정말 로그인하시겠습니까???")
86+
) {
7487
localStorage.setItem("myWordList", "");
7588
localStorage.setItem("recentWords", "");
7689
localStorage.setItem("recentSendUser", "");
7790
localStorage.setItem("myID", "");
78-
return
91+
return;
7992
}
8093

8194
const user = await getUser(MyID.value);
95+
8296
await createBingoBoard(user.user_id, boardData);
8397
}
8498
};
@@ -88,8 +102,10 @@ const BingoContainer = () => {
88102
const userLatestInteraction = await getUserLatestInteraction(user.user_id);
89103

90104
if (userLatestInteraction) {
91-
const sendUserName = await getUserName(userLatestInteraction.send_user_id);
92-
const wordList = userLatestInteraction.word_id_list
105+
const sendUserName = await getUserName(
106+
userLatestInteraction.send_user_id
107+
);
108+
const wordList = userLatestInteraction.word_id_list;
93109
localStorage.setItem("recentWords", wordList);
94110
localStorage.setItem("recentSendUser", sendUserName);
95111
setRecentWords(wordList);
@@ -121,8 +137,7 @@ const BingoContainer = () => {
121137
useEffect(() => {
122138
const fetchData = async () => {
123139
const user = await getUser(MyID.value);
124-
if (user.user_id === null)
125-
return
140+
if (user.user_id === null) return;
126141
const fetchedBingoWords = await getBingoBoard(user.user_id);
127142
const fetchedSelectedWords = await getSelectedWords(user.user_id);
128143
setBingoWords(fetchedBingoWords);

src/modules/Bingo/BingoPresenter.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ import SqaureTextBox from "./components/SqaureTextBox.tsx";
99
import SelectBox from "./components/SelectBox.tsx";
1010
import { defafultBingoBoard } from "./components/DefaultBingoBoard.ts";
1111

12+
const careerOptionsArray = defafultBingoBoard.slice(0, 4);
13+
const careerOptions = careerOptionsArray.map((data) => data.value);
1214

13-
const careerOptionsArray = defafultBingoBoard.slice(0, 4)
14-
const careerOptions = careerOptionsArray.map(data => data.value)
15+
const positionOptionArray = defafultBingoBoard.slice(4, 10);
16+
const positionOption = positionOptionArray.map((data) => data.value);
1517

16-
const positionOptionArray = defafultBingoBoard.slice(4, 10)
17-
const positionOption = positionOptionArray.map(data => data.value)
18-
19-
const pseudolabOptionArray = defafultBingoBoard.slice(10, 14)
20-
const pseudolabOption = pseudolabOptionArray.map(data => data.value)
21-
22-
const talkOptionArray = defafultBingoBoard.slice(14, 20)
23-
const talkOption = talkOptionArray.map(data => data.value)
18+
const pseudolabOptionArray = defafultBingoBoard.slice(10, 14);
19+
const pseudolabOption = pseudolabOptionArray.map((data) => data.value);
2420

21+
const talkOptionArray = defafultBingoBoard.slice(14, 20);
22+
const talkOption = talkOptionArray.map((data) => data.value);
2523

2624
const Wrapper = styled(Container)({
2725
width: "60vw",
@@ -92,7 +90,7 @@ type BingoPresenterProps = {
9290
const BingoPresenter = (props: BingoPresenterProps) => {
9391
return (
9492
<>
95-
{props.userSelectedWords.length === 0 ? (
93+
{props.myID.length === 0 ? (
9694
<Wrapper>
9795
<InputBox
9896
placeholder="나의 닉네임을 입력"
@@ -167,15 +165,15 @@ const BingoPresenter = (props: BingoPresenterProps) => {
167165
draggable // 드래그 가능
168166
pauseOnHover // 마우스를 올리면 알람 정지
169167
theme="light"
170-
// limit={1} // 알람 개수 제한
168+
// limit={1} // 알람 개수 제한
171169
/>
172170
</Wrapper>
173171
) : (
174172
<Wrapper>
175173
<MyInfo>My Id: {props.myID}</MyInfo>
176-
{props.userSelectedWords.map((word) => (
174+
{/* {props.userSelectedWords.map((word) => (
177175
<LongTextBox key={word} text={word} />
178-
))}
176+
))} */}
179177
<RecentSendUserWrapper>
180178
{props.recentSendUser === "" ? (
181179
""
@@ -224,7 +222,7 @@ const BingoPresenter = (props: BingoPresenterProps) => {
224222
draggable // 드래그 가능
225223
pauseOnHover // 마우스를 올리면 알람 정지
226224
theme="light"
227-
// limit={1} // 알람 개수 제한
225+
// limit={1} // 알람 개수 제한
228226
/>
229227
<Button onClick={props.onRefreshBingoWords}>내 빙고판 갱신</Button>
230228
</FormControl>

src/modules/Home/Home.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { toast, ToastContainer } from "react-toastify";
33
import { styled } from "@mui/system";
44
import { useState } from "react";
55
import { SHA256 } from "crypto-js";
6-
import { singUpUser } from "../../api/bingo_api";
6+
import {
7+
singUpUser,
8+
createBingoBoard,
9+
getBingoBoard,
10+
} from "../../api/bingo_api";
711

812
const StyledContainer = styled(Container)({
913
textAlign: "center",
@@ -21,7 +25,7 @@ const Home = () => {
2125
console.log(loginId);
2226
const hash_password = SHA256(password).toString();
2327

24-
const result = singUpUser(loginId, hash_password);
28+
const result = await singUpUser(loginId, hash_password);
2529
if (result.ok === false) {
2630
toast.error(result.message);
2731
localStorage.setItem("myWordList", "");
@@ -30,6 +34,16 @@ const Home = () => {
3034
localStorage.setItem("myID", "");
3135
}
3236
localStorage.setItem("myID", loginId);
37+
38+
const bingoData = await getBingoBoard(loginId);
39+
if (bingoData.length == 0) {
40+
const boardData: {
41+
[key: string]: { value: string; status: number; selected: number };
42+
} = {};
43+
await createBingoBoard(result.user_id, boardData);
44+
}
45+
46+
window.location.href = "/bingo";
3347
};
3448

3549
return (

0 commit comments

Comments
 (0)