Files
mealie/frontend/src/store/store.js
Hayden 8221c36a89 Revert "v0.2.1 (#157)" (#158)
This reverts commit a899f46464.
2021-02-10 19:39:46 -09:00

77 lines
1.6 KiB
JavaScript

import Vue from "vue";
import Vuex from "vuex";
import api from "../api";
import createPersistedState from "vuex-persistedstate";
import userSettings from "./modules/userSettings";
import language from "./modules/language";
import homePage from "./modules/homePage";
Vue.use(Vuex);
const store = new Vuex.Store({
plugins: [
createPersistedState({
paths: ["userSettings", "language", "homePage"],
}),
],
modules: {
userSettings,
language,
homePage,
},
state: {
// Home Page Settings
// 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 };