Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a localstorage option to change the start of the week (Fixes #589) #818

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions frontend/src/components/CalendarQalendar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import {
ref, computed, inject, toRefs, watch, onMounted
ref, computed, inject, toRefs, watch, onMounted,
} from 'vue';
import { Qalendar } from 'qalendar';
import 'qalendar/dist/style.css';
Expand All @@ -12,12 +12,13 @@ import {
} from '@/definitions';
import { getLocale, getPreferredTheme, timeFormat } from '@/utils';
import { useRoute, useRouter } from 'vue-router';
import { dayjsKey } from '@/keys';
import { dayjsKey, isoWeekdaysKey } from '@/keys';

// component constants
const dj = inject(dayjsKey);
const router = useRouter();
const route = useRoute();
const isoWeekdays = inject(isoWeekdaysKey);

// component properties
const props = defineProps({
Expand Down Expand Up @@ -311,7 +312,7 @@ const config = ref({
showEventsOnMobileView: false,
},
week: {
startsOn: locale === 'de' ? 'monday' : 'sunday',
startsOn: localStorage?.getItem('startOfTheWeek') ?? isoWeekdays[0].long.toLowerCase(),
},
style: {
// Just the pre-calculated list from tailwind, could use some fine-tuning.
Expand All @@ -334,13 +335,13 @@ const config = ref({
},
dayBoundaries: {
start: dayBoundary.value.start,
end: dayBoundary.value.end
end: dayBoundary.value.end,
},
eventDialog: {
// We roll our own
isDisabled: true,
},
locale: locale === 'de' ? 'de-DE' : 'en-US'
locale: locale === 'de' ? 'de-DE' : 'en-US',
});

/**
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/components/SettingsGeneral.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<script setup lang="ts">
import { ColorSchemes } from '@/definitions';
import {
ref, reactive, inject, watch,
ref, reactive, inject, watch, computed,
} from 'vue';
import { useI18n } from 'vue-i18n';
import { useUserStore } from '@/stores/user-store';
import { dayjsKey, callKey } from '@/keys';
import { dayjsKey, callKey, isoWeekdaysKey } from '@/keys';
import { SubscriberResponse } from '@/models';

// component constants
const user = useUserStore();
const { t, locale, availableLocales } = useI18n({ useScope: 'global' });
const call = inject(callKey);
const dj = inject(dayjsKey);
const isoWeekdays = inject(isoWeekdaysKey);

const startOfTheWeek = ref(localStorage?.getItem('startOfTheWeek') ?? isoWeekdays[0].long.toLowerCase());
const availableStartOfTheWeekOptions = computed(() => isoWeekdays.filter((day) => day.long === 'Monday' || day.long === 'Sunday'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for other languages than English. E.g. when viewing the settings page in German, this array would be empty.


// handle ui languages
// TODO: move to settings store
Expand Down Expand Up @@ -81,6 +85,11 @@ const updateTimezone = async () => {
// TODO show some confirmation
}
};

// save timezone config
const updateStartOfTheWeek = async (evt) => {
localStorage?.setItem('startOfTheWeek', evt.target.value.toLowerCase());
};
</script>

<template>
Expand Down Expand Up @@ -120,6 +129,22 @@ const updateTimezone = async () => {
</div>
<div class="pl-6">
<div class="text-xl">{{ t('heading.dateAndTimeFormatting') }}</div>
<div class="mt-6 pl-6">
<div class="text-lg">{{ t('label.startOfTheWeek') }}</div>
<label class="mt-4 flex items-center pl-4">
<div class="w-full max-w-2xs">{{ t('label.startOfTheWeek') }}</div>
<select
v-model="startOfTheWeek"
class="w-full max-w-sm rounded-md"
@change="updateStartOfTheWeek"
data-testid="settings-general-timezone-select"
>
<option v-for="day in availableStartOfTheWeekOptions" :key="day.long" :value="day.long.toLowerCase()">
{{ day.long }}
</option>
</select>
</label>
</div>
<div class="mt-6 inline-grid grid-cols-2 gap-x-16 gap-y-8 pl-6">
<div class="text-lg">{{ t('label.timeFormat') }}</div>
<div class="text-lg"><!--{{ t('label.dateFormat') }}--></div>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
"startDate": "Startdatum",
"startTime": "Startzeit",
"startUsingTba": "Starte mit TBA",
"startOfTheWeek": "Erster Tag der Woche",
"status": "Status",
"success": "Erfolg",
"sync": "Synchronisieren",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
"startDate": "Start date",
"startTime": "Start time",
"startUsingTba": "Try Appointment",
"startOfTheWeek": "Start of the week",
"status": "Status",
"success": "Success",
"sync": "Sync",
Expand Down
Loading