Provide feedback to user when no meal is planned

This commit is contained in:
Florian Dupret 2021-04-27 20:05:32 +02:00
commit ebf38add4a
3 changed files with 23 additions and 3 deletions

View file

@ -17,6 +17,8 @@
- Fixes #281 - Slow Handling of Large Sets of Recipes - Fixes #281 - Slow Handling of Large Sets of Recipes
## Features and Improvements ## Features and Improvements
- 'Dinner this week' shows a warning when no meal is planned yet
- 'Dinner today' shows a warning when no meal is planned yet
### General ### General
- More localization - More localization
@ -33,3 +35,5 @@
### Behind the Scenes ### Behind the Scenes
- Unified Sidebar Components - Unified Sidebar Components
- Refactor UI components to fit Vue best practices (WIP) - Refactor UI components to fit Vue best practices (WIP)
- The API returns more consistent status codes
- The API returns error code instead of error text when appropriate

View file

@ -52,6 +52,7 @@
<script> <script>
import { api } from "@/api"; import { api } from "@/api";
import utils from "@/utils";
export default { export default {
data() { data() {
return { return {
@ -60,6 +61,9 @@ export default {
}, },
async mounted() { async mounted() {
this.mealPlan = await api.mealPlans.thisWeek(); this.mealPlan = await api.mealPlans.thisWeek();
if(!this.mealPlan) {
utils.notify.warning(this.$t('meal-plan.no-meal-plan-defined-yet'))
}
}, },
methods: { methods: {
getOrder(index) { getOrder(index) {

View file

@ -2,6 +2,9 @@ import Planner from "@/pages/MealPlan/Planner";
import ThisWeek from "@/pages/MealPlan/ThisWeek"; import ThisWeek from "@/pages/MealPlan/ThisWeek";
import { api } from "@/api"; import { api } from "@/api";
import i18n from '@/i18n.js';
import utils from "@/utils";
export const mealRoutes = [ export const mealRoutes = [
{ {
path: "/meal-plan/planner", path: "/meal-plan/planner",
@ -21,7 +24,12 @@ export const mealRoutes = [
path: "/meal-plan/today", path: "/meal-plan/today",
beforeEnter: async (_to, _from, next) => { beforeEnter: async (_to, _from, next) => {
await todaysMealRoute().then(redirect => { await todaysMealRoute().then(redirect => {
next(redirect); if(redirect) {
next(redirect);
} else {
utils.notify.error(i18n.t('meal-plan.no-meal-planned-for-today'));
next(_from);
}
}); });
}, },
}, },
@ -29,5 +37,9 @@ export const mealRoutes = [
async function todaysMealRoute() { async function todaysMealRoute() {
const response = await api.mealPlans.today(); const response = await api.mealPlans.today();
return "/recipe/" + response.data; if (response.status == 200 && response.data) {
return "/recipe/" + response.data;
} else {
return null;
}
} }