11import { useState , useEffect } from "react" ;
22import BingoPresenter from "./BingoPresenter" ;
3- import { useLocation } from ' react-router-dom' ;
3+ import { useLocation } from " react-router-dom" ;
44import {
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" ;
1515import {
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 ) ;
0 commit comments