-
Notifications
You must be signed in to change notification settings - Fork 0
ERA-10594: Leverage read
filter param in messages API calls from das-web-react
#1259
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 1 commit
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 |
---|---|---|
|
@@ -37,15 +37,21 @@ const MessageMenu = () => { | |
[state.results.length, subjects] | ||
); | ||
|
||
const fetchMenuMessages = useCallback(() => { | ||
fetchAllMessages({ page_size: 100 }) | ||
.then((results = []) => dispatch(fetchMessagesSuccess({ results }))) | ||
const fetchMenuMessages = useCallback((getUnreadMessagesOnly = false) => { | ||
const page_size = 100; | ||
const params = !getUnreadMessagesOnly ? { page_size } : { page_size, read: false }; | ||
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. Since I believe We only want to use 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. I think the condition could be simplified to:
Now, for the case where all we care is to know if we need to render the badge, do we need a page size of 100? Feels like all that data is unused, all we care is to know if there's one or more messages to show the badge but we don't care about the data. We could even send a page_size of 0 and only care about the |
||
fetchAllMessages(params) | ||
.then((results = []) => { | ||
dispatch(fetchMessagesSuccess({ results })); | ||
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. I know this is old code, but given the ticket and the refactor, shouldn't we take this logic to its own duck? Maybe a |
||
}) | ||
.catch((error) => console.warn('error fetching messages', { error })); | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
fetchMenuMessages(); | ||
}, [dispatch, fetchMenuMessages]); | ||
if (subjects.length > 0){ | ||
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. This is needed because internally 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. Hmm I don't think I understand the logic of this. I feel like this needs to be re-done, since we shouldn't care if the subjects are loaded or not. We just want to fetch the unread messages to show a badge, independently of the subjects that sent the message, why do we need to wait? I guess its a constraint of old logic, but we shouldn't rely on that, if we need to re-work old selectors, reducers, etc... Or simply add new ones, we should! |
||
fetchMenuMessages(true); | ||
} | ||
}, [dispatch, fetchMenuMessages, subjects]); | ||
|
||
return canShowMessageMenu ? <Dropdown | ||
align="end" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a top of the file constant
MENU_MESSAGES_PAGE_SIZE
😄