Fix: Todo Multi refresh ...
fix some promises problem
This commit is contained in:
@@ -123,10 +123,10 @@ namespace Actions {
|
||||
function createPushSubscription(context) {
|
||||
|
||||
// If Already subscribed, don't send to the Server DB
|
||||
if (state.wasAlreadySubOnDb) {
|
||||
// console.log('wasAlreadySubOnDb!')
|
||||
return
|
||||
}
|
||||
// if (state.wasAlreadySubOnDb) {
|
||||
// // console.log('wasAlreadySubOnDb!')
|
||||
// return
|
||||
// }
|
||||
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
return
|
||||
@@ -141,7 +141,7 @@ namespace Actions {
|
||||
let reg
|
||||
const mykey = process.env.PUBLICKEY_PUSH
|
||||
const mystate = state
|
||||
navigator.serviceWorker.ready
|
||||
return navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
reg = swreg
|
||||
return swreg.pushManager.getSubscription()
|
||||
@@ -149,11 +149,13 @@ namespace Actions {
|
||||
.then(function (subscription) {
|
||||
mystate.wasAlreadySubscribed = !(subscription === null)
|
||||
|
||||
if (mystate.wasAlreadySubOnDb) {
|
||||
// console.log('User is already SAVED Subscribe on DB!')
|
||||
return null
|
||||
if (mystate.wasAlreadySubscribed) {
|
||||
console.log('User is already SAVED Subscribe on DB!')
|
||||
// return null
|
||||
return subscription
|
||||
} else {
|
||||
// Create a new subscription
|
||||
console.log('Create a new subscription')
|
||||
let convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
return reg.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
@@ -165,7 +167,7 @@ namespace Actions {
|
||||
saveNewSubscriptionToServer(context, newSub)
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err)
|
||||
console.log('ERR createPushSubscription:', err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -178,11 +180,16 @@ namespace Actions {
|
||||
console.log('saveSubscriptionToServer: ', newSub)
|
||||
// console.log('context', context)
|
||||
|
||||
const options = {
|
||||
title: translate('notification.title_subscribed'),
|
||||
content: translate('notification.subscribed'),
|
||||
openUrl: '/'
|
||||
}
|
||||
let options = null
|
||||
|
||||
// If is not already stored in DB, then show the message to the user.
|
||||
// if (!state.wasAlreadySubscribed) {
|
||||
options = {
|
||||
title: translate('notification.title_subscribed'),
|
||||
content: translate('notification.subscribed'),
|
||||
openUrl: '/'
|
||||
}
|
||||
// }
|
||||
|
||||
let myres = {
|
||||
options: { ...options },
|
||||
@@ -252,20 +259,22 @@ namespace Actions {
|
||||
globalroutines(null, 'clearalldata', table, null)
|
||||
})
|
||||
|
||||
// REMOVE ALL SUBSCRIPTION
|
||||
console.log('REMOVE ALL SUBSCRIPTION...')
|
||||
await navigator.serviceWorker.ready.then(function (reg) {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then(function (subscription) {
|
||||
console.log(' Found Subscription...')
|
||||
subscription.unsubscribe().then(function (successful) {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch(function (e) {
|
||||
// Unsubscription failed
|
||||
if ('serviceWorker' in navigator) {
|
||||
// REMOVE ALL SUBSCRIPTION
|
||||
console.log('REMOVE ALL SUBSCRIPTION...')
|
||||
await navigator.serviceWorker.ready.then(function (reg) {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then(function (subscription) {
|
||||
console.log(' Found Subscription...')
|
||||
subscription.unsubscribe().then(function (successful) {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch(function (e) {
|
||||
// Unsubscription failed
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
await deleteSubscriptionToServer(context)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const state: ITodosState = {
|
||||
networkDataReceived: false,
|
||||
todos: [],
|
||||
todos_changed: 1,
|
||||
reload_fromServer: false,
|
||||
reload_fromServer: 0,
|
||||
testpao: 'Test',
|
||||
insidePending: false
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace Mutations {
|
||||
function setTodos_changed(state: ITodosState) {
|
||||
state.todos_changed++
|
||||
mutations.setTestpao('Cambiato : ' + String(state.todos_changed))
|
||||
console.log('******* state.todos_changed', state.todos_changed)
|
||||
// console.log('******* state.todos_changed', state.todos_changed)
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
@@ -78,10 +78,10 @@ namespace Actions {
|
||||
|
||||
let count = await checkPendingMsg(null)
|
||||
if (count > 0) {
|
||||
return navigator.serviceWorker.ready
|
||||
return await navigator.serviceWorker.ready
|
||||
.then(function (sw) {
|
||||
|
||||
globalroutines(null, 'readall', 'swmsg')
|
||||
return globalroutines(null, 'readall', 'swmsg')
|
||||
.then(function (arr_recmsg) {
|
||||
// let recclone = [...arr_recmsg]
|
||||
if (arr_recmsg.length > 0) {
|
||||
@@ -119,11 +119,11 @@ namespace Actions {
|
||||
.then(ris => {
|
||||
if (ris) {
|
||||
console.log('risPending = ', ris)
|
||||
const result = sendSwMsgIfAvailable()
|
||||
return sendSwMsgIfAvailable()
|
||||
.then(something => {
|
||||
if (something) {
|
||||
// Refresh data
|
||||
waitAndRefreshData(context)
|
||||
return waitAndRefreshData(context)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -204,7 +204,7 @@ namespace Actions {
|
||||
Todos.mutations.setTodos_changed()
|
||||
}
|
||||
|
||||
console.log('********** res', res, 'state.todos', state.todos, 'checkPending', checkPending)
|
||||
console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending)
|
||||
|
||||
// After Login will store into the indexedDb...
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Mutations {
|
||||
state.verified_email = data.verified_email
|
||||
state.category = data.categorySel
|
||||
resetArrToken(state.tokens)
|
||||
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: state.x_auth_token, date_login: new Date() })
|
||||
state.tokens.push({ access: 'auth', token: state.x_auth_token, date_login: new Date() })
|
||||
// console.log('state.tokens', state.tokens)
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Mutations {
|
||||
if (!state.tokens) {
|
||||
state.tokens = []
|
||||
}
|
||||
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: data.x_auth_token, data_login: new Date() })
|
||||
state.tokens.push({ access: 'auth', token: data.x_auth_token, data_login: new Date() })
|
||||
}
|
||||
|
||||
function setServerCode(state: IUserState, num: number) {
|
||||
@@ -135,7 +135,7 @@ namespace Mutations {
|
||||
|
||||
// Take only the others access (from others Browser)
|
||||
return arrtokens.filter((token: IToken) => {
|
||||
return token.access !== 'auth ' + navigator.userAgent
|
||||
return token.access !== 'auth'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -368,14 +368,16 @@ namespace Actions {
|
||||
|
||||
let sub = null
|
||||
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
const sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
.catch(e => {
|
||||
sub = null
|
||||
})
|
||||
if ('serviceWorker' in navigator) {
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
const sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
.catch(e => {
|
||||
sub = null
|
||||
})
|
||||
}
|
||||
|
||||
const options = {
|
||||
title: translate('notification.title_subscribed'),
|
||||
|
||||
Reference in New Issue
Block a user