diff options
| author | Kana <[email protected]> | 2020-12-24 21:41:24 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-24 21:41:24 +0900 |
| commit | 2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab (patch) | |
| tree | dbf2b2cad342f31849a62089dedd40165758af86 /src/site/plugins | |
| parent | Enable deleting files with the API key (diff) | |
| parent | bug: fix showlist resetting itself every time the page is changed (diff) | |
| download | host.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.tar.xz host.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.zip | |
Merge pull request #228 from Zephyrrus/begone_trailing_commas
Merge own dev branch into main dev branch
Diffstat (limited to 'src/site/plugins')
| -rw-r--r-- | src/site/plugins/axios.js | 34 | ||||
| -rw-r--r-- | src/site/plugins/buefy.js | 1 | ||||
| -rw-r--r-- | src/site/plugins/flexsearch.js | 3 | ||||
| -rw-r--r-- | src/site/plugins/handler.js | 25 | ||||
| -rw-r--r-- | src/site/plugins/notifier.js | 25 | ||||
| -rw-r--r-- | src/site/plugins/nuxt-client-init.js | 2 |
6 files changed, 78 insertions, 12 deletions
diff --git a/src/site/plugins/axios.js b/src/site/plugins/axios.js index cc6d98e..98bec5c 100644 --- a/src/site/plugins/axios.js +++ b/src/site/plugins/axios.js @@ -1,18 +1,32 @@ -export default function({ $axios, store }) { +export default function ({ $axios, store }) { $axios.setHeader('accept', 'application/vnd.lolisafe.json'); - $axios.onRequest(config => { - if (store.state.token) { - config.headers.common['Authorization'] = `bearer ${store.state.token}`; + + $axios.onRequest((config) => { + if (store.state.auth.token) { + config.headers.common.Authorization = `bearer ${store.state.auth.token}`; } }); - $axios.onError(error => { - if (process.env.development) console.error('[AXIOS Error]', error); + $axios.onError((error) => { + if (process.env.NODE_ENV !== 'production') console.error('[AXIOS Error]', error); if (process.browser) { - store.dispatch('alert', { - text: error.response.data.message, - error: true - }); + if (process.env.NODE_ENV !== 'production') { + if (error.response?.data?.message) { + store.dispatch('alert/set', { + text: error.response.data.message, + error: true + }); + } else { + store.dispatch('alert/set', { + text: `[AXIOS]: ${error.message}`, + error: true + }); + } + } + + /* if (error.response?.data?.message.indexOf('Token expired') !== -1) { + store.dispatch('auth/logout'); + } */ } }); } diff --git a/src/site/plugins/buefy.js b/src/site/plugins/buefy.js index 58bf28f..f3f7552 100644 --- a/src/site/plugins/buefy.js +++ b/src/site/plugins/buefy.js @@ -1,4 +1,5 @@ import Vue from 'vue'; import Buefy from 'buefy'; +// import 'buefy/dist/buefy.css'; Vue.use(Buefy); diff --git a/src/site/plugins/flexsearch.js b/src/site/plugins/flexsearch.js index 595b180..1c06c8d 100644 --- a/src/site/plugins/flexsearch.js +++ b/src/site/plugins/flexsearch.js @@ -1,11 +1,12 @@ import Vue from 'vue'; import FlexSearch from 'flexsearch'; + const search = new FlexSearch('speed'); // https://github.com/nextapps-de/flexsearch Vue.prototype.$search = { - items: async items => { + items: async (items) => { await search.clear(); await search.add(items); }, diff --git a/src/site/plugins/handler.js b/src/site/plugins/handler.js new file mode 100644 index 0000000..7933eab --- /dev/null +++ b/src/site/plugins/handler.js @@ -0,0 +1,25 @@ +import AlertTypes from '~/constants/alertTypes'; + +export default ({ store }, inject) => { + inject('handler', { + async executeAction(action, param) { + try { + const response = await store.dispatch(action, param); + + store.commit('alert/set', { + message: response?.message ?? 'Executed sucesfully', + type: AlertTypes.SUCCESS + }); + + return response; + } catch (e) { + store.commit('alert/set', { + message: e.message, + type: AlertTypes.ERROR + }); + + return null; + } + } + }); +}; diff --git a/src/site/plugins/notifier.js b/src/site/plugins/notifier.js new file mode 100644 index 0000000..465df6d --- /dev/null +++ b/src/site/plugins/notifier.js @@ -0,0 +1,25 @@ +import AlertTypes from '~/constants/alertTypes'; + +export default ({ store }, inject) => { + inject('notifier', { + showMessage({ message = '', type = '', snackbar = false }) { + store.commit('alert/set', { message, type, snackbar }); + }, + message(message, snackbar) { + this.showMessage({ message, type: AlertTypes.PRIMARY, snackbar }); + }, + info(message, snackbar) { + this.showMessage({ message, type: AlertTypes.INFO, snackbar }); + }, + warning(message, snackbar) { + this.showMessage({ message, type: AlertTypes.WARNING, snackbar }); + }, + success(message, snackbar) { + this.showMessage({ message, type: AlertTypes.SUCCESS, snackbar }); + }, + error(message, snackbar) { + this.showMessage({ message, type: AlertTypes.ERROR, snackbar }); + }, + types: AlertTypes + }); +}; diff --git a/src/site/plugins/nuxt-client-init.js b/src/site/plugins/nuxt-client-init.js index 4b10dcd..01f33ff 100644 --- a/src/site/plugins/nuxt-client-init.js +++ b/src/site/plugins/nuxt-client-init.js @@ -1,3 +1,3 @@ -export default async ctx => { +export default async (ctx) => { await ctx.store.dispatch('nuxtClientInit', ctx); }; |