-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature/#502] 헤더 안읽음 알림 카운트 실시간 갱신 #521
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
8 commits
Select commit
Hold shift + click to select a range
ed7a33d
feat: 알림 읽음/도착 시 안읽음 메세지수를 캐시에서 바로 바꾸는 유틸 추가
jjjsun 0a50ca9
feat: 실시간 메세지수 업테이트를 위한 payload 타입추가
jjjsun a41eb28
feat: 알림 단건읽음/모두읽음 optimistic 업데이트
jjjsun e43c3c3
feat: 푸시 payload로 알림 목록 캐시 실시간 갱신
jjjsun 0ce739b
fix: 푸시 메세지를 payload와 같이 페이지로 전달
jjjsun 2c89c07
refactor: 테스트파일 삭제
jjjsun 96f7e66
fix: 알림 읽음 실패시 낡은 캐시 콜백하지 않도록 수정
jjjsun 7081ecd
fix: 알림 읽음 실패시 안읽음 수를 즉시 복구
jjjsun 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
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
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,92 @@ | ||
| import type { InfiniteData } from "@tanstack/react-query"; | ||
|
|
||
| import type { | ||
| INotificationHistoryData, | ||
| INotificationHistoryItem, | ||
| } from "@/types/notification/notification"; | ||
|
|
||
| export type TNotificationHistoryCache = InfiniteData< | ||
| INotificationHistoryData, | ||
| string | null | ||
| >; | ||
|
|
||
| export function emptyHistoryCache(): TNotificationHistoryCache { | ||
| return { pages: [], pageParams: [] }; | ||
| } | ||
|
|
||
| //알림 단건 읽음 처리 | ||
| export function markNotificationRead( | ||
| cache: TNotificationHistoryCache | undefined, | ||
| userNotificationId: number, | ||
| ): TNotificationHistoryCache { | ||
| if (!cache) return emptyHistoryCache(); | ||
|
jjjsun marked this conversation as resolved.
|
||
|
|
||
| return { | ||
| ...cache, | ||
| pages: cache.pages.map((page) => ({ | ||
| ...page, | ||
| notifications: page.notifications.map((item) => | ||
| item.userNotificationId === userNotificationId | ||
| ? { ...item, isRead: true } | ||
| : item, | ||
| ), | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| //모두 읽음 처리 | ||
| export function markAllNotificationRead( | ||
| cache: TNotificationHistoryCache | undefined, | ||
| ): TNotificationHistoryCache { | ||
| if (!cache) return emptyHistoryCache(); | ||
|
|
||
| return { | ||
| ...cache, | ||
| pages: cache.pages.map((page) => ({ | ||
| ...page, | ||
| notifications: page.notifications.map((item) => ({ | ||
| ...item, | ||
| isRead: true, | ||
| })), | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| //새알림 맨 위로 붙이기 | ||
| export function prependNotification( | ||
| cache: TNotificationHistoryCache | undefined, | ||
| item: INotificationHistoryItem, | ||
| ): TNotificationHistoryCache { | ||
| // 캐시가 없거나 페이지 0장이면 새로운 페이지 만들어서 알림 추가 | ||
| if (!cache || cache.pages.length === 0) { | ||
| return { | ||
| pages: [{ hasNext: false, nextCursor: null, notifications: [item] }], | ||
| pageParams: [null], | ||
| }; | ||
| } | ||
|
|
||
| // 이미 페이지가 있으면 페이지 맨위에 알림 추가 | ||
| const alreadyExists = cache.pages.some((page) => | ||
| page.notifications.some( | ||
| (n) => n.userNotificationId === item.userNotificationId, | ||
| ), | ||
| ); | ||
| // 이미 있는 알림이면 캐시 그대로 반환 | ||
| if (alreadyExists) return cache; | ||
|
|
||
| //firstPage = 1페이지 (최신알람들 있는곳) | ||
| //restPages = 2페이지부터 나머지 다 | ||
| const [firstPage, ...restPages] = cache.pages; | ||
| const [firstParam, ...restParams] = cache.pageParams; | ||
|
|
||
| return { | ||
| pages: [ | ||
| { | ||
| ...firstPage, | ||
| notifications: [item, ...firstPage.notifications], //[새알림, ...예전1페이지알림들] | ||
| }, | ||
| ...restPages, | ||
| ], | ||
| pageParams: [firstParam, ...restParams], | ||
| }; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.