Commit cfe0f96b authored by seoyeon's avatar seoyeon
Browse files

Merge remote-tracking branch 'origin/woojiweon2' into seoyeon3

parents 6aeb3ac5 b9acab65
...@@ -20,6 +20,16 @@ const join = async (payload) => { ...@@ -20,6 +20,16 @@ const join = async (payload) => {
return data; return data;
}; };
const roomApi = { getRoom, exitRoom, create, join }; const joinChannel = async (payload) => {
const { data } = await axios.post("/api/room/joinChannel", payload);
return data;
};
const makeChannel = async (payload) => {
const { data } = await axios.post("/api/room/makeChannel", payload);
return data;
};
const roomApi = { getRoom, exitRoom, create, join, joinChannel, makeChannel };
export default roomApi; export default roomApi;
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom' import { Link, Redirect } from 'react-router-dom'
import userApi from '../apis/user.api' import userApi from '../apis/user.api'
import catchErrors from '../context/catchError' import catchErrors from '../context/catchError'
import { handleLogin } from '../context/auth' import { handleLogin } from '../context/auth'
...@@ -46,7 +46,7 @@ const Login = () => { ...@@ -46,7 +46,7 @@ const Login = () => {
} }
if (success) { if (success) {
alert('로그인 되었습니다') alert('로그인 되었습니다')
window.location.href = `/user/${id}` return <Redirect to={`/user/${id}`} />;
} }
const { email, password } = user const { email, password } = user
......
import { useState } from 'react'
import { Link, useParams } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import roomApi from '../../apis/room.api';
import userApi from '../../apis/user.api'
import catchErrors from "../../context/catchError";
const ChannelSingle = (props) => { const ChannelSingle = (props) => {
const { roomId, channelId } = useParams() const [error, setError] = useState("");
const [success, setSuccess] = useState(false);
const [roomName, setRoomName] = useState('');
const { roomId, channelId } = useParams();
console.log('props', props.channel) console.log('props', props.channel)
console.log('hi', channelId) console.log('hi', channelId)
const userId = localStorage.getItem('user')
async function joinChannel(e) {
console.log(e, userId)
try {
const data = await userApi.getUser(userId);
const el = indexCheck(e)
console.log(el)
const mem = props.channel[el].joinUser
console.log(mem)
const joinCh = mem.includes(data.name);
console.log(joinCh)
if (!joinCh) {
const roomA = await roomApi.joinChannel({ roomId: roomId, channelName: e, plusUser: data.name, index: el })
console.log(roomA)
setRoomName(e)
setSuccess(true)
} else {
alert('이미 참여된 채널입니다.')
}
} catch (error) {
catchErrors(error, setError);
}
}
console.log('정보들어왔나', roomName, success)
function indexCheck(e) {
for (const el in props.channel) {
console.log('체크', props.channel[el].channelName, e)
console.log('체크', props.channel[el].channelName === e)
if (props.channel[el].channelName === e) {
console.log('el', el)
return el
}
}
}
if (success) {
alert(`${roomName} 채널에 참가되었습니다.`)
window.location.href = `/room/${roomId}/${roomName}`
}
return ( return (
<div> <div>
<div className="overflow-auto" style={{ height: '610px' }}> <div className="overflow-auto" style={{ height: '610px' }}>
...@@ -13,6 +64,7 @@ const ChannelSingle = (props) => { ...@@ -13,6 +64,7 @@ const ChannelSingle = (props) => {
<div <div
className="m-3 p-1 row" className="m-3 p-1 row"
style={{ backgroundColor: '#E0CEE8' }} style={{ backgroundColor: '#E0CEE8' }}
onClick={() => joinChannel(el.channelName)}
> >
{el.channelName === channelId ? ( {el.channelName === channelId ? (
<img <img
...@@ -35,8 +87,8 @@ const ChannelSingle = (props) => { ...@@ -35,8 +87,8 @@ const ChannelSingle = (props) => {
</div> </div>
</Link> </Link>
{el.joinName && {el.joinUser &&
el.joinName.map((e) => ( el.joinUser.map((e) => (
<div> <div>
<ul className="mx-5" style={{ color: '#76D079' }}> <ul className="mx-5" style={{ color: '#76D079' }}>
<li> <li>
......
import { useState } from "react";
import { useParams } from "react-router-dom";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const MakeChannel = () => {
const { roomId } = useParams();
const [channelName, setChannelName] = useState("");
const [error, setError] = useState("");
const [success, setSuccess] = useState(false);
function handleChange(event) {
const { value } = event.target;
setChannelName(value);
}
console.log(channelName)
async function handleSubmit(e) {
// e.preventDefault();
try {
const data = await roomApi.makeChannel({ roomId: roomId, channelName: channelName });
console.log('서버연결됬나요', data)
setSuccess(true);
} catch (error) {
catchErrors(error, setError);
} finally {
// setLoading(false);
}
}
if (success) {
// console.log('success', success)
alert('채널생성이 완료되었습니다!')
window.location.href = `/room/${roomId}/${channelName}`
}
return (
<div className="modal-content">
<form
onSubmit={handleSubmit}
>
<div className="modal-header">
<div className="modal-title" id="MakeChannelModal">
채널 생성하기
</div>
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div className="modal-body">
{error && <div className="alert alert-danger">{error}</div>}
<div className="input-group mb-3">
<input
type="text"
className="form-control"
placeholder="생성할 채널이름을 입력하세요"
aria-label="생성할 채널이름을 입력하세요"
aria-describedby="basic-addon1"
name="channelName"
// value={channelName}
onChange={handleChange}
/>
</div>
<div className="modal-footer">
<button
type="submit"
className="btn btn-primary">
확인
</button>
</div>
</div>
</form>
</div>
);
};
export default MakeChannel;
...@@ -10,7 +10,7 @@ const INIT_ROOM = { ...@@ -10,7 +10,7 @@ const INIT_ROOM = {
const INIT_CHANNEL = { const INIT_CHANNEL = {
channelName: "", channelName: "",
joinName: [], joinUser: [],
}; };
const RightHamburger = () => { const RightHamburger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]); const [channel, setChannel] = useState([INIT_CHANNEL]);
...@@ -53,7 +53,7 @@ const RightHamburger = () => { ...@@ -53,7 +53,7 @@ const RightHamburger = () => {
console.log(Channel[prop][key]); console.log(Channel[prop][key]);
channelList.push({ channelList.push({
channelName: key, channelName: key,
joinName: Channel[prop][key], joinUser: Channel[prop][key],
}); });
} }
} }
......
...@@ -9,7 +9,7 @@ const INIT_ROOM = { ...@@ -9,7 +9,7 @@ const INIT_ROOM = {
const RoomHeader = () => { const RoomHeader = () => {
const {roomId}=useParams(); const {roomId, channelId}=useParams();
const [room, setRoom] = useState([INIT_ROOM]); const [room, setRoom] = useState([INIT_ROOM]);
const [error, setError] = useState("") const [error, setError] = useState("")
async function getRoom(Id) { async function getRoom(Id) {
...@@ -47,7 +47,7 @@ const RoomHeader = () => { ...@@ -47,7 +47,7 @@ const RoomHeader = () => {
color: '#6c33a2', color: '#6c33a2',
}} }}
> >
# 회의 # {channelId}
</a> </a>
</div> </div>
</div> </div>
......
...@@ -61,7 +61,7 @@ const Signup = () => { ...@@ -61,7 +61,7 @@ const Signup = () => {
if (success) { if (success) {
alert('회원가입이 완료되었습니다!') alert('회원가입이 완료되었습니다!')
window.location.href = '/' return <Redirect to="/" />;
} }
const { name, id, password, checkpw, phone } = user const { name, id, password, checkpw, phone } = user
......
...@@ -107,18 +107,32 @@ const exitRoom = async (req, res) => { ...@@ -107,18 +107,32 @@ const exitRoom = async (req, res) => {
const room = await Room.findOne({ where: { id: roomId } }); const room = await Room.findOne({ where: { id: roomId } });
console.log(room.member) console.log(room.member)
const index = room.member.indexOf(id) const index = room.member.indexOf(id)
console.log('index',index) console.log('index', index)
room.member.splice(index,1) room.member.splice(index, 1)
await Room.update({ member: room.member }, { where: { id: roomId } }); await Room.update({ member: room.member }, { where: { id: roomId } });
const user = await User.findOne({ where: { id: id } }); const user = await User.findOne({ where: { id: id } });
console.log(user.roomNumber) console.log(user.roomNumber)
const index2 = user.roomNumber.indexOf(id) const index2 = user.roomNumber.indexOf(id)
console.log('index',index2) console.log('index', index2)
user.roomNumber.splice(index2,1) user.roomNumber.splice(index2, 1)
await User.update({ roomNumber: user.roomNumber }, { where: { id: id } }); await User.update({ roomNumber: user.roomNumber }, { where: { id: id } });
} }
const joinChannel = async (req, res) => {
const { roomId, channelName, plusUser, index } = req.body
const room = await Room.findOne({ where: { id: roomId } });
room.channel[index][channelName].push(plusUser)
console.log('확인2',room.channel[index])
await Room.update({ channel: room.channel }, { where: { id: roomId } });
return res.json(true)
}
const makeChannel = async (req, res) => {
const { roomId, channelName } = req.body
console.log(roomId, channelName)
}
export default { export default {
joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, joinChannel, makeChannel,
}; };
...@@ -23,21 +23,21 @@ sequelize ...@@ -23,21 +23,21 @@ sequelize
roomNumber : ["1234567abc","abc7654321"], roomNumber : ["1234567abc","abc7654321"],
}); });
// await Room.create({ await Room.create({
// id: "1234567abc", id: "1234567abc",
// name: "room", name: "room",
// owner: 8888, owner: 8888,
// member: [8888], member: ['8888','9999'],
// profileimg: "defaultimg", profileimg: "23bf0d83f161b5bf066f0a81beeb4e78",
// }); });
// await Room.create({ await Room.create({
// id: "abc7654321", id: "abc7654321",
// name: "room1", name: "room1",
// owner: 9999, owner: 9999,
// member: [9999], member: ['9999'],
// profileimg: "defaultimg", profileimg: "23bf0d83f161b5bf066f0a81beeb4e78",
// }); });
app.listen(appConfig.port, () => { app.listen(appConfig.port, () => {
console.log(`Server is running on port ${appConfig.port}`); console.log(`Server is running on port ${appConfig.port}`);
......
...@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => { ...@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
}, },
member: { member: {
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
//type: DataTypes.STRING,
}, },
profileimg: { profileimg: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: "defaultimg" // defaultValue: "defaultimg"
}, },
channel: { channel: {
type: DataTypes.ARRAY(DataTypes.JSON), type: DataTypes.ARRAY(DataTypes.JSON),
......
...@@ -6,5 +6,7 @@ router.route("/getRoom").post(roomCrtl.getRoom); ...@@ -6,5 +6,7 @@ router.route("/getRoom").post(roomCrtl.getRoom);
router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom); router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom);
router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom); router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom);
router.route("/join").put(roomCrtl.joinRoom); router.route("/join").put(roomCrtl.joinRoom);
router.route("/joinChannel").post(roomCrtl.joinChannel);
router.route("/makeChannel").post(roomCrtl.makeChannel);
export default router; export default router;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment