mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
89ab7fac25
commit
c24d532608
403 changed files with 23959 additions and 19557 deletions
|
@ -8,9 +8,13 @@
|
|||
max-width="290px"
|
||||
min-width="auto"
|
||||
>
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-btn color="primary" class="mb-2" v-bind="attrs" v-on="on">
|
||||
<v-icon left>
|
||||
<template #activator="{ props }">
|
||||
<v-btn
|
||||
color="primary"
|
||||
class="mb-2"
|
||||
v-bind="props"
|
||||
>
|
||||
<v-icon start>
|
||||
{{ $globals.icons.calendar }}
|
||||
</v-icon>
|
||||
{{ $d(weekRange.start, "short") }} - {{ $d(weekRange.end, "short") }}
|
||||
|
@ -18,8 +22,8 @@
|
|||
</template>
|
||||
<v-date-picker
|
||||
v-model="state.range"
|
||||
no-title
|
||||
range
|
||||
hide-header
|
||||
:multiple="'range'"
|
||||
:first-day-of-week="firstDayOfWeek"
|
||||
:local="$i18n.locale"
|
||||
>
|
||||
|
@ -30,8 +34,12 @@
|
|||
:hint="$t('meal-plan.numberOfDays-hint')"
|
||||
persistent-hint
|
||||
/>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn text color="primary" @click="state.picker = false">
|
||||
<v-spacer />
|
||||
<v-btn
|
||||
variant="text"
|
||||
color="primary"
|
||||
@click="state.picker = false"
|
||||
>
|
||||
{{ $t("general.ok") }}
|
||||
</v-btn>
|
||||
</v-date-picker>
|
||||
|
@ -39,34 +47,49 @@
|
|||
|
||||
<div class="d-flex flex-wrap align-center justify-space-between mb-2">
|
||||
<v-tabs style="width: fit-content;">
|
||||
<v-tab :to="`/household/mealplan/planner/view`">{{ $t('meal-plan.meal-planner') }}</v-tab>
|
||||
<v-tab :to="`/household/mealplan/planner/edit`">{{ $t('general.edit') }}</v-tab>
|
||||
<v-tab :to="`/household/mealplan/planner/view`">
|
||||
{{ $t('meal-plan.meal-planner') }}
|
||||
</v-tab>
|
||||
<v-tab :to="`/household/mealplan/planner/edit`">
|
||||
{{ $t('general.edit') }}
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
<ButtonLink :icon="$globals.icons.calendar" :to="`/household/mealplan/settings`" :text="$tc('general.settings')" />
|
||||
<ButtonLink
|
||||
:icon="$globals.icons.calendar"
|
||||
:to="`/household/mealplan/settings`"
|
||||
:text="$t('general.settings')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<NuxtChild :mealplans="mealsByDate" :actions="actions" />
|
||||
<NuxtPage
|
||||
:mealplans="mealsByDate"
|
||||
:actions="actions"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<v-row> </v-row>
|
||||
<v-row />
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, ref, useRoute, useRouter, watch } from "@nuxtjs/composition-api";
|
||||
import { isSameDay, addDays, parseISO } from "date-fns";
|
||||
import { useHouseholdSelf } from "~/composables/use-households";
|
||||
import { useMealplans } from "~/composables/use-group-mealplan";
|
||||
import { useUserMealPlanPreferences } from "~/composables/use-users/preferences";
|
||||
|
||||
export default defineComponent({
|
||||
middleware: ["auth"],
|
||||
export default defineNuxtComponent({
|
||||
middleware: ["sidebase-auth"],
|
||||
setup() {
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const i18n = useI18n();
|
||||
const { household } = useHouseholdSelf();
|
||||
|
||||
useSeoMeta({
|
||||
title: i18n.t("meal-plan.dinner-this-week"),
|
||||
});
|
||||
|
||||
const mealPlanPreferences = useUserMealPlanPreferences();
|
||||
const numberOfDays = ref<number>(mealPlanPreferences.value.numberOfDays || 7);
|
||||
watch(numberOfDays, (val) => {
|
||||
|
@ -74,21 +97,12 @@ export default defineComponent({
|
|||
});
|
||||
|
||||
// Force to /view if current route is /planner
|
||||
if (route.value.path === "/household/mealplan/planner") {
|
||||
if (route.path === "/household/mealplan/planner") {
|
||||
router.push("/household/mealplan/planner/view");
|
||||
}
|
||||
|
||||
function fmtYYYYMMDD(date: Date) {
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||
}
|
||||
|
||||
function parseYYYYMMDD(date: string) {
|
||||
const [year, month, day] = date.split("-");
|
||||
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
|
||||
}
|
||||
|
||||
const state = ref({
|
||||
range: [fmtYYYYMMDD(new Date()), fmtYYYYMMDD(addDays(new Date(), adjustForToday(numberOfDays.value)))] as [string, string],
|
||||
range: [new Date(), addDays(new Date(), adjustForToday(numberOfDays.value))] as [Date, Date],
|
||||
start: new Date(),
|
||||
picker: false,
|
||||
end: addDays(new Date(), adjustForToday(numberOfDays.value)),
|
||||
|
@ -99,15 +113,17 @@ export default defineComponent({
|
|||
});
|
||||
|
||||
const weekRange = computed(() => {
|
||||
const sorted = state.value.range.sort((a, b) => {
|
||||
return parseYYYYMMDD(a).getTime() - parseYYYYMMDD(b).getTime();
|
||||
});
|
||||
const sorted = [...state.value.range].sort((a, b) => a.getTime() - b.getTime());
|
||||
|
||||
if (sorted.length === 2) {
|
||||
return {
|
||||
start: parseYYYYMMDD(sorted[0]),
|
||||
end: parseYYYYMMDD(sorted[1]),
|
||||
start: sorted[0],
|
||||
end: sorted[1],
|
||||
};
|
||||
// return {
|
||||
// start: parseYYYYMMDD(sorted[0]),
|
||||
// end: parseYYYYMMDD(sorted[1]),
|
||||
// };
|
||||
}
|
||||
return {
|
||||
start: new Date(),
|
||||
|
@ -128,12 +144,12 @@ export default defineComponent({
|
|||
function adjustForToday(days: number) {
|
||||
// The use case for this function is "how many days are we adding to 'today'?"
|
||||
// e.g. If the user wants 7 days, we substract one to do "today + 6"
|
||||
return days > 0 ? days - 1 : days + 1
|
||||
return days > 0 ? days - 1 : days + 1;
|
||||
}
|
||||
|
||||
const days = computed(() => {
|
||||
const numDays =
|
||||
Math.floor((weekRange.value.end.getTime() - weekRange.value.start.getTime()) / (1000 * 60 * 60 * 24)) + 1;
|
||||
const numDays
|
||||
= Math.floor((weekRange.value.end.getTime() - weekRange.value.start.getTime()) / (1000 * 60 * 60 * 24)) + 1;
|
||||
|
||||
// Calculate absolute value
|
||||
if (numDays < 0) return [];
|
||||
|
@ -143,7 +159,7 @@ export default defineComponent({
|
|||
const date = new Date(weekRange.value.start.getTime());
|
||||
date.setDate(date.getDate() + i);
|
||||
return date;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -162,11 +178,6 @@ export default defineComponent({
|
|||
numberOfDays,
|
||||
};
|
||||
},
|
||||
head() {
|
||||
return {
|
||||
title: this.$t("meal-plan.dinner-this-week") as string,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue