Chat.js 1.57 KB
Newer Older
JeongYeonwoo's avatar
JeongYeonwoo committed
1
import React, { useEffect, useState } from 'react';
2
import { Form, Button, Row } from 'react-bootstrap';
JeongYeonwoo's avatar
JeongYeonwoo committed
3
import axios from "axios";
우지원's avatar
ul    
우지원 committed
4
5
6


function Chat(props) {
JeongYeonwoo's avatar
JeongYeonwoo committed
7
8
  const [username, setUsername] = useState('')

9
10
11
12
13
14
15
16
17
18
  function handleChange(e) {
    e.preventDefault()
    props.setInner(e.target.value)
    console.log(e.target.value)
  }

  function sendMsgCH(e) {
    props.sendMsg(e)
  }

JeongYeonwoo's avatar
JeongYeonwoo committed
19
20
21
22
23
24
25
26
27
  async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
    const userid = localStorage.getItem('user')
    const response = await axios.post(`/users/${userid}`, { 'email': userid })
    setUsername(response.data.username)
  }
  useEffect(() => {
    getLoginedUser()
    console.log('Chat에서 useEffect', username)
  })
우지원's avatar
ul    
우지원 committed
28
  return (
JeongYeonwoo's avatar
JeongYeonwoo committed
29

우지원's avatar
ul    
우지원 committed
30
31
    <div className="chat" id="chat" style={{ border: "2px solid", height: "300%", margin: "1%", borderColor: "#BDBDBD" }}>
      <Button variant="light" onClick={props.handleChatc} >{`<`}</Button>
32
33
34
      <h2>현재 {props.roomName} 입니다.</h2>
      {      props.chatmsg.map((value, index) => (
        <Row key={index} className='ml-3'>
JeongYeonwoo's avatar
JeongYeonwoo committed
35
          {props.roomName}에서 {username}님이 보낸 메세지 : {value} 
36
37
38
39
40
41
42
43
        </Row>
      ))}

      <Form onSubmit={sendMsgCH}>
        <Form.Control name='msg' type='text' onChange={handleChange} />
        <Button variant="primary" type="submit">전송</Button>
      </Form>

우지원's avatar
ul    
우지원 committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
      <Form>
        <Form.Group>
          <Form.Control type="text" />
        </Form.Group>
        <Button variant="primary" type="submit">
          전송
        </Button>
      </Form>
    </div>


  );
}

export default Chat;