refactor(notifications): Centralize notification state update logic #606
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.
The main improvement is the removal of repeated logic for filtering and updating notifications. This is achieved by centralizing it in the 'getUpdatedTopicState' function, making the reducer more readable and reducing potential errors from code duplication.
Description
This PR refactors the notifications reducer to improve code readability and reduce duplication. Previously, filtering and updating logic for notifications was duplicated in multiple cases (FETCH_NOTIFICATIONS_DONE, UNSHIFT_NEW_NOTIFICATIONS). This has now been centralized in a new helper function, getUpdatedTopicState, which handles filtering out existing notifications and updating the state consistently. As a result, the reducer is now cleaner, and the risk of introducing inconsistencies is minimized.
Type of change
Please put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Fixes/Resolves (Optional)
This PR does not fix any issues specifically, but it improves the maintainability of the code by reducing redundancy and simplifying state updates for notifications.
Examples/Screenshots (Optional)
Checklist:
Additional Information (Optional)
The getUpdatedTopicState function improves consistency across state updates by ensuring that notifications are filtered and updated in a unified way. This reduces the risk of errors or bugs that could arise from duplicate logic in the reducer.