Skip to content

Commit

Permalink
fix: add locale and first day of week to all date pickers (#3303)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson authored Mar 12, 2024
1 parent 42523bb commit 5f5b066
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
15 changes: 14 additions & 1 deletion frontend/components/Domain/Recipe/RecipeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@
v-on="on"
></v-text-field>
</template>
<v-date-picker v-model="newMealdate" no-title @input="pickerMenu = false"></v-date-picker>
<v-date-picker
v-model="newMealdate"
no-title
:first-day-of-week="firstDayOfWeek"
:local="$i18n.locale"
@input="pickerMenu = false"
/>
</v-menu>
<v-select
v-model="newMealType"
Expand Down Expand Up @@ -111,6 +117,7 @@ import RecipeDialogPrintPreferences from "./RecipeDialogPrintPreferences.vue";
import RecipeDialogShare from "./RecipeDialogShare.vue";
import { useLoggedInState } from "~/composables/use-logged-in-state";
import { useUserApi } from "~/composables/api";
import { useGroupSelf } from "~/composables/use-groups";
import { alert } from "~/composables/use-toast";
import { usePlanTypeOptions } from "~/composables/use-group-mealplan";
import { Recipe } from "~/lib/api/types/recipe";
Expand Down Expand Up @@ -224,11 +231,16 @@ export default defineComponent({
});
const { i18n, $auth, $globals } = useContext();
const { group } = useGroupSelf();
const { isOwnGroup } = useLoggedInState();
const route = useRoute();
const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "");
const firstDayOfWeek = computed(() => {
return group.value?.preferences?.firstDayOfWeek || 0;
});
// ===========================================================================
// Context Menu Setup
Expand Down Expand Up @@ -432,6 +444,7 @@ export default defineComponent({
addRecipeToPlan,
icon,
planTypeOptions,
firstDayOfWeek,
};
},
});
Expand Down
15 changes: 14 additions & 1 deletion frontend/components/Domain/Recipe/RecipeDialogShare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
v-on="on"
></v-text-field>
</template>
<v-date-picker v-model="expirationDate" no-title @input="datePickerMenu = false"></v-date-picker>
<v-date-picker
v-model="expirationDate"
no-title
:first-day-of-week="firstDayOfWeek"
:local="$i18n.locale"
@input="datePickerMenu = false"
/>
</v-menu>
</v-card-text>
<v-card-actions class="justify-end">
Expand Down Expand Up @@ -60,6 +66,7 @@ import { defineComponent, computed, toRefs, reactive, useContext, useRoute } fro
import { useClipboard, useShare, whenever } from "@vueuse/core";
import { RecipeShareToken } from "~/lib/api/types/recipe";
import { useUserApi } from "~/composables/api";
import { useGroupSelf } from "~/composables/use-groups";
import { alert } from "~/composables/use-toast";
export default defineComponent({
Expand Down Expand Up @@ -106,9 +113,14 @@ export default defineComponent({
);
const { $auth, i18n } = useContext();
const { group } = useGroupSelf();
const route = useRoute();
const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "");
const firstDayOfWeek = computed(() => {
return group.value?.preferences?.firstDayOfWeek || 0;
});
// ============================================================
// Token Actions
Expand Down Expand Up @@ -185,6 +197,7 @@ export default defineComponent({
dialog,
createNewToken,
deleteToken,
firstDayOfWeek,
shareRecipe,
copyTokenLink,
};
Expand Down
10 changes: 9 additions & 1 deletion frontend/components/Domain/Recipe/RecipeLastMade.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<v-date-picker
v-model="newTimelineEventTimestamp"
no-title
:first-day-of-week="firstDayOfWeek"
:local="$i18n.locale"
@input="datePickerMenu = false"
/>
Expand Down Expand Up @@ -109,10 +110,11 @@
</template>

<script lang="ts">
import { defineComponent, reactive, ref, toRefs, useContext } from "@nuxtjs/composition-api";
import { computed, defineComponent, reactive, ref, toRefs, useContext } from "@nuxtjs/composition-api";
import { whenever } from "@vueuse/core";
import { VForm } from "~/types/vuetify";
import { useUserApi } from "~/composables/api";
import { useGroupSelf } from "~/composables/use-groups";
import { Recipe, RecipeTimelineEventIn } from "~/lib/api/types/recipe";
export default defineComponent({
Expand All @@ -129,6 +131,7 @@ export default defineComponent({
setup(props, context) {
const madeThisDialog = ref(false);
const userApi = useUserApi();
const { group } = useGroupSelf();
const { $auth, i18n } = useContext();
const domMadeThisForm = ref<VForm>();
const newTimelineEvent = ref<RecipeTimelineEventIn>({
Expand All @@ -153,6 +156,10 @@ export default defineComponent({
}
);
const firstDayOfWeek = computed(() => {
return group.value?.preferences?.firstDayOfWeek || 0;
});
function clearImage() {
newTimelineEventImage.value = undefined;
newTimelineEventImageName.value = "";
Expand Down Expand Up @@ -226,6 +233,7 @@ export default defineComponent({
...toRefs(state),
domMadeThisForm,
madeThisDialog,
firstDayOfWeek,
newTimelineEvent,
newTimelineEventImage,
newTimelineEventImagePreviewUrl,
Expand Down
15 changes: 14 additions & 1 deletion frontend/pages/group/mealplan/planner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
{{ $d(weekRange.start, "short") }} - {{ $d(weekRange.end, "short") }}
</v-btn>
</template>
<v-date-picker v-model="state.range" no-title range>
<v-date-picker
v-model="state.range"
no-title
range
:first-day-of-week="firstDayOfWeek"
:local="$i18n.locale"
>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="state.picker = false">
{{ $t("general.ok") }}
Expand All @@ -43,13 +49,15 @@
<script lang="ts">
import { computed, defineComponent, ref, useRoute, useRouter } from "@nuxtjs/composition-api";
import { isSameDay, addDays, parseISO } from "date-fns";
import { useGroupSelf } from "~/composables/use-groups";
import { useMealplans } from "~/composables/use-group-mealplan";
export default defineComponent({
middleware: ["auth"],
setup() {
const route = useRoute();
const router = useRouter();
const { group } = useGroupSelf();
// Force to /view if current route is /planner
if (route.value.path === "/group/mealplan/planner") {
Expand All @@ -72,6 +80,10 @@ export default defineComponent({
end: addDays(new Date(), 6),
});
const firstDayOfWeek = computed(() => {
return group.value?.preferences?.firstDayOfWeek || 0;
});
const recipeSearchTerm = ref("");
const weekRange = computed(() => {
Expand Down Expand Up @@ -128,6 +140,7 @@ export default defineComponent({
actions,
mealsByDate,
weekRange,
firstDayOfWeek,
recipeSearchTerm,
};
},
Expand Down
11 changes: 3 additions & 8 deletions frontend/pages/group/mealplan/planner/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
</template>
<v-date-picker
v-model="newMeal.date"
:first-day-of-week="firstDayOfWeek"
no-title
:first-day-of-week="firstDayOfWeek"
:local="$i18n.locale"
@input="state.pickerMenu = false"
/>
</v-menu>
Expand Down Expand Up @@ -256,13 +257,7 @@ export default defineComponent({
});
const firstDayOfWeek = computed(() => {
const pref = group.value?.preferences?.firstDayOfWeek;
if (pref) {
return pref;
}
return 0;
return group.value?.preferences?.firstDayOfWeek || 0;
});
function onMoveCallback(evt: SortableEvent) {
Expand Down

0 comments on commit 5f5b066

Please sign in to comment.