Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cloud/components/organisms/EventSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ const EventSource = ({ teamId }: EventSourceProps) => {
smartFolderDeleteHandler(event)
break
case 'notificationCreated':
case 'notificationViewed':
notificationsEventListener(event)
break
}
Expand Down
1 change: 1 addition & 0 deletions src/cloud/interfaces/db/appEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type SseEventType =
| 'smartFolderUpdate'
| 'smartFolderDelete'
| 'notificationCreated'
| 'notificationViewed'

export interface SerializableAppEventProps {
id: string
Expand Down
6 changes: 4 additions & 2 deletions src/components/organisms/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ const TopLevelNavigator = () => {
}, [])

useEffect(() => {
const handler = (event: CustomEvent<Record<string, number>>) =>
const handler = (event: CustomEvent<Record<string, number>>) => {
setNotificationCounts(event.detail)
}
boosthubNotificationCountsEventEmitter.listen(handler)
return () => boosthubNotificationCountsEventEmitter.unlisten(handler)
}, [])
Expand Down Expand Up @@ -300,6 +301,7 @@ const TopLevelNavigator = () => {
: null

if (boosthubTeam != null) {
const notificationCount = notificationCounts[boosthubTeam.id] || 0
const rows: SidebarToolbarRow[] = [
{
tooltip: 'Spaces',
Expand Down Expand Up @@ -335,7 +337,7 @@ const TopLevelNavigator = () => {
{
tooltip: 'Notifications',
icon:
notificationCounts[boosthubTeam.id] != null ? (
notificationCount > 0 ? (
<NotifyIcon
size={26}
count={notificationCounts[boosthubTeam.id]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const SidebarSpace = ({
<RoundedImage url={row.icon} alt={row.label} size={30} />
</div>
<span className='sidebar__spaces__label'>{row.label}</span>
{row.notificationCount != null && (
{row.notificationCount != null && row.notificationCount > 0 && (
<div className='sidebar__spaces__notifications'>
{row.notificationCount}
</div>
Expand Down
28 changes: 23 additions & 5 deletions src/shared/lib/stores/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ function useNotificationStore() {
cacheRef.current,
observersRef.current
)
setCounts((prev) => {
return {
[updated.team]: Math.max(0, (prev[updated.team] || 1) - 1),
}
})
} catch (error) {
pushApiErrorMessage(error)
}
Expand Down Expand Up @@ -167,6 +162,29 @@ function useNotificationStore() {
[event.data.teamId]: (prev[event.data.teamId] || 0) + 1,
}
})
break
}
case 'notificationViewed': {
if (cacheRef.current.has(event.data.teamId)) {
const notification = await getNotification(
event.data.notificationId
)
insertNotifications(
{ [notification.team]: [notification] },
cacheRef.current,
observersRef.current
)
}
setCounts((prev) => {
return {
...prev,
[event.data.teamId]: Math.max(
0,
(prev[event.data.teamId] || 0) - 1
),
}
})
break
}
}
},
Expand Down