Add support to page notifications; notify when saving the user status
This commit is contained in:
parent
5ba95800a3
commit
6f49eea7b4
3 changed files with 63 additions and 0 deletions
36
js/notification.js
Normal file
36
js/notification.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
export async function showNotification(title, subtitle, time = 5000, hint) {
|
||||
const notificationBox = document.createElement('div');
|
||||
notificationBox.classList.add('notification-box');
|
||||
|
||||
const notificationTitle = document.createElement('h1');
|
||||
notificationTitle.innerHTML = title;
|
||||
|
||||
const notificationSubtitle = document.createElement('p');
|
||||
notificationSubtitle.innerHTML = subtitle;
|
||||
|
||||
notificationBox.appendChild(notificationTitle);
|
||||
if (subtitle) {
|
||||
notificationBox.appendChild(notificationSubtitle);
|
||||
}
|
||||
document.querySelector('body').appendChild(notificationBox);
|
||||
|
||||
let clicked = false;
|
||||
|
||||
notificationBox.addEventListener('click', () => {
|
||||
hideNotification(notificationBox);
|
||||
})
|
||||
|
||||
await new Promise(requestAnimationFrame);
|
||||
notificationBox.classList.add("shown");
|
||||
|
||||
await new Promise(r => setTimeout(r, time));
|
||||
if (!clicked) {
|
||||
hideNotification(notificationBox);
|
||||
}
|
||||
}
|
||||
|
||||
async function hideNotification(notificationBox) {
|
||||
notificationBox.classList.remove('shown');
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
notificationBox.remove();
|
||||
}
|
||||
Loading…
Reference in a new issue