From 28a561dac02412d72b9dc32c7034c67610960383 Mon Sep 17 00:00:00 2001 From: ManjaroOne666 Date: Thu, 14 Feb 2019 11:35:38 +0000 Subject: [PATCH] update: fallbacks if no data --- store/index.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/store/index.js b/store/index.js index 6f810d4..12fffc5 100644 --- a/store/index.js +++ b/store/index.js @@ -2,10 +2,28 @@ export const state = () => ({}) export const actions = { async nuxtServerInit ({ commit }, { $axios }) { - const { siteNav, socialNav } = await $axios.$get('/api/v1/navigation') - - commit('navigation/updateSiteNav', siteNav) - commit('navigation/updateSocialNav', socialNav) + try { + const { siteNav, socialNav } = await $axios.$get('/api/v1/navigation') + if (siteNav.length < 1) { + throw new Error('siteNav empty') + } + commit('navigation/updateSiteNav', siteNav) + commit('navigation/updateSocialNav', socialNav) + } catch { + commit('navigation/updateSiteNav', [ + { "to": "/", "text": "Home", "bgImgUrl": "/img/devices--bw.jpg"}, + { "to": "/galleries", "text": "Galleries", "bgImgUrl": "/img/photo-box--bw.jpg" }, + { "to": "/services", "text": "Services", "bgImgUrl": "/img/camera--bw.jpg" }, + { "to": "/about", "text": "About Me", "bgImgUrl": "/img/silhouette--dark.jpg" }, + { "to": "/contact", "text": "Contact Me", "bgImgUrl": "/img/mail--bw.jpg" } + ]) + commit('navigation/updateSocialNav', [ + { "to": "https://www.instagram.com", "text": "Instagram", "icon": "instagram" }, + { "to": "https://www.facebook.com", "text": "Facebook", "icon": "facebook" }, + { "to": "https://twitter.com", "text": "Twitter", "icon": "twitter" }, + { "to": "https://uk.linkedin.com", "text": "LinkedIn", "icon": "linkedin" } + ]) + } } }