-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 알림 엔드포인트 API함수/Hook 4종 추가 #237
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './auth-service'; | ||
| export * from './follower-service'; | ||
| export * from './group-service'; | ||
| export * from './notification-service'; | ||
| export * from './user-service'; |
This file contains hidden or 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,26 @@ | ||
| import { apiV1 } from '@/api/core'; | ||
| import { GetNotificationListQueryParams, NotificationList } from '@/types/service/notification'; | ||
|
|
||
| export const notificationServiceRemote = () => ({ | ||
| updateRead: async (notificationId: number) => { | ||
| await apiV1.post(`/notifications/${notificationId}/read`); | ||
| }, | ||
|
|
||
| updateReadAll: async () => { | ||
| await apiV1.post(`/notifications/read-all`); | ||
| }, | ||
|
|
||
| getList: async (queryParams: GetNotificationListQueryParams) => { | ||
| return await apiV1.get<NotificationList>(`/notifications`, { | ||
| params: { ...queryParams }, | ||
| }); | ||
| }, | ||
|
|
||
| getUnreadCount: async () => { | ||
| try { | ||
| return await apiV1.get<number>(`/notifications/unread-count`); | ||
| } catch { | ||
| return 0; | ||
| } | ||
| }, | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,25 @@ | ||
| 'use client'; | ||
|
|
||
| import { NotificationCard } from '@/components/pages/notification'; | ||
| import { useNotifications } from '@/hooks/use-notifications'; | ||
| import { useGetNotificationsInfinite } from '@/hooks/use-notification/use-notification-get-list'; | ||
|
|
||
| export default function NotificationPage() { | ||
| const messages = useNotifications(); | ||
| const { data: notificationList, fetchNextPage } = useGetNotificationsInfinite({ size: 1 }); | ||
|
|
||
| if (!notificationList) return; | ||
|
|
||
| return ( | ||
| <section> | ||
| {messages.map((data, idx) => ( | ||
| <NotificationCard key={idx} data={data} /> | ||
| <div className='flex h-10 flex-row items-center justify-end gap-2'> | ||
| <p className='text-mono-white bg-mint-500 flex-center size-4 rounded-full'>v</p> | ||
| <p className='text-mono-black text-text-sm mr-3 text-right'>모두 읽음 처리</p> | ||
| </div> | ||
| {notificationList.map((item, idx) => ( | ||
| <NotificationCard key={idx} item={item} /> | ||
| ))} | ||
| <button className='text-black' onClick={() => fetchNextPage()}> | ||
| 다음 | ||
| </button> | ||
| </section> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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,4 @@ | ||
| export { useGetNotificationsInfinite } from './use-notification-get-list'; | ||
| export { useGetNotificationUnreadCount } from './use-notification-get-unread-count'; | ||
| export { useUpdateNotificationRead } from './use-notification-update-read'; | ||
| export { useUpdateNotificationReadAll } from './use-notification-update-read-all'; |
15 changes: 15 additions & 0 deletions
15
src/hooks/use-notification/use-notification-get-list/index.ts
This file contains hidden or 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 { useInfiniteQuery } from '@tanstack/react-query'; | ||
|
|
||
| import { API } from '@/api'; | ||
| import { notificationKeys } from '@/lib/query-key/query-key-notification'; | ||
| import { GetNotificationListQueryParams } from '@/types/service/notification'; | ||
|
|
||
| export const useGetNotificationsInfinite = (params?: GetNotificationListQueryParams) => { | ||
| return useInfiniteQuery({ | ||
| queryKey: notificationKeys.list(params), | ||
| queryFn: ({ pageParam }) => API.notificationService.getList({ ...params, cursor: pageParam }), | ||
| initialPageParam: params?.cursor, | ||
| getNextPageParam: (lastPage) => lastPage.nextCursor, | ||
| select: (data) => data.pages.flatMap((page) => page.notifications) || [], | ||
| }); | ||
| }; |
15 changes: 15 additions & 0 deletions
15
src/hooks/use-notification/use-notification-get-unread-count/index.ts
This file contains hidden or 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 { useQuery } from '@tanstack/react-query'; | ||
|
|
||
| import { API } from '@/api'; | ||
| import { notificationKeys } from '@/lib/query-key/query-key-notification'; | ||
|
|
||
| export const useGetNotificationUnreadCount = () => { | ||
| const isAuthenticated = typeof window !== 'undefined' && document.cookie.includes('accessToken'); | ||
|
|
||
| return useQuery({ | ||
| queryKey: notificationKeys.unReadCount(), | ||
| queryFn: () => API.notificationService.getUnreadCount(), | ||
| retry: false, // 재시도 안 함 | ||
| enabled: isAuthenticated, | ||
| }); | ||
| }; |
15 changes: 15 additions & 0 deletions
15
src/hooks/use-notification/use-notification-update-read-all/index.ts
This file contains hidden or 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 { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
|
||
| import { API } from '@/api'; | ||
| import { notificationKeys } from '@/lib/query-key/query-key-notification'; | ||
|
|
||
| export const useUpdateNotificationReadAll = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| mutationFn: () => API.notificationService.updateReadAll(), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: notificationKeys.list() }); | ||
| queryClient.invalidateQueries({ queryKey: notificationKeys.unReadCount() }); | ||
| }, | ||
| }); | ||
| }; |
15 changes: 15 additions & 0 deletions
15
src/hooks/use-notification/use-notification-update-read/index.ts
This file contains hidden or 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 { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
|
||
| import { API } from '@/api'; | ||
| import { notificationKeys } from '@/lib/query-key/query-key-notification'; | ||
|
|
||
| export const useUpdateNotificationRead = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| mutationFn: (notificationId: number) => API.notificationService.updateRead(notificationId), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: notificationKeys.list() }); | ||
| queryClient.invalidateQueries({ queryKey: notificationKeys.unReadCount() }); | ||
| }, | ||
| }); | ||
| }; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,11 @@ | ||
| import { GetNotificationListQueryParams } from '@/types/service/notification'; | ||
|
|
||
| export const notificationKeys = { | ||
| all: ['notifications'] as const, | ||
| list: (params?: GetNotificationListQueryParams) => [ | ||
| 'notifications', | ||
| 'list', | ||
| ...(params ? [params] : []), | ||
| ], | ||
| unReadCount: () => [...notificationKeys.all, 'unread-count'], | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
router.push 라는 성공 후 추가 로직이 존재하기 때문에 mutateAsync를 사용했다고 보면 될까요?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습니당 mutateAsync 성공 후 페이지 이동이 되어야 해서요 :)