-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat * feat * 중복 처리 * fix * f * feat * feat(recruit): 내 공고 생성 모달 구현 (#20) * feat(recruit): 내 공고 생성 모달 구현 * update * feat(editor): 에디터의 제목, 태그 구현 (#19) * feat * feat * 중복 처리 * fix * f * fix * import * fix * a * fix ui * fix * fix * fix * fix * fix * fix * fix * yarn * fix * fix * feat * feat * feat * feat * feat * fix * fix * f * fix * fix * f --------- Co-authored-by: shellboy <qkrdmstlr3@naver.com>
- Loading branch information
1 parent
7aed0ed
commit 71e15b1
Showing
23 changed files
with
439 additions
and
466 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/app/(sidebar)/write/[id]/api/useDeleteCardTag/useDeleteCardTag.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { http } from '@/apis/http'; | ||
|
||
const deleteCardTag = (cardId: number, tagId: number) => | ||
http.delete({ | ||
url: `/cards/${cardId}/title/tag/${tagId}`, | ||
}); | ||
|
||
export const useDeleteCardTag = (cardId: number) => | ||
useMutation({ | ||
mutationKey: ['delete-card-tag', cardId], | ||
mutationFn: (tagId: number) => deleteCardTag(cardId, tagId), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/app/(sidebar)/write/[id]/api/useGetCardDetail/useGetCardDetail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { http } from '@/apis/http'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { JSONContent } from '@tiptap/react'; | ||
|
||
export interface GetCardDetailResponse { | ||
title: string; | ||
content: JSONContent; | ||
updatedDate: `${string} ${string}`; | ||
cardTypeValueList: string[]; | ||
tagList: Array<{ | ||
id: number; | ||
name: string; | ||
type: '인성' | '역량' | '분류'; | ||
}>; | ||
} | ||
|
||
const getCardDetail = (cardId: number) => | ||
http.get({ | ||
url: `/cards/${cardId}`, | ||
}); | ||
|
||
export const useGetCardDetail = (cardId: number) => | ||
useSuspenseQuery({ | ||
queryKey: ['get-card-detail', cardId], | ||
queryFn: () => getCardDetail(cardId), | ||
select: ({ data }) => data, | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/app/(sidebar)/write/[id]/api/usePostCardTag/usePostCardTag.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { http } from '@/apis/http'; | ||
|
||
const postCardTag = (cardId: number, tagId: number) => | ||
http.post({ | ||
url: `/cards/${cardId}/title/tag/${tagId}`, | ||
}); | ||
|
||
export const usePostCardTag = (cardId: number) => | ||
useMutation({ | ||
mutationKey: ['post-card-tag', cardId], | ||
mutationFn: (tagId: number) => postCardTag(cardId, tagId), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/app/(sidebar)/write/[id]/api/usePutCardContent/usePutCardContent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { JSONContent } from '@tiptap/react'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { http } from '@/apis/http'; | ||
|
||
const putCardContent = (cardId: number, content: JSONContent) => | ||
http.put({ | ||
url: `/cards/${cardId}/content`, | ||
data: content, | ||
}); | ||
|
||
export const usePutCardContent = (cardId: number) => | ||
useMutation({ | ||
mutationKey: ['put-card-content', cardId], | ||
mutationFn: (content: JSONContent) => putCardContent(cardId, content), | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/app/(sidebar)/write/[id]/api/usePutCardTitle/usePutCardTitle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { http } from '@/apis/http'; | ||
|
||
const putCardTitle = (cardId: number, title: string) => | ||
http.put({ | ||
url: `/cards/${cardId}/title`, | ||
data: { title }, | ||
}); | ||
|
||
export const usePutCardTitle = (cardId: number) => | ||
useMutation({ | ||
mutationKey: ['put-card', cardId], | ||
mutationFn: (title: string) => putCardTitle(cardId, title), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use client'; | ||
|
||
import { generateContext } from '@/lib'; | ||
import { StrictPropsWithChildren } from '@/types'; | ||
import { useGetCardDetail } from '../api/useGetCardDetail/useGetCardDetail'; | ||
import { GetCardDetailResponse } from '@/app/(sidebar)/write/[id]/api/useGetCardDetail/useGetCardDetail'; | ||
|
||
const [CardDetailTagsProvider, useCardDetailTagsContext] = generateContext<GetCardDetailResponse>({ | ||
name: 'card-detail-tag-fetcher', | ||
defaultValue: { title: '', cardTypeValueList: [], content: {}, tagList: [], updatedDate: ' ' }, | ||
}); | ||
|
||
function CardTagFetcher({ children, cardId }: StrictPropsWithChildren<{ cardId: number }>) { | ||
const { data } = useGetCardDetail(cardId); | ||
|
||
return <CardDetailTagsProvider {...data}>{children}</CardDetailTagsProvider>; | ||
} | ||
|
||
export { CardTagFetcher, useCardDetailTagsContext }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import { usePutCardTitle } from '../api/usePutCardTitle/usePutCardTitle'; | ||
import { usePostCardTag } from '../api/usePostCardTag/usePostCardTag'; | ||
import { useDeleteCardTag } from '../api/useDeleteCardTag/useDeleteCardTag'; | ||
import { useCardDetailTagsContext } from '../fetcher/CardTagFetcher'; | ||
import { GetCardDetailResponse } from '@/app/(sidebar)/write/[id]/api/useGetCardDetail/useGetCardDetail'; | ||
|
||
export function useWrite(id: number) { | ||
const { title: prevTitle, updatedDate, tagList } = useCardDetailTagsContext(); | ||
|
||
const personalityTags = useMemo(() => tagList.filter((tag) => tag.type === '인성'), [id]); | ||
const abilityTags = useMemo(() => tagList.filter((tag) => tag.type === '역량'), [id]); | ||
const categoryTags = useMemo(() => tagList.filter((tag) => tag.type === '분류'), [id]); | ||
|
||
const [title, setTitle] = useState<string>(prevTitle || ''); | ||
const [selectedTags, setSelectedTags] = useState<GetCardDetailResponse['tagList']>([ | ||
...personalityTags, | ||
...abilityTags, | ||
]); | ||
const [selectedCategories, setSelectedCategories] = useState<GetCardDetailResponse['tagList']>(categoryTags); | ||
|
||
const { mutate: mutatePutCardTitle } = usePutCardTitle(id); | ||
const { mutate: mutatePostCardTag } = usePostCardTag(id); | ||
const { mutate: mutateDeleteCardTag } = useDeleteCardTag(id); | ||
|
||
const handlePutCardTitle = useCallback((value: string) => { | ||
setTitle(value); | ||
mutatePutCardTitle(value); | ||
}, []); | ||
|
||
const handlePostCardTag = useCallback( | ||
(tag: GetCardDetailResponse['tagList'][number], type: 'category' | 'tag') => { | ||
mutatePostCardTag(tag.id, { | ||
onSuccess: () => { | ||
if (type === 'category') { | ||
setSelectedCategories((prev) => [...prev, tag]); | ||
return; | ||
} | ||
setSelectedTags((prev) => [...prev, tag]); | ||
}, | ||
}); | ||
}, | ||
[...selectedCategories, ...selectedTags], | ||
); | ||
|
||
const handleDeleteCardTag = useCallback( | ||
(tag: GetCardDetailResponse['tagList'][0], type: 'category' | 'tag') => { | ||
mutateDeleteCardTag(tag.id, { | ||
onSuccess: () => { | ||
if (type === 'category') { | ||
setSelectedCategories((prev) => prev.filter((value) => value.id !== tag.id)); | ||
return; | ||
} | ||
setSelectedTags((prev) => prev.filter((value) => value.id !== tag.id)); | ||
}, | ||
}); | ||
}, | ||
[...selectedCategories, ...selectedTags], | ||
); | ||
|
||
return { | ||
handlePutCardTitle, | ||
handlePostCardTag, | ||
handleDeleteCardTag, | ||
title, | ||
selectedTags, | ||
selectedCategories, | ||
personalityTags, | ||
abilityTags, | ||
categoryTags, | ||
updatedDate: updatedDate.split(' ')[0].replaceAll(/-/g, '.'), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AsyncBoundaryWithQuery } from '@/lib'; | ||
import { PropsWithChildren } from 'react'; | ||
import { CardTagFetcher } from './fetcher/CardTagFetcher'; | ||
|
||
export default function WriteLayout({ params: { id }, children }: PropsWithChildren<{ params: { id: string } }>) { | ||
return ( | ||
<AsyncBoundaryWithQuery> | ||
<CardTagFetcher cardId={Number(id)}> | ||
<main>{children}</main> | ||
</CardTagFetcher> | ||
</AsyncBoundaryWithQuery> | ||
); | ||
} |
Oops, something went wrong.