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}
+
+
+ );
+ })}