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) => {
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;
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 catchErrors from '../context/catchError'
import { handleLogin } from '../context/auth'
......@@ -46,7 +46,7 @@ const Login = () => {
}
if (success) {
alert('로그인 되었습니다')
window.location.href = `/user/${id}`
return <Redirect to={`/user/${id}`} />;
}
const { email, password } = user
......
import { useState } from 'react'
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 { 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('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 (
<div>
<div className="overflow-auto" style={{ height: '610px' }}>
......@@ -13,6 +64,7 @@ const ChannelSingle = (props) => {
<div
className="m-3 p-1 row"
style={{ backgroundColor: '#E0CEE8' }}
onClick={() => joinChannel(el.channelName)}
>
{el.channelName === channelId ? (
<img
......@@ -35,8 +87,8 @@ const ChannelSingle = (props) => {
</div>
</Link>
{el.joinName &&
el.joinName.map((e) => (
{el.joinUser &&
el.joinUser.map((e) => (
<div>
<ul className="mx-5" style={{ color: '#76D079' }}>
<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 = {
const INIT_CHANNEL = {
channelName: "",
joinName: [],
joinUser: [],
};
const RightHamburger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]);
......@@ -53,7 +53,7 @@ const RightHamburger = () => {
console.log(Channel[prop][key]);
channelList.push({
channelName: key,
joinName: Channel[prop][key],
joinUser: Channel[prop][key],
});
}
}
......
......@@ -9,7 +9,7 @@ const INIT_ROOM = {
const RoomHeader = () => {
const {roomId}=useParams();
const {roomId, channelId}=useParams();
const [room, setRoom] = useState([INIT_ROOM]);
const [error, setError] = useState("")
async function getRoom(Id) {
......@@ -47,7 +47,7 @@ const RoomHeader = () => {
color: '#6c33a2',
}}
>
# 회의
# {channelId}
</a>
</div>
</div>
......
......@@ -61,7 +61,7 @@ const Signup = () => {
if (success) {
alert('회원가입이 완료되었습니다!')
window.location.href = '/'
return <Redirect to="/" />;
}
const { name, id, password, checkpw, phone } = user
......
......@@ -107,18 +107,32 @@ const exitRoom = async (req, res) => {
const room = await Room.findOne({ where: { id: roomId } });
console.log(room.member)
const index = room.member.indexOf(id)
console.log('index',index)
room.member.splice(index,1)
console.log('index', index)
room.member.splice(index, 1)
await Room.update({ member: room.member }, { where: { id: roomId } });
const user = await User.findOne({ where: { id: id } });
console.log(user.roomNumber)
const index2 = user.roomNumber.indexOf(id)
console.log('index',index2)
user.roomNumber.splice(index2,1)
console.log('index', index2)
user.roomNumber.splice(index2, 1)
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 {
joinRoom, roomImgUpload, createRoom, getRoom, exitRoom,
joinRoom, roomImgUpload, createRoom, getRoom, exitRoom, joinChannel, makeChannel,
};
......@@ -23,21 +23,21 @@ sequelize
roomNumber : ["1234567abc","abc7654321"],
});
// await Room.create({
// id: "1234567abc",
// name: "room",
// owner: 8888,
// member: [8888],
// profileimg: "defaultimg",
// });
await Room.create({
id: "1234567abc",
name: "room",
owner: 8888,
member: ['8888','9999'],
profileimg: "23bf0d83f161b5bf066f0a81beeb4e78",
});
// await Room.create({
// id: "abc7654321",
// name: "room1",
// owner: 9999,
// member: [9999],
// profileimg: "defaultimg",
// });
await Room.create({
id: "abc7654321",
name: "room1",
owner: 9999,
member: ['9999'],
profileimg: "23bf0d83f161b5bf066f0a81beeb4e78",
});
app.listen(appConfig.port, () => {
console.log(`Server is running on port ${appConfig.port}`);
......
......@@ -17,11 +17,10 @@ const RoomModel = (sequelize) => {
},
member: {
type: DataTypes.ARRAY(DataTypes.STRING),
//type: DataTypes.STRING,
},
profileimg: {
type: DataTypes.STRING,
defaultValue: "defaultimg"
// defaultValue: "defaultimg"
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
......
......@@ -6,5 +6,7 @@ router.route("/getRoom").post(roomCrtl.getRoom);
router.route("/exitRoom/:id/:roomId").delete(roomCrtl.exitRoom);
router.route("/create").post(roomCrtl.roomImgUpload, roomCrtl.createRoom);
router.route("/join").put(roomCrtl.joinRoom);
router.route("/joinChannel").post(roomCrtl.joinChannel);
router.route("/makeChannel").post(roomCrtl.makeChannel);
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