-
Notifications
You must be signed in to change notification settings - Fork 2
feat: SP1 알림배지 제거 api 연결 #379
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,13 +3,12 @@ import { END_POINT } from '@constants/api'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ALARM_KEY } from '@constants/query-key'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import queryClient from '@libs/query-client'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mutationOptions } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { postReadAlarmResponse } from '@/shared/types/alarm-types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const alarmMutations = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| READ_ALARM: () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationOptions<postReadAlarmResponse, Error, number>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationKey: ALARM_KEY.READ(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: (matchId) => post(END_POINT.POST_READ_ALARM(matchId)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| READ_ALL_ALARMS: () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationOptions<Error, void>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationKey: ALARM_KEY.READ_ALL(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: () => post(END_POINT.POST_READ_ALL_ALARMS), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: ALARM_KEY.HAS_UNREAD }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 낙관적 업데이트 롤백 누락 → 실패 시 배지가 계속 숨겨질 수 있음 API 실패해도 HAS_UNREAD를 false로 유지합니다. 이전 값 스냅샷 저장 → onError 롤백, 무조건 onSettled에서 invalidate 하도록 바꿔주세요. 컨텍스트 타입 제네릭(4번째)도 명시 필요. - READ_ALL_ALARMS: () =>
- mutationOptions<void, Error, void>({
+ READ_ALL_ALARMS: () =>
+ mutationOptions<void, Error, void, { previous?: boolean }>({
mutationKey: ALARM_KEY.READ_ALL(),
mutationFn: () => post<void>(END_POINT.POST_READ_ALL_ALARMS),
- onMutate: async () => {
- queryClient.setQueryData(ALARM_KEY.HAS_UNREAD, false);
- },
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: ALARM_KEY.HAS_UNREAD });
- },
+ onMutate: async () => {
+ await queryClient.cancelQueries({ queryKey: ALARM_KEY.HAS_UNREAD });
+ const previous = queryClient.getQueryData<boolean>(ALARM_KEY.HAS_UNREAD);
+ queryClient.setQueryData<boolean>(ALARM_KEY.HAS_UNREAD, false);
+ return { previous };
+ },
+ onError: (_err, _vars, ctx) => {
+ if (ctx?.previous !== undefined) {
+ queryClient.setQueryData(ALARM_KEY.HAS_UNREAD, ctx.previous);
+ }
+ },
+ onSettled: () => {
+ queryClient.invalidateQueries({ queryKey: ALARM_KEY.HAS_UNREAD });
+ },
}),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.