Notification with Service Workers now is working!

When a Notification arrives, it save into the IndexDb,
then in Vue.js call a polling to check in the db if there is a different record count.
If is different then call a get to update the notification.
This commit is contained in:
paoloar77
2022-08-07 02:01:20 +02:00
parent 66ee007e92
commit ce20daed6d
27 changed files with 411 additions and 232 deletions

View File

@@ -1,11 +1,11 @@
// import { useGlobalStore } from '@store/globalStore'
// import indexdb from './indexdb'
import indexdb from './indexdb'
import { idbKeyval as storage } from '@src/js/storage'
export default async (cmd: string, table: string, data: any = null, id = '') => {
export default async (cmd: string, table: string, data: any = null, id: any = '') => {
// const globalStore = useGlobalStore()
// const descr = data !== null ? data.descr : ''

View File

@@ -6,13 +6,13 @@ import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore'
import { idbKeyval as storage } from '../js/storage.js'
function writeConfigIndexDb(context: any, data: any) {
function writeConfigIndexDb(data: any) {
// console.log('writeConfigIndexDb', data)
storage.setdata('config', data)
}
function saveConfigIndexDb(context: any) {
function saveConfigIndexDb() {
const userStore = useUserStore()
const data: ICfgData = {
@@ -22,10 +22,10 @@ function saveConfigIndexDb(context: any) {
userId: userStore.my._id,
}
writeConfigIndexDb('config', data)
writeConfigIndexDb(data)
}
async function readfromIndexDbToState(context: any, table: string) {
async function readfromIndexDbToState(table: string) {
console.log('*** readfromIndexDbToState ***', table)
return storage.getalldata(table)
@@ -79,13 +79,13 @@ function consolelogpao(str: string, str2 = '', str3 = '') {
// Todos.mutations.setTestpao(str + str2 + str3)
}
export default async (context: any, cmd: string, table: string, datakey: any = null, id = '') => {
export default async (cmd: string, table: string, datakey: any = null, id: any = '') => {
const globalStore = useGlobalStore()
try {
// console.log('TABLE', table, 'cmd', cmd)
if (cmd === 'loadapp') {
// ****** LOAD APP AL CARICAMENTO ! *******
return saveConfigIndexDb(context)
return saveConfigIndexDb()
}
if (cmd === 'write') {
if (globalStore) {
@@ -94,7 +94,7 @@ export default async (context: any, cmd: string, table: string, datakey: any = n
return await storage.setdata(table, datakey)
}
if (cmd === 'updatefromIndexedDbToState') {
return await readfromIndexDbToState(context, table)
return await readfromIndexDbToState(table)
}
if (cmd === 'readall') {
if (globalStore) {
@@ -104,7 +104,9 @@ export default async (context: any, cmd: string, table: string, datakey: any = n
return await storage.getalldata(table)
}
if (cmd === 'count') {
return await storage.count(table)
let contatore = await storage.count(table)
// console.log('COUNT:', table, contatore)
return contatore
}
if (cmd === 'read') {
if (globalStore) {