Skip to content

Commit

Permalink
Merge pull request #2217 from pkarw/develop
Browse files Browse the repository at this point in the history
Hofix: Improved offline mode handlers
  • Loading branch information
pkarw authored Jan 16, 2019
2 parents c69f2b8 + 2ab4855 commit 9dcda73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
10 changes: 10 additions & 0 deletions core/pages/Category.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import toString from 'lodash-es/toString'

import i18n from '@vue-storefront/i18n'
import store from '@vue-storefront/store'
import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus'
import { baseFilterProductsQuery, buildFilterProductsQuery } from '@vue-storefront/core/helpers'
Expand Down Expand Up @@ -252,6 +253,15 @@ export default {
this.$store.dispatch('category/products', this.getCurrentCategoryProductQuery)
EventBus.$emitFilter('category-after-load', { store: this.$store, route: this.$route })
}
}).catch(err => {
if (err.message.indexOf('query returned empty result') > 0) {
this.$store.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t('The product, category or CMS page is not available in Offline mode. Redirecting to Home.'),
action1: { label: i18n.t('OK') }
})
this.$router.push(localizedRoute('/', currentStoreView().storeCode))
}
})
},
onUserPricesRefreshed () {
Expand Down
30 changes: 14 additions & 16 deletions core/store/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ export const quickSearchByQuery = async ({ query, start = 0, size = 50, entityT
resolve(res)
console.debug('Result from cache for ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
servedFromCache = true
} else {
if (!isOnline()) {
console.debug('No results and offline ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
res = {
items: [],
total: 0,
start: 0,
perPage: 0,
aggregations: {},
offline: true,
cache: true,
noresults: true
}
servedFromCache = true
resolve(res)
}
}
}).catch((err) => {
console.error('Cannot read cache for ' + cacheKey + ', ' + err)
Expand Down Expand Up @@ -109,6 +93,20 @@ export const quickSearchByQuery = async ({ query, start = 0, size = 50, entityT
}
}
}).catch(err => {
if (!servedFromCache) {
console.debug('No results and offline ' + cacheKey + ' (' + entityType + '), ms=' + (new Date().getTime() - benchmarkTime.getTime()))
const res = {
items: [],
total: 0,
start: 0,
perPage: 0,
aggregations: {},
offline: true,
cache: true,
noresults: true
}
resolve(res)
}
reject(err)
})
})
Expand Down

0 comments on commit 9dcda73

Please sign in to comment.