set initial selection for category button

This commit is contained in:
hay-kot 2021-03-28 10:30:41 -08:00
commit 81c74d407f
9 changed files with 42 additions and 34 deletions

View file

@ -78,6 +78,7 @@ export default {
this.$store.dispatch("requestRecentRecipes");
this.$store.dispatch("refreshToken");
this.$store.dispatch("requestCurrentGroup");
this.$store.dispatch("requestCategories");
this.darkModeSystemCheck();
this.darkModeAddEventListener();
},

View file

@ -10,7 +10,7 @@ const categoryURLs = {
};
export default {
async get_all() {
async getAll() {
let response = await apiReq.get(categoryURLs.get_all);
return response.data;
},

View file

@ -16,7 +16,6 @@ const mealPlanURLs = {
export default {
async create(postBody) {
console.log(postBody);
let response = await apiReq.post(mealPlanURLs.create, postBody);
return response;
},

View file

@ -141,7 +141,6 @@ export default {
return numbers;
},
open(importData) {
console.log(importData);
this.recipeData = importData.recipeImports;
this.themeData = importData.themeImports;
this.settingsData = importData.settingsImports;

View file

@ -12,14 +12,18 @@
<v-spacer></v-spacer>
</v-app-bar>
<v-form ref="newGroup" @submit="submitForm">
<v-form ref="newGroup" @submit.prevent="submitForm">
<v-card-text>
<v-text-field
autofocus
v-model="page.name"
label="Page Name"
></v-text-field>
<CategorySelector v-model="page.categories" />
<CategorySelector
v-model="page.categories"
ref="categoryFormSelector"
@mounted="catMounted = true"
/>
</v-card-text>
<v-card-actions>
@ -46,6 +50,7 @@ export default {
},
data() {
return {
catMounted: false,
title: "",
buttonText: "",
create: false,
@ -57,16 +62,9 @@ export default {
},
};
},
mounted() {
this.page = {
name: "",
position: 0,
categories: [],
};
},
watch: {
page() {
console.log(this.page);
catMounted(val) {
if (val) this.pushSelected();
},
},
methods: {
@ -76,6 +74,11 @@ export default {
this.buttonText = parameters.buttonText;
this.title = parameters.title;
this.pageDialog = true;
if (this.catMounted) this.pushSelected();
},
pushSelected() {
this.$refs.categoryFormSelector.setInit(this.page.categories);
},
async submitForm() {
if (this.create) {

View file

@ -38,7 +38,7 @@
</v-icon>
<v-toolbar-title class="headline">
{{$t('settings.homepage.home-page-sections')}}
{{ $t("settings.homepage.home-page-sections") }}
</v-toolbar-title>
<v-spacer></v-spacer>
@ -80,7 +80,7 @@
</v-icon>
<v-toolbar-title class="headline">
{{$t('settings.homepage.all-categories')}}
{{ $t("settings.homepage.all-categories") }}
</v-toolbar-title>
<v-spacer></v-spacer>
@ -153,13 +153,12 @@ export default {
},
computed: {
allCategories() {
return this.$store.getters.getCategories;
return this.$store.getters.getAllCategories;
},
},
methods: {
writeLang(val) {
console.log(val);
this.settings.language = val;
},
deleteCategoryfromDatabase(category) {

View file

@ -16,7 +16,7 @@
</template>
<script>
import api from "@/api";
const MOUNTED_EVENT = "mounted";
export default {
props: {
value: Array,
@ -24,21 +24,24 @@ export default {
data() {
return {
selected: [],
allCategories: [],
};
},
watch: {
value() {
this.selected = this.value;
mounted() {
this.$emit(MOUNTED_EVENT);
},
computed: {
allCategories() {
return this.$store.getters.getAllCategories;
},
async created() {
this.allCategories = await api.categories.get_all();
},
methods: {
emitChange() {
this.$emit("input", this.selected);
},
setInit(val) {
this.selected = val;
},
},
};
</script>

View file

@ -92,18 +92,13 @@ export default {
default: false,
},
title: {
default: null
default: null,
},
recipes: Array,
cardLimit: {
default: 999,
},
},
watch: {
recipes(val) {
console.log(val)
}
},
computed: {
viewScale() {
switch (this.$vuetify.breakpoint.name) {

View file

@ -26,6 +26,7 @@ const store = new Vuex.Store({
recentRecipes: [],
allRecipes: [],
mealPlanCategories: [],
allCategories: [],
},
mutations: {
@ -36,6 +37,9 @@ const store = new Vuex.Store({
setMealPlanCategories(state, payload) {
state.mealPlanCategories = payload;
},
setAllCategories(state, payload) {
state.allCategories = payload;
},
},
actions: {
@ -52,11 +56,16 @@ const store = new Vuex.Store({
this.commit("setRecentRecipes", payload);
},
async requestCategories({ commit }) {
const categories = await api.categories.getAll();
commit("setAllCategories", categories);
},
},
getters: {
getRecentRecipes: state => state.recentRecipes,
getMealPlanCategories: state => state.mealPlanCategories,
getAllCategories: state => state.allCategories,
},
});