Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

[FE] feat: 카테고리 및 글 드래그앤드롭 기능 구현 #418

Merged
merged 25 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
19497a7
refactor: 카테고리 데이터가 null 인 경우 early return
nangkyeonglim Sep 12, 2023
543cb3b
feat: 글 및 카테고리 순서 수정 API, 훅 작성
nangkyeonglim Sep 16, 2023
27b6e00
feat: 타입 가드 유틸 함수 구현
nangkyeonglim Sep 16, 2023
d0f32bc
feat: 글 및 카테고리 순서 수정 API mocking
nangkyeonglim Sep 16, 2023
3a8269b
feat: 카테고리에 스크롤이 생길 때 `Header`가 고정되도록 수정
nangkyeonglim Sep 16, 2023
925a694
feat: 스크롤이 있을 때 카테고리 추가 시 맨 아래로 스크롤 되는 기능 구현
nangkyeonglim Sep 16, 2023
bd56b74
design: 카테고리 및 글 hover시 색상 변경
nangkyeonglim Sep 16, 2023
8d6cfe0
feat: `throttle` 유틸 함수 구현
nangkyeonglim Sep 16, 2023
1d007d3
feat: 같은 배열인지 확인하는 유틸 함수 작성
nangkyeonglim Sep 16, 2023
82c9fc2
feat: useDragAndDrop 훅 작성
nangkyeonglim Sep 16, 2023
eace190
feat: 카테고리 드래그 앤 드롭 구현
nangkyeonglim Sep 16, 2023
1d30e31
feat: 글 드래그 앤 드롭 구현
nangkyeonglim Sep 16, 2023
3dc15b3
feat: 드래그 영역 확장 및 throttle 적용
nangkyeonglim Sep 16, 2023
efb4468
refactor: `useDragAndDrop` 훅 파일 이동
nangkyeonglim Sep 16, 2023
16e602c
fix: dragEnd 시 버블링으로 인해 2번 API 요청 되는 현상 수정
nangkyeonglim Sep 19, 2023
fea808c
refactor: 카테고리 순서 변경 시 테이블 페이지의 글을 받아오는 쿼리 무효화 제거
nangkyeonglim Sep 19, 2023
5f4d2a4
refactor: 드래그 종류 확인 함수를 값으로 변경하고 네이밍 수정
nangkyeonglim Sep 19, 2023
7df8f3c
refactor: 마지막 드래그 영역 아이디 상수화
nangkyeonglim Sep 19, 2023
354e868
refactor: 드래그 영역 색 상수화
nangkyeonglim Sep 19, 2023
cb5f0bc
docs: 동작 이해를 위한 주석 추가
nangkyeonglim Sep 19, 2023
c24e73b
refactor: 기본 카테고리 id 로컬스토리지에서 받아오도록 변경
nangkyeonglim Sep 19, 2023
6db984a
refactor: `decideDraggingTarget` 조건문 분리
nangkyeonglim Sep 19, 2023
0baaa73
refactor: `handleDragStart` 버블링 막는 조건문 변경
nangkyeonglim Sep 19, 2023
56c03f6
refactor: 드래그 위치 인덱스 상수화
nangkyeonglim Sep 19, 2023
2939b6f
refactor: 드래그 불가한 조건문 명확하게 변경
nangkyeonglim Sep 20, 2023
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
11 changes: 8 additions & 3 deletions frontend/src/apis/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
AddCategoriesRequest,
GetCategoriesResponse,
GetCategoryDetailResponse,
PatchCategoryArgs,
UpdateCategoryOrderArgs,
UpdateCategoryTitleArgs,
} from 'types/apis/category';

// POST: 카테고리 추가
Expand All @@ -17,8 +18,12 @@ export const getCategories = (): Promise<GetCategoriesResponse> => http.get(cate
export const getWritingsInCategory = (categoryId: number): Promise<GetCategoryDetailResponse> =>
http.get(`${categoryURL}/${categoryId}`);

// PATCH: 카테고리 수정
export const patchCategory = ({ categoryId, body }: PatchCategoryArgs) =>
// PATCH: 카테고리 이름 수정
export const updateCategoryTitle = ({ categoryId, body }: UpdateCategoryTitleArgs) =>
http.patch(`${categoryURL}/${categoryId}`, { json: body });

// PATCH: 카테고리 순서 수정
export const updateCategoryOrder = ({ categoryId, body }: UpdateCategoryOrderArgs) =>
http.patch(`${categoryURL}/${categoryId}`, { json: body });

// DELETE: 카테고리 삭제
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/apis/writings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
GetWritingResponse,
PublishWritingArgs,
UpdateWritingTitleArgs,
UpdateWritingOrderArgs,
} from 'types/apis/writings';

// 글 생성(글 업로드): POST
Expand Down Expand Up @@ -47,3 +48,7 @@ export const getDetailWritings = (categoryId: number): Promise<GetDetailWritings
// 글 제목 변경: PATCH
export const updateWritingTitle = ({ writingId, body }: UpdateWritingTitleArgs) =>
http.patch(`${writingURL}/${writingId}`, { json: body });

// 글 제목 순서 변경: PATCH
export const updateWritingOrder = ({ writingId, body }: UpdateWritingOrderArgs) =>
http.patch(`${writingURL}/${writingId}`, { json: body });
4 changes: 2 additions & 2 deletions frontend/src/components/Category/Category/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Category = ({ categoryId, categoryName, isDefaultCategory }: Props) => {
isError,
setIsError,
} = useUncontrolledInput();
const { patchCategory, deleteCategory } = useCategoryMutation();
const { updateCategoryTitle, deleteCategory } = useCategoryMutation();
const { goWritingTablePage } = usePageNavigate();
const toast = useToast();

Expand All @@ -38,7 +38,7 @@ const Category = ({ categoryId, categoryName, isDefaultCategory }: Props) => {

validateCategoryName(categoryName);

patchCategory({
updateCategoryTitle({
categoryId,
body: {
categoryName,
Expand Down
14 changes: 11 additions & 3 deletions frontend/src/components/Category/useCategoryMutation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import {
addCategory as addCategoryRequest,
patchCategory as patchCategoryRequest,
updateCategoryTitle as updateCategoryTitleRequest,
updateCategoryOrder as updateCategoryOrderRequest,
deleteCategory as deleteCategoryRequest,
} from 'apis/category';

Expand All @@ -14,7 +15,14 @@ export const useCategoryMutation = () => {
},
});

const { mutate: patchCategory } = useMutation(patchCategoryRequest, {
const { mutate: updateCategoryTitle } = useMutation(updateCategoryTitleRequest, {
onSuccess: () => {
queryClient.invalidateQueries(['categories']);
queryClient.invalidateQueries(['detailWritings']);
},
});

const { mutate: updateCategoryOrder } = useMutation(updateCategoryOrderRequest, {
onSuccess: () => {
queryClient.invalidateQueries(['categories']);
queryClient.invalidateQueries(['detailWritings']);
yogjin marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -28,5 +36,5 @@ export const useCategoryMutation = () => {
},
});

return { addCategory, patchCategory, deleteCategory };
return { addCategory, updateCategoryTitle, updateCategoryOrder, deleteCategory };
};
13 changes: 13 additions & 0 deletions frontend/src/hooks/queries/writing/useWritingOrderUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { updateWritingOrder } from 'apis/writings';

export const useWritingOrderUpdate = () => {
const queryClient = useQueryClient();

return useMutation(updateWritingOrder, {
onSuccess: () => {
queryClient.invalidateQueries(['detailWritings']);
queryClient.invalidateQueries(['writingsInCategory']);
},
});
};
10 changes: 5 additions & 5 deletions frontend/src/types/apis/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export type GetCategoryDetailResponse = {
writings: CategoryWriting[] | null;
} & CategoryResponse;

export type PatchCategory = {
categoryName?: string;
nextCategoryId?: number;
export type UpdateCategoryTitleArgs = {
categoryId: number;
body: AddCategoriesRequest;
};

export type PatchCategoryArgs = {
export type UpdateCategoryOrderArgs = {
categoryId: number;
body: PatchCategory;
body: { nextCategoryId: number };
};
8 changes: 8 additions & 0 deletions frontend/src/types/apis/writings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ export type UpdateWritingTitleArgs = {
writingId: number;
body: Pick<Writing, 'title'>;
};

export type UpdateWritingOrderArgs = {
writingId: number;
body: {
targetCategoryId: number;
nextWritingId: number;
};
};