-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for showing desktop notifications.
- Loading branch information
1 parent
b70d647
commit 225a2bb
Showing
3 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { UserNotification } from '../api'; | ||
import * as engineer from '../icons/engineer_blu.jpg'; | ||
|
||
export const DesktopNotifications = ({ | ||
notifications, | ||
isLoading | ||
}: { | ||
notifications?: UserNotification[]; | ||
isLoading: boolean; | ||
}) => { | ||
const [newest, setNewest] = useState<number>(); | ||
|
||
useEffect(() => { | ||
if (isLoading || notifications == null) { | ||
return; | ||
} | ||
|
||
// Track the newest one we get on initial load so we are only showing items that are newer. | ||
if (newest == null) { | ||
setNewest(notifications.length > 0 ? notifications[0].person_notification_id : 0); | ||
return; | ||
} | ||
|
||
notifications | ||
.filter((n) => n.person_notification_id > newest) | ||
.map((n) => { | ||
setNewest(n.person_notification_id); | ||
new Notification('New Notification Received', { | ||
body: n.message, | ||
// timestamp: Math.floor(n.created_on.getTime()), chrome only | ||
silent: true, | ||
lang: 'en-US', | ||
icon: engineer.default | ||
}); | ||
}); | ||
}, [isLoading, newest, notifications]); | ||
|
||
return <></>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters