diff --git a/vue3/src/pages/SearchPage.vue b/vue3/src/pages/SearchPage.vue index 7e8ec5fba..df8678680 100644 --- a/vue3/src/pages/SearchPage.vue +++ b/vue3/src/pages/SearchPage.vue @@ -156,10 +156,11 @@ import RecipeCard from "@/components/display/RecipeCard.vue"; import {useDisplay} from "vuetify"; import {useUserPreferenceStore} from "@/stores/UserPreferenceStore"; import {useRouteQuery} from "@vueuse/router"; -import {stringToBool, toNumberArray} from "@/utils/utils"; +import {routeQueryDateTransformer, stringToBool, toNumberArray} from "@/utils/utils"; import RandomIcon from "@/components/display/RandomIcon.vue"; import {VRating, VSelect, VTextField} from "vuetify/components"; import RatingField from "@/components/inputs/RatingField.vue"; +import {DateTime} from "luxon"; const {t} = useI18n() const router = useRouter() @@ -421,25 +422,24 @@ const filters = ref({ modelValue: useRouteQuery('makenow', "false"), }, - // cookedonGte: { - // id: 'cookedonGte', - // label: 'Cooked after', - // hint: 'Only recipes that were cooked on or after the given date.', - // enabled: false, - // default: null, - // is: VTextField, - // type: "date", - // modelValue: useRouteQuery('cookedonGte', null, {transform: Date}), - // }, - // cookedonLte: { - // id: 'cookedonLte', - // label: 'Cooked before', - // hint: 'Only recipes that were cooked on or before the given date.', - // enabled: false, - // default: null, - // is: VDateInput, - // modelValue: useRouteQuery('cookedonLte', null, {transform: Date}), - // }, + cookedonGte: { + id: 'cookedonGte', + label: 'Cooked after', + hint: 'Only recipes that were cooked on or after the given date.', + enabled: false, + default: null, + is: VDateInput, + modelValue: useRouteQuery('cookedonGte', null, {transform: routeQueryDateTransformer}), + }, + cookedonLte: { + id: 'cookedonLte', + label: 'Cooked before', + hint: 'Only recipes that were cooked on or before the given date.', + enabled: false, + default: null, + is: VDateInput, + modelValue: useRouteQuery('cookedonLte', null, {transform: routeQueryDateTransformer}), + }, }) /** diff --git a/vue3/src/pages/TestPage.vue b/vue3/src/pages/TestPage.vue index 0dff20cd9..c41ae34f2 100644 --- a/vue3/src/pages/TestPage.vue +++ b/vue3/src/pages/TestPage.vue @@ -1,88 +1,84 @@ diff --git a/vue3/src/utils/utils.ts b/vue3/src/utils/utils.ts index 0d66bfd5e..b5d733795 100644 --- a/vue3/src/utils/utils.ts +++ b/vue3/src/utils/utils.ts @@ -1,6 +1,7 @@ import {getCookie} from "@/utils/cookie"; import {Recipe, RecipeFromJSON, RecipeImageFromJSON, UserFileFromJSON} from "@/openapi"; import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore"; +import {DateTime} from "luxon"; /** * Gets a nested property of an object given a dot-notation path. @@ -70,4 +71,12 @@ export function stringToBool(param: string): boolean | undefined { } else { return undefined } +} + +/** + * allows binding and transforming of dates to route query parameters + */ +export const routeQueryDateTransformer = { + get: (value: string | null | Date) => ((value == null) ? null : (new Date(value))), + set: (value: string | null | Date) => ((value == null) ? null : (DateTime.fromJSDate(new Date(value)).toISODate())) } \ No newline at end of file