mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
Add date range to useMealplans composable (#888)
This fixes #857 by passing a date range ref to useMealplans, so that the meal plans are re-queried whenever the date range changes.
This commit is contained in:
parent
74e13682cb
commit
1482f51fcd
2 changed files with 26 additions and 25 deletions
|
@ -200,7 +200,7 @@
|
|||
</v-row>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, reactive, toRefs, watch } from "@nuxtjs/composition-api";
|
||||
import { isSameDay, addDays, subDays, parseISO, format } from "date-fns";
|
||||
|
@ -218,19 +218,25 @@ export default defineComponent({
|
|||
RecipeCard,
|
||||
},
|
||||
setup() {
|
||||
const { mealplans, actions, loading } = useMealplans();
|
||||
|
||||
useRecipes(true, true);
|
||||
const state = reactive({
|
||||
createMealDialog: false,
|
||||
edit: false,
|
||||
hover: {},
|
||||
pickerMenu: null,
|
||||
start: null as Date | null,
|
||||
today: new Date(),
|
||||
end: null as Date | null,
|
||||
});
|
||||
|
||||
const weekRange = computed(() => {
|
||||
return {
|
||||
start: subDays(state.today, 1),
|
||||
end: addDays(state.today, 6),
|
||||
};
|
||||
});
|
||||
|
||||
const { mealplans, actions, loading } = useMealplans(weekRange);
|
||||
|
||||
useRecipes(true, true);
|
||||
|
||||
function filterMealByDate(date: Date) {
|
||||
if (!mealplans.value) return;
|
||||
return mealplans.value.filter((meal) => {
|
||||
|
@ -241,13 +247,11 @@ export default defineComponent({
|
|||
|
||||
function forwardOneWeek() {
|
||||
if (!state.today) return;
|
||||
// @ts-ignore
|
||||
state.today = addDays(state.today, +5);
|
||||
}
|
||||
|
||||
function backOneWeek() {
|
||||
if (!state.today) return;
|
||||
// @ts-ignore
|
||||
state.today = addDays(state.today, -5);
|
||||
}
|
||||
|
||||
|
@ -282,16 +286,7 @@ export default defineComponent({
|
|||
});
|
||||
});
|
||||
|
||||
const weekRange = computed(() => {
|
||||
// @ts-ignore - Not Sure Why This is not working
|
||||
const end = addDays(state.today, 6);
|
||||
// @ts-ignore - Not sure why the type is invalid
|
||||
const start = subDays(state.today, 1);
|
||||
return { start, end, today: state.today };
|
||||
});
|
||||
|
||||
const days = computed(() => {
|
||||
if (weekRange.value?.start === null) return [];
|
||||
return Array.from(Array(8).keys()).map(
|
||||
// @ts-ignore
|
||||
(i) => new Date(weekRange.value.start.getTime() + i * 24 * 60 * 60 * 1000)
|
||||
|
@ -390,4 +385,3 @@ export default defineComponent({
|
|||
border-bottom: 2px solid var(--v-primary-base) !important;
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue