-
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.
commit 035ca7b Author: Jeon Jinho <[email protected]> Date: Sun Mar 10 14:43:31 2024 +0900 알림 기능 구현 (#245) * feat: add getNotification api * feat: add useUnreadNotifications * feat: add dot to unread item * feat: add read notification commit 8fdd711 Author: Jeon Jinho <[email protected]> Date: Sun Mar 10 14:43:16 2024 +0900 feat: add topic card action sheet (#244) * feat: add topic card action sheet * feat: disable 투표 다시하기 commit c9a80ca Author: Jeon Jinho <[email protected]> Date: Thu Mar 7 22:12:17 2024 +0900 캐시 무효화(cache busting) (#243)
- Loading branch information
Showing
7 changed files
with
171 additions
and
80 deletions.
There are no files selected for viewing
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,50 @@ | ||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { NotificationResponse } from '@interfaces/api/notification'; | ||
|
||
import client from '@apis/fetch'; | ||
|
||
export const NOTICE_KEY = 'notifications'; | ||
|
||
const getNotifications = () => { | ||
return client.get<NotificationResponse[]>('/notifications'); | ||
}; | ||
|
||
const getUnreadNotifications = () => { | ||
return client.get<number>('/notifications/counts/unread '); | ||
}; | ||
|
||
const readNotification = (id: number) => { | ||
return client.post({ path: `/notifications/${id}/read`, body: {} }); | ||
}; | ||
|
||
const useNotifications = () => { | ||
return useQuery({ | ||
queryKey: [NOTICE_KEY], | ||
queryFn: getNotifications, | ||
refetchOnMount: true, | ||
}); | ||
}; | ||
|
||
const useUnreadNotifications = () => { | ||
return useQuery({ | ||
queryKey: [NOTICE_KEY, 'unread'], | ||
queryFn: getUnreadNotifications, | ||
refetchOnMount: true, | ||
}); | ||
}; | ||
|
||
const useReadNotification = (notificationId: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: () => readNotification(notificationId), | ||
onMutate: () => { | ||
queryClient.setQueryData([NOTICE_KEY], (prev: NotificationResponse[]) => | ||
prev.map((item) => (item.id === notificationId ? { ...item, isRead: true } : item)) | ||
); | ||
}, | ||
}); | ||
}; | ||
|
||
export { useNotifications, useUnreadNotifications, useReadNotification }; |
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
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,17 @@ | ||
interface NotificationResponse { | ||
id: number; | ||
type: 'VOTE_RESULT' | 'VOTE_COUNT_ON_TOPIC' | 'COMMENT_ON_TOPIC' | 'LIKE_IN_COMMENT'; | ||
receiverType: string; | ||
isRead: boolean; | ||
message: Message; | ||
createdAt: number; | ||
} | ||
|
||
interface Message { | ||
title: string; | ||
content: string; | ||
topicId: number; | ||
commentId: number; | ||
} | ||
|
||
export type { NotificationResponse, Message }; |
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