diff --git a/src/.App.js.swo b/src/.App.js.swo new file mode 100644 index 0000000..4df6e14 Binary files /dev/null and b/src/.App.js.swo differ diff --git a/src/App.js b/src/App.js index 6124681..dabe6cc 100644 --- a/src/App.js +++ b/src/App.js @@ -27,11 +27,13 @@ export default function App() { //로그인 상태 관리하기-------------------------------- useEffect(() => { - // refreshTokenRequest(); - if (accessToken.accessToken !== null) { - history.push('/Waiting'); - } - }, []); + + //refreshTokenRequest() + if(accessToken.accessToken!==null){ + history.push('/Waiting') + } + },[]); + const loginHandler = (data) => { issueAccessToken(data.data.accessToken); history.push('/Waiting'); @@ -44,13 +46,11 @@ export default function App() { //로그 아웃-------------------------------------------------------- const hendleLogout = () => { axios - .get('http://localhost:4000/user/logout', { - headers: { - 'Content-Type': 'application/json', - 'Clear-Site-Data': 'cookies', - }, - }) - .then((res) => {}); + + .get( + 'http://localhost:4000/user/logout', + {withCredentials: true} + ).then((res) => {}) setUserInfo({ id: null, nickname: null, @@ -94,13 +94,18 @@ export default function App() { withCredentials: true, }) .then((res) => { - if (res.data.message !== 'ok') { - } - const { nickname, email, profile_image } = res.data.data.userInfo; - setAccessToken({ accessToken: res.data.data.accessToken }); + + + if (res.data.message !== 'ok') {} + const { nickname, email, profile_image, id,comment } = res.data.data.userInfo; + console.log(res.data.data.accessToken) + setAccessToken({accessToken:res.data.data.accessToken}) + setUserInfo({ + id : id, nickname: nickname, email: email, + comment:comment, profile_image: profile_image, }); }); diff --git a/src/GamePages/InGame.js b/src/GamePages/InGame.js index 1979e0d..fe6f3ab 100644 --- a/src/GamePages/InGame.js +++ b/src/GamePages/InGame.js @@ -49,11 +49,9 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) { }, [locationKeys]); // ! Chat - const socketRef = useRef(); const [state, setState] = useState({ message: '', name: userInfo.nickname }); - // ! App.js 에서 유저이름 name에 넣으면 됨 ! - const [chat, setChat] = useState([]); + // ! App.js 에서 유저이름 name에 넣으면 됨 ! // ! SelectWords const [Word1, SetWord1] = useState(''); @@ -93,37 +91,19 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) { SetIsOpen(false); }; - const renderChat = () => { - return chat.map(({ name, message }, index) => ( -
-

- {name}: {message}{' '} -

-
- )); - }; - - // const onMessageSubmit = (e) => { - // const { name, message } = state; - // socket.current.emit('message', { name, message }); - // e.preventDefault(); - // setState({ message: '', name }); - // }; - const onMessageSubmit = (e) => { e.preventDefault(); const { name, message } = state; - socket.emit('message', { name, message }); + socket.emit('send message', name, message); + setState({ message: '', name }); }; const onTextChange = (e) => { - setState({ ...state, [e.target.name]: e.target.value }); + setState({ ...state, message: e.target.value }); }; const startRound = () => { - // setIsPresenter(false); - // setPresenter({ nickname: '', id: '' }); setWinner([]); setAnswer(''); setIsPresenter(false); @@ -136,22 +116,12 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) { socket.emit('set answer', { answer }); }; - // const endRound = () => { - // socket.emit('end round'); - // }; - //! --------------------------method-------------------------- - useEffect(() => { - socket.on('message', ({ name, message }) => { - if (chat.length > 4) { - return setChat([]); - } - return setChat([...chat, { name, message }]); - }); - }, [chat]); + useEffect(() => { + // * 문제가 선택되면 게임스타트와 문제를 서버에 보내줌 SetAnswer(answer); }, [answer]); @@ -180,35 +150,33 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) { setWinner([...winner, name]); }); - socket.on('show chat', (name, message) => { - setChat([...chat, { name, message }]); - }); + socket.on('renew userlist', (list) => { + console.log('d우ㅠ저소ㅓ켓'); setUserlist([...list]); }); - }); + }, []); + + useEffect(() => { + + socket.on('show chat', (name, message) => { + if (chat.length > 10) { + setChat([...chat.slice(1), { name, message }]); + } else { + setChat([...chat, { name, message }]); + } + }); + }, [state]); useEffect(() => { // * 사용자 정보 소켓으로 불러 오기 - socket.on('my socket id', (data) => {}); let parsedUrl = window.location.href.split('/'); let roomNum = parsedUrl[parsedUrl.length - 1]; socket.emit('send roomNum', roomNum); }, []); - useEffect(() => { - // * 결과창이 열리고 서버에 라운드가 종료메세지 보냄 , 일정 시간이 지나면 결과창 닫히고 다시 게임 시작 - const closeResult = setTimeout(() => { - setResultPopup(false); - setChat([]); - if (presenter.id === userInfo.id) { - startRound(); - } - }, 3000); - }, [resultPopup]); - return ( <> @@ -248,7 +216,6 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) { chat={chat} onTextChange={onTextChange} onMessageSubmit={onMessageSubmit} - renderChat={renderChat} /> diff --git a/src/GamePages/components/Chat.js b/src/GamePages/components/Chat.js index 5aacc20..ac8a4e1 100644 --- a/src/GamePages/components/Chat.js +++ b/src/GamePages/components/Chat.js @@ -1,22 +1,44 @@ import TextField from '@material-ui/core/TextField'; -export default function Chat({ - chat, - onMessageSubmit, - onTextChange, - state, - renderChat, -}) { +export default function Chat({ chat, onMessageSubmit, onTextChange, state }) { + const throttle = (callback, delay) => { + let previousCall = new Date().getTime(); + return function () { + const time = new Date().getTime(); + console.log('실행되니 ????'); + if (time - previousCall >= delay) { + previousCall = time; + callback(); + } + }; + }; + const handleKeyPress = (e) => { + if (e.key === 'Enter') { + onMessageSubmit(e); + } + }; + return (

Chat Log

- {renderChat()} + + {chat.map(({ name, message }, index) => { + return ( +
+

+ {name}: {message} +

+
+ ); + })}
+
- onTextChange(e)} value={state.message} diff --git a/src/GamePages/components/User.js b/src/GamePages/components/User.js index e587b49..d8a3485 100644 --- a/src/GamePages/components/User.js +++ b/src/GamePages/components/User.js @@ -2,6 +2,7 @@ import React from 'react'; import UserPic from '../../images/Character1.png'; export default function User({ users, userInfo }) { + console.log('유저!!', users); return (
    @@ -10,7 +11,7 @@ export default function User({ users, userInfo }) {
    {el.nickname}
    ; })} -
  • + {/*
  • user_profile
    @@ -30,7 +31,7 @@ export default function User({ users, userInfo }) {
  • user_profile
    닉네임 : {userInfo.nickname}
    -
  • + */}
); diff --git a/src/MainPages/main.js b/src/MainPages/main.js index 282597b..9afa09e 100644 --- a/src/MainPages/main.js +++ b/src/MainPages/main.js @@ -23,7 +23,10 @@ export default function Main({ loginHandler, handleGuestLogin }) { const guestLogIn = () => { axios - .get('http://localhost:4000/guest') + .get('http://localhost:4000/guest', + { + withCredentials: true + }) .then((res) => { loginHandler(res.data); history.push('/Waiting'); diff --git a/src/MyPages/MyPage.js b/src/MyPages/MyPage.js index b3604a8..2e0a639 100644 --- a/src/MyPages/MyPage.js +++ b/src/MyPages/MyPage.js @@ -16,7 +16,7 @@ function MyPage({ accessToken, refreshTokenRequest, userInfo }) { const [isPhotoBoxOpen, setIsPhotoBoxOpen] = useState(false); const { nickname, email, profile_image, comment, id } = userInfo; const [PhotoNum, setPhotoNum] = useState(0); - const [nowPhoto, setPhoto] = useState(PhotoData[PhotoNum]); + const [nowPhoto, setPhoto] = useState(PhotoData[profile_image]); const [text, setText] = useState(null); // const emailInputValue = (e) => { diff --git a/src/MyPages/components/ExitBtn.js b/src/MyPages/components/ExitBtn.js index 678f5cd..ca2ca4e 100644 --- a/src/MyPages/components/ExitBtn.js +++ b/src/MyPages/components/ExitBtn.js @@ -1,7 +1,7 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; -export default function ExitBtn({ MyPageSaveData }) { +export default function ExitBtn({ MyPageSaveData, PhotoNum }) { const history = useHistory(); return ( diff --git a/src/MyPages/components/Header.js b/src/MyPages/components/Header.js index c100977..9e9d96a 100644 --- a/src/MyPages/components/Header.js +++ b/src/MyPages/components/Header.js @@ -3,14 +3,14 @@ import React, { useEffect } from 'react'; import ExitBtn from './ExitBtn'; import Complete from './Complete'; -export default function Header({ isOpen, nowPhoto, nickname, MyPageSaveData }) { +export default function Header({ isOpen, nowPhoto, nickname, MyPageSaveData,PhotoNum }) { console.log(nickname); return (

{nickname}님의 마이페이지

- +
); }