Skip to content

Commit

Permalink
auto-open preview if user didn't see item after voting ending
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Aug 2, 2023
1 parent a067bb2 commit 2dc85f1
Showing 1 changed file with 20 additions and 2 deletions.
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),
);
};

0 comments on commit 2dc85f1

Please sign in to comment.