From d30b0b28c9371e56ffe54b5a8b56087718221c1d Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 1 Jul 2020 19:15:28 +0300 Subject: [PATCH 1/7] catch localforage error and let the application work, add an alert for user to dismiss --- src/App.js | 6 ++++++ src/App.scss | 9 +++++++++ src/App.vue | 10 ++++++++++ src/i18n/en.json | 3 +++ src/main.js | 13 +++++++++++-- src/modules/instance.js | 2 +- src/modules/interface.js | 7 +++++++ 7 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 040138c9..da66fe21 100644 --- a/src/App.js +++ b/src/App.js @@ -107,6 +107,9 @@ export default { return { 'order': this.$store.state.instance.sidebarRight ? 99 : 0 } + }, + showStorageError () { + return this.$store.state.interface.storageError === 'show' } }, methods: { @@ -129,6 +132,9 @@ export default { if (changed) { this.$store.dispatch('setMobileLayout', mobileLayout) } + }, + hideStorageError () { + this.$store.dispatch('setStorageError', 'hide') } } } diff --git a/src/App.scss b/src/App.scss index f2972eda..db447f1c 100644 --- a/src/App.scss +++ b/src/App.scss @@ -806,6 +806,15 @@ nav { } } +.storage-error-notice { + text-align: center; + i { + cursor: pointer; + color: $fallback--text; + color: var(--alertErrorText, $fallback--text); + } +} + .button-icon { font-size: 1.2em; } diff --git a/src/App.vue b/src/App.vue index 7b9ad3dc..23991eac 100644 --- a/src/App.vue +++ b/src/App.vue @@ -101,6 +101,16 @@
+
+ {{ $t("errors.storage_unavailable") }} + +
-
- {{ $t("errors.storage_unavailable") }} - -
diff --git a/src/components/global_notice_list/global_notice_list.js b/src/components/global_notice_list/global_notice_list.js new file mode 100644 index 00000000..3af29c23 --- /dev/null +++ b/src/components/global_notice_list/global_notice_list.js @@ -0,0 +1,15 @@ + +const GlobalNoticeList = { + computed: { + notices () { + return this.$store.state.interface.globalNotices + } + }, + methods: { + closeNotice (notice) { + this.$store.dispatch('removeGlobalNotice', notice) + } + } +} + +export default GlobalNoticeList diff --git a/src/components/global_notice_list/global_notice_list.vue b/src/components/global_notice_list/global_notice_list.vue new file mode 100644 index 00000000..0e4285cc --- /dev/null +++ b/src/components/global_notice_list/global_notice_list.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/src/main.js b/src/main.js index a7294ea0..5bddc76e 100644 --- a/src/main.js +++ b/src/main.js @@ -62,14 +62,14 @@ const persistedStateOptions = { }; (async () => { - let persistedState - let storageError = 'none' + let storageError = false + const plugins = [pushNotifications] try { - persistedState = await createPersistedState(persistedStateOptions) + const persistedState = await createPersistedState(persistedStateOptions) + plugins.push(persistedState) } catch (e) { console.error(e) - storageError = 'show' - persistedState = _ => _ + storageError = true } const store = new Vuex.Store({ modules: { @@ -93,11 +93,13 @@ const persistedStateOptions = { polls: pollsModule, postStatus: postStatusModule }, - plugins: [persistedState, pushNotifications], + plugins, strict: false // Socket modifies itself, let's ignore this for now. // strict: process.env.NODE_ENV !== 'production' }) - store.dispatch('setStorageError', storageError) + if (storageError) { + store.dispatch('pushGlobalNotice', { messageKey: 'errors.storage_unavailable', level: 'error' }) + } afterStoreSetup({ store, i18n }) })() diff --git a/src/modules/interface.js b/src/modules/interface.js index 4b5b5b5d..338ef651 100644 --- a/src/modules/interface.js +++ b/src/modules/interface.js @@ -8,14 +8,14 @@ const defaultState = { noticeClearTimeout: null, notificationPermission: null }, - storageError: 'none', browserSupport: { cssFilter: window.CSS && window.CSS.supports && ( window.CSS.supports('filter', 'drop-shadow(0 0)') || window.CSS.supports('-webkit-filter', 'drop-shadow(0 0)') ) }, - mobileLayout: false + mobileLayout: false, + globalNotices: [] } const interfaceMod = { @@ -60,8 +60,11 @@ const interfaceMod = { state.settingsModalLoaded = true } }, - setStorageError (state, value) { - state.storageError = value + pushGlobalNotice (state, notice) { + state.globalNotices.push(notice) + }, + removeGlobalNotice (state, notice) { + state.globalNotices = state.globalNotices.filter(n => n !== notice) } }, actions: { @@ -86,8 +89,26 @@ const interfaceMod = { togglePeekSettingsModal ({ commit }) { commit('togglePeekSettingsModal') }, - setStorageError ({ commit }, value) { - commit('setStorageError', value) + pushGlobalNotice ( + { commit, dispatch }, + { + messageKey, + messageArgs = {}, + level = 'error', + timeout = 0 + }) { + const notice = { + messageKey, + messageArgs, + level + } + if (timeout) { + setTimeout(() => dispatch('removeGlobalNotice', notice), timeout) + } + commit('pushGlobalNotice', notice) + }, + removeGlobalNotice ({ commit }, notice) { + commit('removeGlobalNotice', notice) } } } diff --git a/src/services/theme_data/pleromafe.js b/src/services/theme_data/pleromafe.js index b577cfab..83c878ed 100644 --- a/src/services/theme_data/pleromafe.js +++ b/src/services/theme_data/pleromafe.js @@ -34,7 +34,8 @@ export const DEFAULT_OPACITY = { alert: 0.5, input: 0.5, faint: 0.5, - underlay: 0.15 + underlay: 0.15, + alertPopup: 0.85 } /** SUBJECT TO CHANGE IN THE FUTURE, this is all beta @@ -627,6 +628,39 @@ export const SLOT_INHERITANCE = { textColor: true }, + alertPopupError: { + depends: ['alertError'], + opacity: 'alertPopup' + }, + alertPopupErrorText: { + depends: ['alertErrorText'], + layer: 'popover', + variant: 'alertPopupError', + textColor: true + }, + + alertPopupWarning: { + depends: ['alertWarning'], + opacity: 'alertPopup' + }, + alertPopupWarningText: { + depends: ['alertWarningText'], + layer: 'popover', + variant: 'alertPopupWarning', + textColor: true + }, + + alertPopupNeutral: { + depends: ['alertNeutral'], + opacity: 'alertPopup' + }, + alertPopupNeutralText: { + depends: ['alertNeutralText'], + layer: 'popover', + variant: 'alertPopupNeutral', + textColor: true + }, + badgeNotification: '--cRed', badgeNotificationText: { depends: ['text', 'badgeNotification'], From 685ab4f33ee57e1dc4997b58314e5c0d38581e9d Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 2 Jul 2020 10:46:43 +0300 Subject: [PATCH 6/7] make the addNotice dispatch return the notice --- src/modules/interface.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/interface.js b/src/modules/interface.js index 338ef651..e31630fc 100644 --- a/src/modules/interface.js +++ b/src/modules/interface.js @@ -106,6 +106,7 @@ const interfaceMod = { setTimeout(() => dispatch('removeGlobalNotice', notice), timeout) } commit('pushGlobalNotice', notice) + return notice }, removeGlobalNotice ({ commit }, notice) { commit('removeGlobalNotice', notice) From 9cac5d94dd78ea331254307871e876da7e266a6f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 2 Jul 2020 15:17:58 +0300 Subject: [PATCH 7/7] change alert popup alpha --- src/services/theme_data/pleromafe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/theme_data/pleromafe.js b/src/services/theme_data/pleromafe.js index 83c878ed..6b25cd6f 100644 --- a/src/services/theme_data/pleromafe.js +++ b/src/services/theme_data/pleromafe.js @@ -35,7 +35,7 @@ export const DEFAULT_OPACITY = { input: 0.5, faint: 0.5, underlay: 0.15, - alertPopup: 0.85 + alertPopup: 0.95 } /** SUBJECT TO CHANGE IN THE FUTURE, this is all beta