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

영상통화 기능 구현 #31

Merged
merged 29 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6dc8cd9
move: useShallow 훅 이동
MinKonKim Jul 26, 2024
9e8c83b
feat: 채널생성 페이지
MinKonKim Jul 26, 2024
5aa6fc0
feat: 유저 목록 출력
MinKonKim Jul 26, 2024
19d5eec
feat: userChannel 커스텀 훅
MinKonKim Jul 26, 2024
8423075
fix: 오탈자 수정
MinKonKim Jul 27, 2024
a2bbf60
update: supabse type 업데이트
MinKonKim Jul 27, 2024
c027da5
fix : 오탈자 수정
MinKonKim Jul 27, 2024
68bc226
feat: 화면공유 레이아웃 수정
MinKonKim Jul 27, 2024
ee1719d
merge : 브랜치 최신화
MinKonKim Jul 27, 2024
b700fc9
merge: branch 최신화
MinKonKim Jul 27, 2024
db958c4
update: 타입 임포트 수정
MinKonKim Jul 27, 2024
35d4888
merge: 병합 후 , 안맞는 부분 수정
MinKonKim Jul 27, 2024
f123af6
remove: 겹치는 부분 삭제
MinKonKim Jul 28, 2024
f8de463
fix : 겹치는 부분 합침.
MinKonKim Jul 28, 2024
9daef90
fix : 화상통화 필요없는 코드 수정
MinKonKim Jul 28, 2024
cab7c61
feature: 화상회의방 셋팅 전역에서 관리.
MinKonKim Jul 28, 2024
392b1b5
update: supabase 타입 변환
MinKonKim Jul 28, 2024
dadeb94
fix : 필요없는 코드 삭제
MinKonKim Jul 28, 2024
07ea72a
fix: build 에러 수정
MinKonKim Jul 28, 2024
0272273
merge: 브랜치 최신화
MinKonKim Jul 28, 2024
057b076
merge: 최적화.
MinKonKim Jul 28, 2024
c157882
merge: 빌드오류해결
MinKonKim Jul 28, 2024
b7adf1f
fix: 에러 수정
MinKonKim Jul 28, 2024
6ea4857
fix : channelAPI 이름 수정
MinKonKim Jul 29, 2024
204687d
fix: 대소문자 오류 수정
1eeyerin Jul 29, 2024
72f7ba9
fix: 중복 파일 삭제
1eeyerin Jul 29, 2024
faad8f1
fix: 대소문자 파일 중복 제거
1eeyerin Jul 29, 2024
3257db3
fix: 중복 파일 삭제
1eeyerin Jul 29, 2024
b42c1a3
fix: 대소문자 수정
1eeyerin Jul 29, 2024
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
Prev Previous commit
Next Next commit
fix: 오탈자 수정
  • Loading branch information
MinKonKim committed Jul 27, 2024
commit 8423075f90345b5e8c819247f18917a446b106c8
6 changes: 3 additions & 3 deletions src/api/channelUserAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tables } from '@/types/supabase';
import { InsertChannelUserType } from '@/types/channeluser';
import { AxiosInstance } from 'axios';

class ChannelUserAPI {
Expand All @@ -8,15 +8,15 @@ class ChannelUserAPI {
this.axios = axios;
}

async getChannelUserList(channel_id: number): Promise<Tables<'channel_user'>> {
async getChannelUserList(channel_id: number): Promise<InsertChannelUserType> {
const response = await this.axios.get(this.path, {
params: { channel_id }
});

return response.data;
}

async postChannelUser(row: Tables<'channel_user'>) {
async postChannelUser(row: InsertChannelUserType) {
const response = await this.axios.post(this.path, row);
return response.data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import useChannel from '@/hooks/useChannel';
import { useRouter } from 'next/navigation';
import VideoListItem from '../VideoListItem';

// 해당 파일은 임시 파일 입니다.
const VideoList = () => {
// 전역으로 관리 되어야 할듯
const workspace_id = 2;
const userName = 'minkon';

const router = useRouter();
const { channelList } = useChannel('video', workspace_id);

if (!channelList) {
return <div>목록이 없습니다..</div>;
}
const handleSubmit = (e: MouseEvent, roomName: string) => {
e.preventDefault();

// TODO: DB에 방 추가 하는 로직 작성 해야함.
if (roomName && userName) {
router.push(`/video-channel/${roomName}?username=${userName}`);
} else {
alert('방이름과 사용자 이름을 입력해 주세요.');
}
};
return (
<div className="m-5">
{channelList.map((channel) => (
Expand Down
60 changes: 50 additions & 10 deletions src/app/(providers)/(root)/video-channel/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
'use client';
import useChannel from '@/hooks/useChannel';
import useChannelUser from '@/hooks/useChannelUser';
import useWorkspaceUserList from '@/hooks/useWorkspaceUserList';
import { ChannelInsertType } from '@/types/channel';
import { Tables } from '@/types/supabase';
import { useRouter } from 'next/navigation';
import { useState } from 'react';

const FAKE_WORKSPACE_ID = 2;

// 임시 파일
type WorkspaceUserType = Tables<'workspace_user'>;

const CreateChannelPage = () => {
const userName = 'minkon';
const router = useRouter();

const { workspaceUserList } = useWorkspaceUserList(FAKE_WORKSPACE_ID);
const [selectedUserList, setSelectedUserList] = useState<string[]>([]);
const { createChannel } = useChannel('video', FAKE_WORKSPACE_ID);
const [selectedUserList, setSelectedUserList] = useState<WorkspaceUserType[]>([]);

const handleSelectUser = (user_id: string) => {
setSelectedUserList((prev) => [...selectedUserList!, user_id]);
const handleSelectUser = (user: WorkspaceUserType) => {
setSelectedUserList((prev) => [...selectedUserList!, user]);
};
const handleSubmit = async (roomName: string) => {
const newChannel: ChannelInsertType = {
name: roomName,
type: 'video',
workspace_id: FAKE_WORKSPACE_ID
};

const channel = await createChannel(newChannel); // 생성된 채널 정보 가져오기

// [utils]
console.log('생성된 채널 정보 : ', channel);
selectedUserList.forEach((user) => {
const { enterChannel } = useChannelUser(channel[0].channel_id, user.id);
enterChannel(user.user_id);
});

if (roomName) {
router.push(`/video-channel/${roomName}?username=${userName}`);
} else {
alert('방이름과 사용자 이름을 입력해 주세요.');
}
};
// [utils] : 방 이름 작성
const makeRoomName = () => {
return selectedUserList.join(',');
let roomName = '';
for (let i = 0; i < selectedUserList.length; i++) {
if (i !== 0) {
roomName += `,${selectedUserList[i]}`;
} else {
roomName + selectedUserList[i];
}
}
return roomName;
};

return (
<div>
<div className="flex gap-5 p-5">
<p>{makeRoomName()}</p>
<button className="border hover:brightness-90">확인</button>
<button onClick={() => handleSubmit(makeRoomName())} className="border hover:brightness-90">
확인
</button>
</div>
{workspaceUserList &&
workspaceUserList.map((wokespaceUser) => (
<div key={wokespaceUser.id} onClick={() => handleSelectUser(wokespaceUser.name as string)}>
<div key={wokespaceUser.id} onClick={() => handleSelectUser(wokespaceUser)}>
<UserItem {...wokespaceUser} />
</div>
))}
Expand All @@ -40,7 +80,7 @@ type UserItemProps = Tables<'workspace_user'>;
const UserItem = ({ ...wokespaceUser }: UserItemProps) => {
return (
<div className="bg-red-100 hover:brightness-90 p-5">
<p>{wokespaceUser.name}</p>
<p>{wokespaceUser.user_id}</p>
</div>
);
};
6 changes: 3 additions & 3 deletions src/app/api/channel/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const GET = async (request: NextRequest) => {
try {
const { data, error } = await supabase
.from('channel')
.select()
.select('*')
.eq('type', type!)
.eq('workspace_id', workspace_id!)
.order('created_at', { ascending: true });
Expand All @@ -39,7 +39,7 @@ export const POST = async (request: NextRequest) => {

const { name, type, workspace_id } = await request.json();
try {
const { error } = await supabase.from('channel').insert({ name, type, workspace_id });
const { data, error } = await supabase.from('channel').insert({ name, type, workspace_id }).select('*');

if (error)
return NextResponse.json({
Expand All @@ -48,7 +48,7 @@ export const POST = async (request: NextRequest) => {
status: false,
statusCode: 500
});
return NextResponse.json({ message: 'Create Channel' });
return NextResponse.json(data);
} catch (error) {
return NextResponse.json({
message: 'Failed to insert data',
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useChannel = (type: 'chat' | 'video', workspace_id: number) => {
queryFn: () => api.channel.getChannelList(type, workspace_id)
});

const { mutateAsync: addChannel } = useMutation({
const { mutateAsync: createChannel } = useMutation({
mutationFn: (channel: ChannelInsertType) => api.channel.postChannel(channel),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['channel'] });
Expand All @@ -29,7 +29,7 @@ const useChannel = (type: 'chat' | 'video', workspace_id: number) => {
}
});

return { channelList, isPending, isError, addChannel, delChannel };
return { channelList, isPending, isError, createChannel, delChannel };
};

export default useChannel;
9 changes: 5 additions & 4 deletions src/hooks/useChannelUser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import api from '@/api/api';
import { Tables } from '@/types/supabase';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';

const useChannel = (channel_id: number, workspace_user_id?: string) => {
const useChannelUser = (channel_id: number, workspace_user_id: string) => {
const queryClient = useQueryClient();
const {
data: channelUser,
Expand All @@ -14,18 +13,20 @@ const useChannel = (channel_id: number, workspace_user_id?: string) => {
});

const { mutateAsync: enterChannel } = useMutation({
mutationFn: (row: Tables<'channel_user'>) => api.channelUser.postChannelUser(row),
mutationFn: (user_id: string) => api.channelUser.postChannelUser({ user_id, channel_id, workspace_user_id }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['channelUser', channel_id] });
}
});

const { mutateAsync: leaveChannel } = useMutation({
mutationFn: (row: Tables<'channel_user'>) => api.channelUser.deleteChannelUser(channel_id, workspace_user_id!),
mutationFn: () => api.channelUser.deleteChannelUser(channel_id, workspace_user_id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['channelUser', channel_id] });
}
});

return { channelUser, isPending, isError, enterChannel, leaveChannel };
};

export default useChannelUser;
8 changes: 8 additions & 0 deletions src/types/channeluser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type InsertChannelUserType = {
channel_id: number;
created_at?: string;
id?: number;
last_read_chat_id?: number | null;
user_id: string;
workspace_user_id?: string | null;
};