Skip to content

Commit

Permalink
Added an unread count badge on message bar
Browse files Browse the repository at this point in the history
  • Loading branch information
predatorray committed Dec 11, 2024
1 parent 44a479d commit e4dbb63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,10 @@
display: flex;
justify-content: space-between;
padding: 0 5px;
box-shadow: 0 0 10px 0 #3333;
border-bottom: 1px solid #f1f1f1;
}

.message-bar .title-bar:hover {
background: #f6f6f6;
cursor: pointer;
}

Expand Down Expand Up @@ -474,6 +473,12 @@
transform: rotate(-90deg);
}

.message-bar .title-bar .badge {
margin-left: 7px;
background: #ffeb90;
color: #111;
}

.message-bar .no-messages {
font-size: 12px;
color: #333;
Expand Down Expand Up @@ -552,6 +557,17 @@
background-repeat: no-repeat;
border-radius: 4px;
height: 25px;
min-height: 25px;
margin: 10px auto;
border: 2px solid transparent;
}

.badge {
background-color: #999;
display: inline-block;
padding: 5px;
font-size: 10px;
font-weight: 800;
color: #fff;
border-radius: 5px;
}
11 changes: 11 additions & 0 deletions src/components/MessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export default function MessageBar(props: {
const [collapsed, setCollapsed] = useState(false);
const flipCollapsed = useCallback(() => setCollapsed(collapsed => !collapsed), []);

const [readMessageCount, setReadMessageCount] = useState<number>(0);
useEffect(() => {
if (!collapsed) {
setReadMessageCount(messages.length);
}
}, [messages, collapsed]);
const unreadMessageCount = useMemo(() => messages.length - readMessageCount, [messages, readMessageCount]);

const [inputValue, setInputValue] = useState('');

const handleInputChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(e => {
Expand Down Expand Up @@ -139,6 +147,9 @@ export default function MessageBar(props: {
<div className="profile">
<PlayerAvatar playerId={playerId}/>
<a>Messages</a>
{
(collapsed && unreadMessageCount > 0) && <span className="badge">{unreadMessageCount > 99 ? '99+' : unreadMessageCount}</span>
}
</div>
<div className="icon">
<p style={{transform: collapsed ? 'rotate(-90deg)' : 'rotate(90deg)'}}></p>
Expand Down

0 comments on commit e4dbb63

Please sign in to comment.