Files
mealie/frontend/src/store/store.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-12-24 16:37:38 -09:00
import Vue from "vue";
import Vuex from "vuex";
import api from "../api";
import createPersistedState from "vuex-persistedstate";
import userSettings from "./modules/userSettings";
2020-12-24 16:37:38 -09:00
Vue.use(Vuex);
const store = new Vuex.Store({
plugins: [createPersistedState({
paths: ['userSettings']
})],
modules: {
userSettings
},
2020-12-24 16:37:38 -09:00
state: {
// Snackbar
snackActive: false,
snackText: "",
snackType: "warning",
// All Recipe Data Store
recentRecipes: [],
allRecipes: [],
},
mutations: {
setSnackBar(state, payload) {
state.snackText = payload.text;
state.snackType = payload.type;
state.snackActive = true;
},
setSnackActive(state, payload) {
state.snackActive = payload;
},
setRecentRecipes(state, payload) {
state.recentRecipes = payload;
},
},
actions: {
async requestRecentRecipes() {
const keys = [
"name",
"slug",
"image",
"description",
"dateAdded",
"rating",
];
const payload = await api.recipes.allByKeys(keys);
this.commit("setRecentRecipes", payload);
},
},
getters: {
//
getSnackText: (state) => state.snackText,
getSnackActive: (state) => state.snackActive,
getSnackType: (state) => state.snackType,
getRecentRecipes: (state) => state.recentRecipes,
},
});
export default store;
export { store };