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

Composables TypeScript #498

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { App } from 'vue';
import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import duration from 'dayjs/plugin/duration';
Expand All @@ -13,7 +14,14 @@ import timezone from 'dayjs/plugin/timezone';
import weekday from 'dayjs/plugin/weekday';
import 'dayjs/locale/de';

export default function useDayJS(app, locale) {
export type IsoWeekday = {
iso: number,
long: string,
short: string,
min: string,
};

export default function useDayJS(app: App<Element>, locale: string) {
dayjs.locale(locale);
dayjs.extend(advancedFormat);
dayjs.extend(duration);
Expand All @@ -32,7 +40,7 @@ export default function useDayJS(app, locale) {
// TODO: provide method to live update the dayjs locale
app.provide('dayjs', dayjs);

const hDuration = (m) => ((m < 60)
const hDuration = (m: number): string => ((m < 60)
? dayjs.duration(m, 'minutes').humanize()
: dayjs.duration(m / 60, 'hours').humanize());
app.provide('hDuration', hDuration);
Expand All @@ -44,7 +52,7 @@ export default function useDayJS(app, locale) {

// provide unified list of locale weekdays with Monday=1 to Sunday=7 (isoweekdays)
// taking locale first day of week into account
const isoWeekdays = [];
const isoWeekdays = [] as IsoWeekday[];
// TODO: generate order list for all starting days
const order = isoFirstDayOfWeek === 7 ? [7, 1, 2, 3, 4, 5, 6] : [1, 2, 3, 4, 5, 6, 7];
order.forEach((i) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const messages = {
de, // German
en, // English
};
const loc = localStorage?.getItem('locale') ?? (navigator.language || navigator.userLanguage);
const loc = localStorage?.getItem('locale') ?? navigator.language;
const instance = createI18n({
legacy: false,
globalInjection: true,
Expand Down
1 change: 1 addition & 0 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowJs": true,
"paths": {
Expand Down