Skip to content

Commit

Permalink
feature-060: 비디오 삭제 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
gs0428 committed Feb 13, 2024
1 parent aae5f9a commit 932d972
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/apis/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { APIResponse } from '@/models/config/axios';
import { IVideo, VideoVersionType } from '@/models/video';

import axios from './config/instance';
import axiosInstance from './config/instance';

const PREFIX = '/videos';

Expand All @@ -11,3 +12,10 @@ export const getVideoAPI = (
) => {
return axios.get<APIResponse<IVideo>>(PREFIX + `/${videoId}/${versionId}`);
};

export const deleteVideos = async (videos: number[]) => {
const response = await axiosInstance.delete('/videos/selectDelete', {
data: { videos },
});
return response.data;
};
29 changes: 20 additions & 9 deletions src/pages/CategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useRecoilValue } from 'recoil';
import { categoryState } from '@/stores/category';
import { ISubFolderProps } from 'types/category';
import EmptyCard from '@/components/category/EmptyCard';
import { deleteVideos } from '@/apis/videos';

const CategoryPage = () => {
const params = useParams();
Expand Down Expand Up @@ -46,11 +47,22 @@ const CategoryPage = () => {
}
}, [categories, params.top_folder]);

const allCheckBtnHandler = () => {
if (checkedVideos.length === videos.length) {
// 삭제 API 요청
console.log('모두 삭제');
const handleDeleteVideos = async () => {
const res = await deleteVideos(checkedVideos);
if (res.isSuccess) {
const existVideos = videos.filter(
(video) => !checkedVideos.includes(video.video_id),
);
setVideos(existVideos);
setCheckedVideos([]);
} else {
alert('비디오를 삭제하는데 실패했습니다.');
}
};

const allCheckBtnHandler = async () => {
if (checkedVideos.length === videos.length) {
handleDeleteVideos();
} else {
console.log('모두 선택');
setCheckedVideos(videos.map((video) => video.video_id));
Expand All @@ -60,10 +72,7 @@ const CategoryPage = () => {
const dirMoveHanlder = () => {
console.log(checkedVideos);
};

const garbageHandler = () => {
console.log(checkedVideos);
};
console.log(videos);

return (
<CategoryPageStyles.Container>
Expand All @@ -90,7 +99,9 @@ const CategoryPage = () => {
<CategoryPageStyles.ManagementBoxGray onClick={dirMoveHanlder}>
<FolderSvg width={28} height={28} />
</CategoryPageStyles.ManagementBoxGray>
<CategoryPageStyles.ManagementBoxGray onClick={garbageHandler}>
<CategoryPageStyles.ManagementBoxGray
onClick={handleDeleteVideos}
>
<GarbageSvg width={28} height={28} />
</CategoryPageStyles.ManagementBoxGray>
<CategoryPageStyles.ManagementBox>
Expand Down

0 comments on commit 932d972

Please sign in to comment.