-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21] implements the notification when notes are overdue
- Loading branch information
Showing
9 changed files
with
155 additions
and
4 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,36 @@ | ||
<template> | ||
<div> | ||
<v-snackbar :value="true" | ||
right top | ||
color="primary" | ||
class="text-center" | ||
:timeout="0" | ||
v-for="note of overdueNotes" :key="note.id"> | ||
<h3><v-icon>alarm</v-icon> {{note.title}}</h3> | ||
<v-btn icon @click="removeAlarm(note.id)"> | ||
<v-icon>close</v-icon> | ||
</v-btn> | ||
</v-snackbar> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters, mapMutations } from 'vuex'; | ||
export default { | ||
name: "OverdueNotifications", | ||
computed: { | ||
...mapGetters({ | ||
overdueNotes: 'note/getOverdueNotes', | ||
}), | ||
}, | ||
methods: { | ||
...mapMutations({ | ||
removeAlarm: 'note/removeOverdueAlarm' | ||
}), | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default function ({ isHMR, app, store, route, params, error, redirect }) { | ||
// check if the browser supports notifications | ||
if ("Notification" in window) { | ||
store.commit('settings/setNotificationSupported', true) | ||
} else { | ||
//notification are not supported! | ||
return | ||
} | ||
|
||
if (Notification.permission === "granted"){ | ||
store.commit('settings/setNotificationGranted', true) | ||
} else if (Notification.permission !== 'denied') { | ||
Notification.requestPermission((permission) => { | ||
store.commit('settings/setNotificationGranted', permission === "granted") | ||
}) | ||
} | ||
} |
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,35 @@ | ||
const TICKER_TIME=60000 //1min | ||
|
||
const activeNotifications = {} | ||
|
||
const checkOverdue = (store, env) => { | ||
store.dispatch('note/checkOverdueNotes') | ||
.then(() => { | ||
if(store.getters['settings/isNotificationEnabled']){ | ||
for(let overdueNote of store.getters['note/getOverdueNotes']){ | ||
if(!activeNotifications[overdueNote.id]) { | ||
activeNotifications[overdueNote.id] = new Notification(overdueNote.title, { | ||
icon: `${env.routerBase}icon.png`, | ||
tag: overdueNote.id, | ||
requireInteraction: true, | ||
}) | ||
activeNotifications[overdueNote.id].onclick = () => { | ||
store.commit('note/removeOverdueAlarm', overdueNote.id) | ||
delete activeNotifications[overdueNote.id] | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
setTimeout(() => { | ||
checkOverdue(store, env); | ||
}, TICKER_TIME); | ||
} | ||
|
||
export default function ({store, env}) { | ||
//check but dont blocking! | ||
setTimeout(() => { | ||
checkOverdue(store, env) | ||
}, 1) | ||
} |
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