Moved snackbars to their own store and component
This commit is contained in:
41
app/imports/ui/components/snackbars/Snackbars.vue
Normal file
41
app/imports/ui/components/snackbars/Snackbars.vue
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<v-snackbar
|
||||||
|
v-if="snackbar"
|
||||||
|
:key="snackbar.text"
|
||||||
|
auto-height
|
||||||
|
bottom
|
||||||
|
:value="true"
|
||||||
|
:timeout="0"
|
||||||
|
>
|
||||||
|
{{ snackbar.text }}
|
||||||
|
<v-btn
|
||||||
|
v-if="snackbar.callback"
|
||||||
|
flat
|
||||||
|
icon
|
||||||
|
@click="snackbar.callback"
|
||||||
|
>
|
||||||
|
<v-icon>{{ snackbar.callbackName }}</v-icon>
|
||||||
|
</v-btn>
|
||||||
|
<v-btn
|
||||||
|
v-if="snackbar.showCloseButton"
|
||||||
|
flat
|
||||||
|
icon
|
||||||
|
@click="$store.dispatch('closeSnackbar')"
|
||||||
|
>
|
||||||
|
<v-icon>close</v-icon>
|
||||||
|
</v-btn>
|
||||||
|
</v-snackbar>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
snackbar(){
|
||||||
|
return this.$store.state.snackbars.snackbars[0];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="css" scoped>
|
||||||
|
</style>
|
||||||
47
app/imports/ui/components/snackbars/snackboxStore.js
Normal file
47
app/imports/ui/components/snackbars/snackboxStore.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
const snackbarStore = {
|
||||||
|
state: {
|
||||||
|
snackbars: [],
|
||||||
|
snackbarTimout: undefined,
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
addSnackbar(state, value){
|
||||||
|
state.snackbars.push(value)
|
||||||
|
},
|
||||||
|
closeCurrentSnackbar (state){
|
||||||
|
state.snackbars.shift();
|
||||||
|
},
|
||||||
|
cancelSnackbarTimeout (state){
|
||||||
|
if(state.snackbarTimout){
|
||||||
|
clearTimeout(state.snackbarTimout);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setSnackbarTimout(state, value){
|
||||||
|
state.snackbarTimout = value;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
snackbar({dispatch, commit}, value){
|
||||||
|
// value = {
|
||||||
|
// text,
|
||||||
|
// showCloseButton,
|
||||||
|
// callback,
|
||||||
|
// callbackName
|
||||||
|
// }
|
||||||
|
commit('addSnackbar', value);
|
||||||
|
commit('setSnackbarTimout', setTimeout(() => {
|
||||||
|
dispatch('closeSnackbar');
|
||||||
|
}, 5000));
|
||||||
|
},
|
||||||
|
closeSnackbar({dispatch, commit, state}){
|
||||||
|
commit('closeCurrentSnackbar');
|
||||||
|
commit('cancelSnackbarTimeout');
|
||||||
|
if (state.snackbars.length){
|
||||||
|
commit('setSnackbarTimout', setTimeout(() => {
|
||||||
|
dispatch('closeSnackbar');
|
||||||
|
}, 5000));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default snackbarStore;
|
||||||
@@ -93,9 +93,6 @@
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data(){return {
|
|
||||||
snackbars: [],
|
|
||||||
}},
|
|
||||||
reactiveProvide: {
|
reactiveProvide: {
|
||||||
name: 'context',
|
name: 'context',
|
||||||
include: ['creature', 'editPermission'],
|
include: ['creature', 'editPermission'],
|
||||||
@@ -124,10 +121,10 @@
|
|||||||
added(doc){
|
added(doc){
|
||||||
if (!that.$subReady.singleCharacter) return;
|
if (!that.$subReady.singleCharacter) return;
|
||||||
if (that.$store.state.rightDrawer) return;
|
if (that.$store.state.rightDrawer) return;
|
||||||
if (that.snackbars.some(o => o._id === doc._id)) return;
|
if (that.$store.state.snackbars.snackbars.some(o => o._id === doc._id)) return;
|
||||||
doc.open = true;
|
that.$store.dispatch('snackbar', {
|
||||||
that.$store.commit('snackbar', {
|
text: doc.text,
|
||||||
doc
|
showCloseButton: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -67,31 +67,7 @@
|
|||||||
name="rightDrawer"
|
name="rightDrawer"
|
||||||
/>
|
/>
|
||||||
<dialog-stack />
|
<dialog-stack />
|
||||||
<v-snackbar
|
<snackbars />
|
||||||
v-for="snackbar in snackbars"
|
|
||||||
:key="snackbar._id"
|
|
||||||
:value="snackbar.open"
|
|
||||||
auto-height
|
|
||||||
bottom
|
|
||||||
>
|
|
||||||
{{ snackbar.text.split(/\n+/).pop() }}
|
|
||||||
<v-btn
|
|
||||||
v-if="snackbar.callback"
|
|
||||||
flat
|
|
||||||
icon
|
|
||||||
@click="snackbar.callback"
|
|
||||||
>
|
|
||||||
<v-icon>{{ snackbar.callbackName }}</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
<v-btn
|
|
||||||
v-if="snackbar.showCloseButton"
|
|
||||||
flat
|
|
||||||
icon
|
|
||||||
@click="snackbar.open = false"
|
|
||||||
>
|
|
||||||
<v-icon>close</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-snackbar>
|
|
||||||
</v-app>
|
</v-app>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -101,11 +77,13 @@
|
|||||||
import DialogStack from '/imports/ui/dialogStack/DialogStack.vue';
|
import DialogStack from '/imports/ui/dialogStack/DialogStack.vue';
|
||||||
import { theme, darkTheme } from '/imports/ui/theme.js';
|
import { theme, darkTheme } from '/imports/ui/theme.js';
|
||||||
import { mapMutations } from 'vuex';
|
import { mapMutations } from 'vuex';
|
||||||
|
import Snackbars from '/imports/ui/components/snackbars/Snackbars.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
DialogStack,
|
DialogStack,
|
||||||
|
Snackbars,
|
||||||
},
|
},
|
||||||
data(){return {
|
data(){return {
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Vuex from 'vuex';
|
import Vuex from 'vuex';
|
||||||
import dialogStackStore from '/imports/ui/dialogStack/dialogStackStore.js';
|
import dialogStackStore from '/imports/ui/dialogStack/dialogStackStore.js';
|
||||||
|
import snackbarStore from '/imports/ui/components/snackbars/snackboxStore.js';
|
||||||
|
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
strict: process.env.NODE_ENV !== 'production',
|
strict: process.env.NODE_ENV !== 'production',
|
||||||
modules: {
|
modules: {
|
||||||
dialogStack: dialogStackStore,
|
dialogStack: dialogStackStore,
|
||||||
|
snackbars: snackbarStore,
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
drawer: undefined,
|
drawer: undefined,
|
||||||
rightDrawer: undefined,
|
rightDrawer: undefined,
|
||||||
pageTitle: undefined,
|
pageTitle: undefined,
|
||||||
snackbars: [],
|
|
||||||
snackbarTimout: undefined,
|
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
toggleDrawer (state) {
|
toggleDrawer (state) {
|
||||||
@@ -32,43 +32,7 @@ const store = new Vuex.Store({
|
|||||||
state.pageTitle = value;
|
state.pageTitle = value;
|
||||||
document.title = value;
|
document.title = value;
|
||||||
},
|
},
|
||||||
addSnackbar(state, value){
|
|
||||||
value.open = true;
|
|
||||||
state.snackbars.push(value)
|
|
||||||
},
|
|
||||||
closeCurrentSnackbar (state){
|
|
||||||
state.snackbars.shift();
|
|
||||||
},
|
|
||||||
cancelSnackbarTimeout (state){
|
|
||||||
if(state.snackbarTimout){
|
|
||||||
clearTimeout(state.snackbarTimout);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setSnackbarTimout(state, value){
|
|
||||||
state.snackbarTimout = value;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
actions: {
|
|
||||||
snackbar({commit}, value){
|
|
||||||
// value = {
|
|
||||||
// text,
|
|
||||||
// showCloseButton,
|
|
||||||
// callback,
|
|
||||||
// callbackName
|
|
||||||
// }
|
|
||||||
commit('addSnackbar', value);
|
|
||||||
},
|
|
||||||
closeSnackbar({dispatch, commit, state}){
|
|
||||||
commit('closeCurrentSnackbar');
|
|
||||||
commit('cancelSnackbarTimeout');
|
|
||||||
if (state.snackbars.length){
|
|
||||||
commit('setSnackbarTimout');
|
|
||||||
state.snackbarTimout = setTimeout(() => {
|
|
||||||
dispatch('closeSnackbar');
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default store;
|
export default store;
|
||||||
|
|||||||
Reference in New Issue
Block a user