Skip to content

Instantly share code, notes, and snippets.

@lushiyun
Last active September 26, 2020 22:14
Show Gist options
  • Save lushiyun/6829e63a43b0e351dc1d38d317745458 to your computer and use it in GitHub Desktop.
Save lushiyun/6829e63a43b0e351dc1d38d317745458 to your computer and use it in GitHub Desktop.
// src/features/messages/messagesSlice.js
... // omitted other imports
import { selectTeamById } from '../teams/teamsSlice'
import { isAfter, parseISO, subYears } from 'date-fns'
export const selectUnreadMessages = createSelector(
[selectMessagesByTeam, selectTeamById],
(messages, team) => {
const lastReadAt = parseISO(team.lastReadAt) || subYears(Date.now(), 1)
return messages.filter((message) =>
isAfter(parseISO(message.created_at), lastReadAt)
)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment