Skip to content

Commit

Permalink
Fix old chat toast appearing when closing chat or starting game
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerkrewson committed Aug 3, 2024
1 parent feb03d3 commit b604f64
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions components/layout/GameLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const GameLayout = ({
const [frameRefresh, setFrameRefresh] = useState(0);

const [enableToasts, setEnableToasts] = useState(!isKidsMode);
const [lastShownToastDate, setLastShownToastDate] = useState(0);

const { darkModeActive } = useDarkMode();

Expand Down Expand Up @@ -96,13 +95,11 @@ const GameLayout = ({

const { playerId, playerName, message, date } = newestMsg;

const lastMessageCameInOverOneSecondAgo =
differenceInMilliseconds(Date.now(), date) > 1000;
// is latest message over 3 seconds old
const isLatestMessageOld =
differenceInMilliseconds(Date.now(), date) > 3000;

// don't show a toast for an old message that happens to be the latest
// when we are initializing
if (!lastShownToastDate && lastMessageCameInOverOneSecondAgo) {
setLastShownToastDate(date);
if (isLatestMessageOld) {
return;
}

Expand Down Expand Up @@ -130,17 +127,7 @@ const GameLayout = ({
);

igLogEvent("toastMsg");

// don't include showChat because it changing shouldn't
// cause a toast to appear
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
enableToasts,
igLogEvent,
lastShownToastDate,
newestMsg,
thisPlayer.id,
]);
}, [enableToasts, igLogEvent, newestMsg, showChat, thisPlayer.id]);

const hostName = playerList.find(({ isHost }) => isHost).name;

Expand Down

0 comments on commit b604f64

Please sign in to comment.