Skip to content
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

알림 실시간 빨간 동그라미 표시 #255

Closed
wants to merge 8 commits into from

Conversation

seheon99
Copy link
Contributor

변경 개요

구현 내용

  • 알림 아이콘을 별도 컴포넌트로 분리했어요
    • useAlarmQuery() 사용
    • 10초에 한번씩 알람의 첫 페이지 revalidate
    • 마지막 알람의 isReadedfalse 면 빨간 점 표시

관련 이슈

seheon99 added 4 commits July 13, 2024 18:37
This commit renames the `HeaderAlarmBlock` component to `HeaderAlarmModal` to better reflect its functionality as a modal rather than a static block. Accompanying this rename, interface names and import statements in related components are updated to ensure consistency and correct linkage across the project. This change improves the clarity and accuracy of the component naming.
This commit introduces a type alias `OpenModal` to manage the modal state in the `HeaderUserBlock` component. The type alias is used to clarify and restrict the values for opening different modals, making the state management more explicit and the code more readable. This refactor enhances maintainability and clarity of the modal handling logic.
This commit adds a new `HeaderAlarmIcon` component that includes a dynamic badge to indicate unread notifications. This component uses a polling mechanism via `useEffect` to periodically update the alarm status. It has been integrated into the `HeaderUserBlock`, replacing the direct use of the `Icons` component for displaying the alarm icon. This change enhances the notification functionality by visually indicating new alerts without user action.
…RY_KEY

This commit refines the alarm updating mechanism in the HeaderAlarmIcon component by decoupling the mutation function from the useAlarmQuery hook, using it with a specific query key. The change involves exporting ALARM_QUERY_KEY from the use-alarm hook and updating the useEffect in HeaderAlarmIcon to use this key for more precise control over data updates. This approach reduces unnecessary dependencies in the useEffect and ensures more targeted data fetching.
Copy link

vercel bot commented Jul 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fit-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2024 2:16pm

@seheon99 seheon99 requested a review from jaewoongs July 14, 2024 02:58
@seheon99 seheon99 self-assigned this Jul 14, 2024
Comment on lines 13 to 16
useEffect(() => {
const interval = setInterval(() => mutate(ALARM_QUERY_KEY(0)), 10000);
return () => clearInterval(interval);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 : 현재 백엔드와 연계된 문제라고 생각하긴 하는데 지금 알람을 불러와서 안읽은게 있으면 빨간불이 뜨지만 한번 불러온 알람은 읽음 처리가 돼서 10초 뒤에 다시 api를 호출하면 빨간불이 사라집니다. 혹시 좋은 아이디어 있을까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훅으로 따로 빼서 복잡하게 처리해야겠네요... 😢

seheon99 added 3 commits July 14, 2024 22:51
…val options

This commit updates the useAlarmQuery hook to include the revalidateOnFocus and dedupingInterval options in the useSWRInfinite function. By setting revalidateOnFocus to false and dedupingInterval to 1000 * 60 * 10, we prevent unnecessary revalidation of data when the page regains focus and reduce duplicate requests within a 10-minute interval. This optimization improves the performance and efficiency of data fetching in the useAlarmQuery hook.
This commit refactors the HeaderAlarmIcon component to use the newly created useAlarmBadge hook. The useAlarmBadge hook encapsulates the logic for determining whether to display the badge indicating unread notifications. By using this hook, the code becomes more modular and reusable. This change improves the maintainability and readability of the code.
Refactor the HeaderUserBlock component to use the newly created useAlarmBadge hook. This hook encapsulates the logic for determining whether to display the badge indicating unread notifications. By using this hook, the code becomes more modular and reusable, improving maintainability and readability.
@seheon99
Copy link
Contributor Author

seheon99 commented Jul 14, 2024

  • intervalIdbadged 를 상태로 갖고 badged 를 반환하는 useAlarmBadge 훅을 만들었는데 확인 한번 부탁드립니다!
  • 포커스될 때 다시 revalidate 할 때도 비슷한 문제가 생길 것 같아서 useAlarmQuery 훅에서 revalidateOnFocus 를 꺼뒀고 dedupingInterval 도 1시간으로 늘렸어요
  • 유저가 알람을 눌렀을 때 최신 알람을 확인하지 못할 수도 있어서 알람 배지를 눌렀을 때 revalidate 하게 했습니다!

서버에서의 추가 구현 없이는

  1. 페이지가 켜져있는 상태에서 엄청 긴 시간 (지금은 한시간) 이 지나거나
  2. 페이지를 새로고침할 때
  3. 페이지를 닫을 때

경우를 해결 못할 것 같아요 🥲

@seheon99 seheon99 requested a review from jaewoongs July 14, 2024 14:07
Refactor the useAlarmBadge hook to handle unread notifications more accurately. This change ensures that the badge indicating unread notifications is displayed only when the first value in the data array is not marked as read. By improving the logic in the hook, we enhance the reliability and effectiveness of the badge display.
@jaewoongs
Copy link
Contributor

백엔드에서 알림을 불러오는 api와 읽었다고 보내는 api를 나눠서 하면 편하지 않을까요..?

@seheon99
Copy link
Contributor Author

seheon99 commented Jul 16, 2024

넹 서버에서 추가 구현이 가능하면 좋을 것 같아요

@seheon99 seheon99 closed this Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

알림 실시간 빨간 동그라미 표시
2 participants