Skip to content

Commit

Permalink
Add a debounce delay to avoid user flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
bubner committed Aug 21, 2023
1 parent f88df4c commit d434274
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/chat/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,22 @@ function Message(props: { isAdmin: boolean; message: MessageData; key: string })
</p>
) : message.uid === auth.currentUser?.uid ? (
<>
<p className="text">
<div className="waiting">
<div className="text">
<p className="waiting">
<i>
Your message content is currently not visible as it has not been reviewed.
<br />
Please wait for an admin to review it.
</i>
<br />
</div>
</p>
{messageText}
</p>
</div>
</>
) : (
<>
<p className="text">
<i>&lt;under review&gt;</i>
</p>
</>
<p className="text">
<i>&lt;under review&gt;</i>
</p>
)
) : (
<p className="text">{messageText}</p>
Expand Down
14 changes: 8 additions & 6 deletions src/layout/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ function Navbar() {
date.setTime(Date.now());
setCurrentTime(date.toLocaleTimeString("en-AU", { hour12: true }));
}, 1000);
return () => {
clearInterval(timer);
};
return () => clearInterval(timer);
}, []);

/*
Expand Down Expand Up @@ -66,9 +64,13 @@ function Navbar() {
allOffline.push(user[1]);
}
});
setOnlineUsers(allOnline);
setOfflineUsers(allOffline);
setUnknownUsers(allUnknown);
// Debounce the setting of the state to prevent unnecessary rerenders
const debounceTimeout = setTimeout(() => {
setOnlineUsers(allOnline);
setOfflineUsers(allOffline);
setUnknownUsers(allUnknown);
}, 1000);
return () => clearTimeout(debounceTimeout);
}, [userData]);

return (
Expand Down
1 change: 0 additions & 1 deletion src/windows/FilterWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function FilterWindow() {
if (index > -1) {
oldStorage.splice(index, 1);
localStorage.setItem("filterlist", JSON.stringify(oldStorage));
oldStorage[oldStorage.length - 1]
setBlacklist(oldStorage);
}
}
Expand Down

0 comments on commit d434274

Please sign in to comment.