-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications for duels #189
Draft
valentinperignon
wants to merge
48
commits into
main
Choose a base branch
from
notif-handle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
78bfb7f
add message
4cf4661
update style
fbdee43
CSS in progress
1e951dc
Improve css
da530cd
Improve Notification
ebdaab8
Ask user
747f55b
Fix tests
e139182
Improve notification handle
f2f23d8
can send notification when Push ation
593a1e4
subscribe to push
cacb85f
fix notification state
79f1cef
use firebase
4193af9
get notifications from firebase
7b7abc2
add messaging
0bda59c
send messages from server
cf5e197
merge
81f5c4d
Merge branch 'main' into notif-handle
e06d759
update database to save messaging token
a6c78fc
add request
143661c
update messaging token with api
cf76597
add or remove messaging token (api)
b8ca9d0
save token
16315ce
update client
45ad303
add handler
880ee9d
send notification when a new duel is available
61d8d94
update workflow
d1c8682
attention ça va bientôt merge
d029fca
merge
53c0881
update to utils
af950a4
can send notifications
ab4b410
foreground notification
2956803
notification with timer
17c1498
get foreground notification
4b80f9a
fix css
a44dcea
bye bye console.log
00b92b5
merge
5450bb5
fix server tests
9dd31ba
upda
d41d8e6
update client tests
55232c7
fix some bugs
6331daa
nathal suggestions
fc363e5
merge
7be4263
merge again
8c8fa44
Seems to be working, I mean the merge, of course, haha, what a long n…
6b9f156
Update route
6d203e2
add async / await
33413f7
Looks like it's working
62f7eab
add doc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,15 @@ | ||
import { PropTypes } from "prop-types"; | ||
import React from "react"; | ||
|
||
const FullScreenMessage = ({ id, children }) => ( | ||
<section className="fullscreen-message" id={id}> | ||
<div>{children}</div> | ||
</section> | ||
); | ||
|
||
FullScreenMessage.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
children: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default FullScreenMessage; |
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 { Cross1Icon } from "@modulz/radix-icons"; | ||
import { PropTypes } from "prop-types"; | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const NotificationForeground = ({ title, text, closeNotification }) => { | ||
const [timer, setTimer] = useState(10); | ||
|
||
useEffect(() => { | ||
let interval = setTimeout(() => { | ||
setTimer(timer - 0.05); | ||
}, 50); | ||
|
||
if (timer <= 0) { | ||
closeNotification(); | ||
} | ||
|
||
return () => clearInterval(interval); | ||
}); | ||
|
||
return ( | ||
<div className="notification"> | ||
<div id="indicator" style={{ width: `${timer * 10}%` }}></div> | ||
|
||
<div id="close" onClick={closeNotification}> | ||
<Cross1Icon /> | ||
</div> | ||
|
||
<h2>{title}</h2> | ||
<p>{text}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
NotificationForeground.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
text: PropTypes.string.isRequired, | ||
closeNotification: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default NotificationForeground; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
|
||
// Import Firebase scripts | ||
import firebase from "firebase"; | ||
|
||
// Import firebase scripts | ||
self.importScripts("https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js"); | ||
self.importScripts("https://www.gstatic.com/firebasejs/8.2.9/firebase-messaging.js"); | ||
|
||
let cacheName = "guacamolePWA-v1"; | ||
caches.has(cacheName).then((res) => { | ||
if (res) { | ||
cacheName = "guacamolePWA-v2"; | ||
} | ||
}); | ||
|
||
// Initialize app with firebase data | ||
// You can create a project and get these data here: https://firebase.google.com/ | ||
firebase.initializeApp({ | ||
apiKey: "YOUR_KEY", | ||
authDomain: "YOUR_AUTH_DOMAIN", | ||
projectId: "YOUR_PROJECT_ID", | ||
storageBucket: "YOUR_STORAGE_BUCKET", | ||
messagingSenderId: "YOUR_MESSAGING_SENDER_ID", | ||
appId: "YOUR_APP_ID", | ||
}); | ||
|
||
/** | ||
* Install the service worker | ||
* JavaScript files and assets (e.g. images) are cached | ||
|
@@ -65,16 +83,66 @@ self.addEventListener("fetch", (e) => { | |
const newResource = r.clone(); | ||
caches.open(cacheName).then((cache) => { | ||
console.info(`[Service Worker] Caching new resource: ${e.request.url}`); | ||
cache.put(e.request, newResource); | ||
cache.put(e.request, newResource).catch(() => console.error("Can't cache new resource")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an error or a simple warning? |
||
}); | ||
return r; | ||
}); | ||
}) | ||
); | ||
}); | ||
|
||
/** | ||
* Message sent from the client to the service-worker | ||
*/ | ||
self.addEventListener("message", (e) => { | ||
// User wants to use the new sw | ||
if (e.data.type && e.data.type === "SKIP_WAITING") { | ||
self.skipWaiting(); | ||
self.skipWaiting().catch(() => console.error("Can't skip waiting")); | ||
} | ||
}); | ||
|
||
/** | ||
* Push message handling (app on background) | ||
* Use functions from firebase API | ||
*/ | ||
const messaging = firebase.messaging(); | ||
messaging.onBackgroundMessage((payload) => { | ||
// A notification must have a title | ||
if (!payload.data.title) { | ||
console.error("Can't display notification without title"); | ||
return; | ||
} | ||
|
||
const { title } = payload.data; | ||
const options = { | ||
body: payload.data.body, | ||
icon: payload.data.image, | ||
data: payload.data, | ||
}; | ||
|
||
// Show notification | ||
self.registration | ||
.showNotification(title, options) | ||
.catch((err) => console.error("Can't send notification: ", err)); | ||
}); | ||
|
||
/** | ||
* Handle user click on a notification | ||
* Display the duel page id linked to the notification | ||
*/ | ||
self.addEventListener("notificationclick", (e) => { | ||
const { notification, action } = e; | ||
if (action === "close") { | ||
notification.close(); | ||
return; | ||
} | ||
|
||
const { data } = notification; | ||
if (data.type === "duel" && data.duelId) { | ||
// eslint-disable-next-line no-undef | ||
clients | ||
.openWindow(`/duel/${data.duelId}`) | ||
.catch(() => console.error("Can't open window after the user clicks on a notification")); | ||
notification.close(); | ||
} | ||
}); |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this possible to have these file in our bundle instead of downloading them from a third-party server?