feat: add API example (#317)

This commit is contained in:
Lucas Fernandes Nogueira
2023-05-05 09:41:17 -03:00
committed by GitHub
parent be1c775b8d
commit 5015132ece
98 changed files with 10334 additions and 156 deletions
@@ -0,0 +1,34 @@
<script>
export let onMessage
// send the notification directly
// the backend is responsible for checking the permission
function _sendNotification() {
new Notification('Notification title', {
body: 'This is the notification body'
})
}
// alternatively, check the permission ourselves
function sendNotification() {
if (Notification.permission === 'default') {
Notification.requestPermission()
.then(function (response) {
if (response === 'granted') {
_sendNotification()
} else {
onMessage('Permission is ' + response)
}
})
.catch(onMessage)
} else if (Notification.permission === 'granted') {
_sendNotification()
} else {
onMessage('Permission is denied')
}
}
</script>
<button class="btn" id="notification" on:click={_sendNotification}>
Send test notification
</button>