mirror of
https://github.com/romancm/gamebrary
synced 2025-02-16 11:08:24 +00:00
Moved save settings to actions
This commit is contained in:
parent
622dd14a26
commit
86396dd8c4
4 changed files with 22 additions and 25 deletions
18
src/App.vue
18
src/App.vue
|
@ -24,7 +24,6 @@ import NavHeader from '@/components/NavHeader';
|
||||||
import Toast from '@/components/Toast';
|
import Toast from '@/components/Toast';
|
||||||
import firebase from 'firebase/app';
|
import firebase from 'firebase/app';
|
||||||
import { mapState } from 'vuex';
|
import { mapState } from 'vuex';
|
||||||
import { debounce } from 'lodash';
|
|
||||||
import 'firebase/auth';
|
import 'firebase/auth';
|
||||||
import 'firebase/firestore';
|
import 'firebase/firestore';
|
||||||
import 'firebase/storage';
|
import 'firebase/storage';
|
||||||
|
@ -105,14 +104,12 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$bus.$on('SAVE_SETTINGS', this.saveSettings);
|
|
||||||
this.$bus.$on('SAVE_TAGS', this.saveTags);
|
this.$bus.$on('SAVE_TAGS', this.saveTags);
|
||||||
this.$bus.$on('SAVE_NOTES', this.saveNotes);
|
this.$bus.$on('SAVE_NOTES', this.saveNotes);
|
||||||
this.init();
|
this.init();
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.$bus.$off('SAVE_SETTINGS');
|
|
||||||
this.$bus.$off('SAVE_TAGS');
|
this.$bus.$off('SAVE_TAGS');
|
||||||
this.$bus.$off('SAVE_NOTES');
|
this.$bus.$off('SAVE_NOTES');
|
||||||
},
|
},
|
||||||
|
@ -170,21 +167,6 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
saveSettings: debounce(
|
|
||||||
// eslint-disable-next-line
|
|
||||||
function(settings) {
|
|
||||||
// TOOD: move to actions
|
|
||||||
db.collection('settings').doc(this.user.uid).set(settings, { merge: true })
|
|
||||||
.then(() => {
|
|
||||||
this.$store.commit('SET_SETTINGS', settings);
|
|
||||||
this.$bus.$emit('TOAST', { message: 'Settings saved' });
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.$bus.$emit('TOAST', { message: 'There was an error saving your settings', type: 'error' });
|
|
||||||
this.$router.push({ name: 'sessionExpired' });
|
|
||||||
});
|
|
||||||
}, 500),
|
|
||||||
|
|
||||||
saveTags(tags, force) {
|
saveTags(tags, force) {
|
||||||
if (tags) {
|
if (tags) {
|
||||||
// TOOD: move to actions
|
// TOOD: move to actions
|
||||||
|
|
|
@ -109,12 +109,8 @@ export default {
|
||||||
wallpapers: this.wallpapers,
|
wallpapers: this.wallpapers,
|
||||||
};
|
};
|
||||||
|
|
||||||
const db = firebase.firestore();
|
this.$store.dispatch('SAVE_SETTINGS', settings)
|
||||||
|
|
||||||
// TOOD: move to actions
|
|
||||||
db.collection('settings').doc(this.user.uid).set(settings)
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$store.commit('SET_SETTINGS', settings);
|
|
||||||
this.$bus.$emit('TOAST', { message: 'Settings saved' });
|
this.$bus.$emit('TOAST', { message: 'Settings saved' });
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
})
|
})
|
||||||
|
|
|
@ -102,8 +102,14 @@ export default {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
save() {
|
save() {
|
||||||
// TODO: call action directly
|
this.$store.dispatch('SAVE_SETTINGS', this.localSettings)
|
||||||
this.$bus.$emit('SAVE_SETTINGS', this.localSettings);
|
.then(() => {
|
||||||
|
this.$bus.$emit('TOAST', { message: 'Settings saved' });
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.$bus.$emit('TOAST', { message: 'There was an error saving your settings', type: 'error' });
|
||||||
|
this.$router.push({ name: 'sessionExpired' });
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteAccount() {
|
deleteAccount() {
|
||||||
|
|
|
@ -24,6 +24,19 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
SAVE_SETTINGS({ commit, state }, settings) {
|
||||||
|
const db = firebase.firestore();
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.collection('settings').doc(state.user.uid).set(settings, { merge: true })
|
||||||
|
.then(() => {
|
||||||
|
commit('SET_SETTINGS', settings);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
LOAD_RELEASES({ commit }) {
|
LOAD_RELEASES({ commit }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.get('https://api.github.com/repos/romancm/gamebrary/releases')
|
axios.get('https://api.github.com/repos/romancm/gamebrary/releases')
|
||||||
|
|
Loading…
Add table
Reference in a new issue