move api calls to created event (#559)

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-06-17 19:48:54 -08:00 committed by GitHub
parent 71a5de3432
commit d272784469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 70 additions and 55 deletions

View File

@ -48,32 +48,16 @@ export default {
}, },
}, },
async mounted() { async created() {
// Initial API Requests
this.$store.dispatch("initTheme"); this.$store.dispatch("initTheme");
this.$store.dispatch("requestRecentRecipes");
this.$store.dispatch("refreshToken"); this.$store.dispatch("refreshToken");
this.$store.dispatch("requestCurrentGroup");
this.$store.dispatch("requestUserData"); this.$store.dispatch("requestUserData");
this.$store.dispatch("requestCategories"); this.$store.dispatch("requestCurrentGroup");
this.$store.dispatch("requestTags"); this.$store.dispatch("requestTags");
this.darkModeSystemCheck();
this.darkModeAddEventListener();
this.$store.dispatch("requestAppInfo"); this.$store.dispatch("requestAppInfo");
this.$store.dispatch("requestCustomPages");
this.$store.dispatch("requestSiteSettings"); this.$store.dispatch("requestSiteSettings");
},
data() {
return {
refreshing: false,
registration: null,
snackBtnText: "",
snackWithBtnText: "",
snackWithButtons: false,
};
},
created() {
// Listen for swUpdated event and display refresh snackbar as required. // Listen for swUpdated event and display refresh snackbar as required.
document.addEventListener("swUpdated", this.showRefreshUI, { once: true }); document.addEventListener("swUpdated", this.showRefreshUI, { once: true });
// Refresh all open app tabs when a new service worker is installed. // Refresh all open app tabs when a new service worker is installed.
@ -86,6 +70,21 @@ export default {
} }
}, },
mounted() {
this.darkModeSystemCheck();
this.darkModeAddEventListener();
},
data() {
return {
refreshing: false,
registration: null,
snackBtnText: "",
snackWithBtnText: "",
snackWithButtons: false,
};
},
methods: { methods: {
// For Later! // For Later!

View File

@ -72,6 +72,13 @@ export default {
selected: [], selected: [],
}; };
}, },
async created() {
if (this.tagSelector) {
this.$store.dispatch("requestTags");
} else {
this.$store.dispatch("requestCategories");
}
},
mounted() { mounted() {
this.$emit(MOUNTED_EVENT); this.$emit(MOUNTED_EVENT);
this.setInit(this.value); this.setInit(this.value);

View File

@ -30,7 +30,7 @@ export default {
], ],
}; };
}, },
mounted() { created() {
this.selectedItem = this.$store.getters.getActiveLang; this.selectedItem = this.$store.getters.getActiveLang;
}, },
computed: { computed: {

View File

@ -122,7 +122,7 @@ export default {
} }
}, },
}, },
async mounted() { async created() {
await this.$store.dispatch("requestCurrentGroup"); await this.$store.dispatch("requestCurrentGroup");
await this.$store.dispatch("requestAllRecipes"); await this.$store.dispatch("requestAllRecipes");
await this.buildMealStore(); await this.buildMealStore();

View File

@ -82,7 +82,7 @@ export default {
} else return this.$t("settings.backup.partial-backup"); } else return this.$t("settings.backup.partial-backup");
}, },
}, },
mounted() { created() {
this.resetData(); this.resetData();
this.getAvailableBackups(); this.getAvailableBackups();
}, },

View File

@ -78,15 +78,21 @@ export default {
hideImage: false, hideImage: false,
}; };
}, },
mounted() { created() {
this.getVersion();
this.showSidebar = !this.isMobile; this.showSidebar = !this.isMobile;
}, },
watch: { watch: {
user() { user() {
this.hideImage = false; this.hideImage = false;
}, },
isMain(val) {
if (val) {
this.$store.dispatch("requestCustomPages");
} else {
this.getVersion();
}
},
}, },
computed: { computed: {

View File

@ -75,7 +75,7 @@ export default {
prettyInfo: [], prettyInfo: [],
}; };
}, },
async mounted() { async created() {
await this.getInfo(); await this.getInfo();
}, },
methods: { methods: {

View File

@ -89,7 +89,7 @@ export default {
return this.availableBackups.length; return this.availableBackups.length;
}, },
}, },
mounted() { created() {
this.getAvailableBackups(); this.getAvailableBackups();
}, },
methods: { methods: {

View File

@ -105,7 +105,7 @@ export default {
}, },
}; };
}, },
mounted() { created() {
this.getStatistics(); this.getStatistics();
}, },
methods: { methods: {

View File

@ -76,7 +76,7 @@ export default {
return this.group.users.length >= 1 ? true : false; return this.group.users.length >= 1 ? true : false;
}, },
}, },
mounted() { created() {
this.buildData(); this.buildData();
}, },
methods: { methods: {

View File

@ -54,7 +54,7 @@ export default {
}, },
}, },
}, },
mounted() { created() {
this.reqGroups(); this.reqGroups();
}, },
methods: { methods: {

View File

@ -52,7 +52,7 @@ export default {
}, },
}; };
}, },
mounted() { created() {
this.getAvailableMigrations(); this.getAvailableMigrations();
}, },
methods: { methods: {

View File

@ -100,7 +100,7 @@ export default {
}; };
}, },
mounted() { created() {
this.$store.dispatch("requestUserData"); this.$store.dispatch("requestUserData");
}, },

View File

@ -160,7 +160,7 @@ export default {
}, },
}, },
async mounted() { async created() {
this.getTodaysMeal(); this.getTodaysMeal();
await this.$store.dispatch("requestCurrentGroup"); await this.$store.dispatch("requestCurrentGroup");
this.getSiteSettings(); this.getSiteSettings();

View File

@ -189,7 +189,7 @@ export default {
}, },
}, },
}, },
async mounted() { async created() {
await this.getAllThemes(); await this.getAllThemes();
}, },
methods: { methods: {

View File

@ -138,7 +138,7 @@ export default {
}, },
}, },
async mounted() { async created() {
this.refreshProfile(); this.refreshProfile();
}, },

View File

@ -90,7 +90,7 @@ export default {
}, },
}; };
}, },
async mounted() { async created() {
this.getPages(); this.getPages();
}, },
methods: { methods: {

View File

@ -154,7 +154,7 @@ export default {
}, },
}; };
}, },
mounted() { created() {
this.getOptions(); this.getOptions();
}, },
computed: { computed: {

View File

@ -67,7 +67,7 @@ export default {
tagsToAssign: [], tagsToAssign: [],
}; };
}, },
mounted() { created() {
this.$store.dispatch("requestAllRecipes"); this.$store.dispatch("requestAllRecipes");
}, },
watch: { watch: {

View File

@ -157,7 +157,7 @@ export default {
], ],
}; };
}, },
mounted() { created() {
this.getAllNotifications(); this.getAllNotifications();
}, },
computed: { computed: {

View File

@ -67,7 +67,7 @@ export default {
}, },
}, },
}, },
mounted() { created() {
this.refreshUnorganized(); this.refreshUnorganized();
}, },
methods: { methods: {

View File

@ -33,6 +33,11 @@ export default {
recipeByCategory: [], recipeByCategory: [],
}; };
}, },
async created() {
await this.$store.dispatch("requestRecentRecipes");
await this.buildPage();
this.recipeByCategory.sort((a, b) => a.position - b.position);
},
computed: { computed: {
siteSettings() { siteSettings() {
return this.$store.getters.getSiteSettings; return this.$store.getters.getSiteSettings;
@ -41,10 +46,7 @@ export default {
return this.$store.getters.getRecentRecipes; return this.$store.getters.getRecentRecipes;
}, },
}, },
async mounted() {
await this.buildPage();
this.recipeByCategory.sort((a, b) => a.position - b.position);
},
methods: { methods: {
async buildPage() { async buildPage() {
await this.$store.dispatch("requestSiteSettings"); await this.$store.dispatch("requestSiteSettings");

View File

@ -101,7 +101,7 @@ export default {
plannedMeals: [], plannedMeals: [],
editMealPlan: null, editMealPlan: null,
}), }),
async mounted() { async created() {
this.requestMeals(); this.requestMeals();
}, },
methods: { methods: {

View File

@ -45,7 +45,7 @@ export default {
mealPlan: {}, mealPlan: {},
}; };
}, },
async mounted() { async created() {
if (this.mealplanId) { if (this.mealplanId) {
this.mealPlan = await api.mealPlans.getById(this.mealplanId); this.mealPlan = await api.mealPlans.getById(this.mealplanId);
} else { } else {

View File

@ -28,7 +28,7 @@ export default {
defaultMessage: { details: "site failed to return valid schema" }, defaultMessage: { details: "site failed to return valid schema" },
}; };
}, },
mounted() { created() {
if (this.$route.query.test_url) { if (this.$route.query.test_url) {
this.getTestData(); this.getTestData();
} }

View File

@ -130,12 +130,13 @@ export default {
}; };
}, },
async mounted() { created() {
await this.getRecipeDetails(); this.getRecipeDetails();
this.jsonEditor = false; this.jsonEditor = false;
this.form = this.$route.query.edit === "true" && this.loggedIn; this.form = this.$route.query.edit === "true" && this.loggedIn;
},
async mounted() {
this.checkPrintRecipe(); this.checkPrintRecipe();
}, },

View File

@ -28,7 +28,7 @@ export default {
sortedResults: [], sortedResults: [],
}; };
}, },
async mounted() { async created() {
if (this.allRecipes.length < 1) { if (this.allRecipes.length < 1) {
this.loading = true; this.loading = true;
} }

View File

@ -81,7 +81,7 @@ export default {
this.getRecipes(); this.getRecipes();
}, },
}, },
mounted() { created() {
this.getRecipes(); this.getRecipes();
this.sortedResults = []; this.sortedResults = [];
}, },

View File

@ -58,7 +58,7 @@ export default {
}, },
}, },
async mounted() { async created() {
await this.buildPage(); await this.buildPage();
this.render = true; this.render = true;
}, },

View File

@ -34,7 +34,7 @@ export default {
} }
}, },
}, },
async mounted() { async created() {
this.userData = await api.users.getFavorites(this.$route.params.id); this.userData = await api.users.getFavorites(this.$route.params.id);
this.sortedResults = []; this.sortedResults = [];
}, },

View File

@ -88,7 +88,7 @@ export default {
}, },
}; };
}, },
mounted() { created() {
this.$store.dispatch("requestAllRecipes"); this.$store.dispatch("requestAllRecipes");
}, },
computed: { computed: {