Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeHeon-Kim committed May 6, 2021
2 parents 0a08d8a + ee463fd commit d926e3a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 85 deletions.
Binary file added src/.App.js.swo
Binary file not shown.
37 changes: 21 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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,
});
});
Expand Down
73 changes: 20 additions & 53 deletions src/GamePages/InGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down Expand Up @@ -93,37 +91,19 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {
SetIsOpen(false);
};

const renderChat = () => {
return chat.map(({ name, message }, index) => (
<div key={index}>
<h3>
{name}: <span>{message}</span>{' '}
</h3>
</div>
));
};

// 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);
Expand All @@ -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]);
Expand Down Expand Up @@ -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 (
<>
<BackBtn />
Expand Down Expand Up @@ -248,7 +216,6 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {
chat={chat}
onTextChange={onTextChange}
onMessageSubmit={onMessageSubmit}
renderChat={renderChat}
/>
</div>

Expand Down
40 changes: 31 additions & 9 deletions src/GamePages/components/Chat.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="card">
<div className="render-chat">
<h1>Chat Log</h1>
{renderChat()}

{chat.map(({ name, message }, index) => {
return (
<div key={index}>
<h3>
{name}: <span>{message}</span>
</h3>
</div>
);
})}
</div>

<form onSubmit={onMessageSubmit}>
<input type="text"></input>
<div className="msgBtn">
<TextField
<input
onKeyPress={handleKeyPress}
name="message"
onChange={(e) => onTextChange(e)}
value={state.message}
Expand Down
5 changes: 3 additions & 2 deletions src/GamePages/components/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import UserPic from '../../images/Character1.png';

export default function User({ users, userInfo }) {
console.log('유저!!', users);
return (
<div className="UserTable">
<ul className="users">
Expand All @@ -10,7 +11,7 @@ export default function User({ users, userInfo }) {
<div className="inGameUserNickName">{el.nickname}</div>
</li>;
})}
<li className="inGameUserProfile">
{/* <li className="inGameUserProfile">
<img className="inGameImg" src={UserPic} alt="user_profile" />
<div>
<div className="inGameUserNickName">
Expand All @@ -30,7 +31,7 @@ export default function User({ users, userInfo }) {
<li className="inGameUserProfile">
<img className="inGameImg" src={UserPic} alt="user_profile" />
<div className="inGameUserNickName">닉네임 : {userInfo.nickname}</div>
</li>
</li> */}
</ul>
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion src/MainPages/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/MyPages/MyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/MyPages/components/ExitBtn.js
Original file line number Diff line number Diff line change
@@ -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 (
<span className="Exit">
Expand Down
4 changes: 2 additions & 2 deletions src/MyPages/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<header className="header">
<h1>{nickname}님의 마이페이지</h1>
<Complete isOpen={isOpen} />
<ExitBtn MyPageSaveData={MyPageSaveData} />
<ExitBtn MyPageSaveData={MyPageSaveData} PhotoNum={PhotoNum}/>
</header>
);
}

0 comments on commit d926e3a

Please sign in to comment.