-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-open preview if user didn't see item after voting ending
- Loading branch information
1 parent
a067bb2
commit 2dc85f1
Showing
1 changed file
with
20 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 20 additions & 2 deletions
22
src/pages/commonFeed/components/FeedLayout/utils/checkShouldAutoOpenPreview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import { ChatItem } from "@/pages/common/components/ChatComponent"; | ||
import { ProposalState } from "@/shared/models"; | ||
import { checkIsCountdownState } from "@/shared/utils"; | ||
|
||
export const checkShouldAutoOpenPreview = ( | ||
chatItem?: ChatItem | null, | ||
): boolean => | ||
!chatItem?.seenOnce || chatItem?.proposal?.state === ProposalState.VOTING; | ||
): boolean => { | ||
if (!chatItem) { | ||
return false; | ||
} | ||
if (!chatItem.seenOnce || chatItem.proposal?.state === ProposalState.VOTING) { | ||
return true; | ||
} | ||
const expirationTimestamp = | ||
chatItem.proposal?.data.votingExpiresOn || | ||
chatItem.proposal?.data.discussionExpiresOn; | ||
|
||
return Boolean( | ||
!chatItem.lastSeenAt || | ||
(chatItem.proposal && | ||
!checkIsCountdownState(chatItem.proposal) && | ||
expirationTimestamp && | ||
chatItem.lastSeenAt.seconds < expirationTimestamp.seconds), | ||
); | ||
}; |