-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): Notify user for new message through browser API
Check if notifications API is supported Add a switch allowing the user to received notifications when new message is received Close #59
- Loading branch information
Showing
5 changed files
with
222 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div v-if="isNotificationsSupported"> | ||
<o-switch v-model="hasNotificationsEnabledSwitch" title="Allow the browser to send you notifications when you miss messages">Notifications</o-switch> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState, mapActions } from 'pinia' | ||
import { useStore } from '@/store' | ||
import { useWebNotification } from '@vueuse/core' | ||
const lsNotificationKey = 'hasNotificationsEnabled' | ||
export default { | ||
name: 'NotificationsSwitch', | ||
setup() { | ||
const { isSupported } = useWebNotification() | ||
return { isNotificationsSupported: isSupported } | ||
}, | ||
computed: { | ||
...mapState(useStore, [ | ||
'hasNotificationsEnabled', | ||
]), | ||
hasNotificationsEnabledSwitch: { | ||
get() { | ||
return this.hasNotificationsEnabled | ||
}, | ||
set(hasNotificationsEnabled) { | ||
if (hasNotificationsEnabled) { | ||
localStorage.setItem(lsNotificationKey, hasNotificationsEnabled) | ||
} else { | ||
localStorage.removeItem(lsNotificationKey) | ||
} | ||
this.setNotificationStatus(hasNotificationsEnabled) | ||
}, | ||
}, | ||
}, | ||
mounted () { | ||
const hasNotificationsEnabled = localStorage.getItem(lsNotificationKey) | ||
if (hasNotificationsEnabled) { | ||
this.setNotificationStatus(hasNotificationsEnabled) | ||
} | ||
}, | ||
methods: { | ||
...mapActions(useStore, ['setNotificationStatus']), | ||
}, | ||
} | ||
</script> |
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