Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #101

Merged
merged 3 commits into from
May 6, 2021
Merged

Dev #101

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/.App.js.swo
Binary file not shown.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function App() {

//로그인 상태 관리하기--------------------------------
useEffect(() => {
refreshTokenRequest();
// refreshTokenRequest();
if (accessToken.accessToken !== null) {
history.push('/Waiting');
}
Expand Down
29 changes: 6 additions & 23 deletions src/GamePages/InGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,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 @@ -94,16 +92,6 @@ 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 });
Expand All @@ -115,6 +103,8 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {
e.preventDefault();
const { name, message } = state;
socket.emit('send message', name, message);
// socket.emit('send message', name, message);

setState({ message: '', name });
};

Expand Down Expand Up @@ -145,10 +135,7 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {

// useEffect(() => {
// socket.on('message', ({ name, message }) => {
// if (chat.length > 4) {
// return setChat([]);
// }
// return setChat([...chat, { name, message }]);
// setChat([...chat, { name, message }]);
// });
// console.log('채팅이야!!!!!', chat);
// }, [chat]);
Expand Down Expand Up @@ -183,8 +170,8 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {
});

socket.on('show chat', (name, message) => {
console.log(message);
setChat([...chat, { name, message }]);
console.log('너니 ?????', message);
setChat(chat.concat([{ name, message }]));
});

socket.on('renew userlist', (list) => {
Expand All @@ -194,9 +181,6 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {

useEffect(() => {
// * 사용자 정보 소켓으로 불러 오기
socket.on('my socket id', (data) => {
console.log('mySocketID : ', data);
});

let parsedUrl = window.location.href.split('/');
let roomNum = parsedUrl[parsedUrl.length - 1];
Expand Down Expand Up @@ -253,7 +237,6 @@ export default function InGame({ accessToken, isLogIn, loginCheck, userInfo }) {
chat={chat}
onTextChange={onTextChange}
onMessageSubmit={onMessageSubmit}
renderChat={renderChat}
/>
</div>

Expand Down
39 changes: 30 additions & 9 deletions src/GamePages/components/Chat.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
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
1 change: 0 additions & 1 deletion src/GamePages/components/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import UserPic from '../../images/Character1.png';

export default function User({ users, userInfo }) {
console.log(userInfo);
return (
<div className="UserTable">
<ul className="users">
Expand Down
1 change: 1 addition & 0 deletions src/MyPages/MyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
import { withRouter } from 'react-router-dom';
import SearchUser from './components/SearchUser';
import Header from './components/Header';
import axios from 'axios';
import ChangePsw from './components/ChangePsw';
import Character1 from '../images/Character1.png';
import Character2 from '../images/Character2.png';
Expand Down