diff options
| -rw-r--r-- | apps/projects/src/app/lib/i18n/en/index.ts | 3 | ||||
| -rw-r--r-- | apps/projects/src/app/lib/i18n/i18n-types.ts | 26 | ||||
| -rw-r--r-- | apps/projects/src/app/lib/i18n/nb/index.ts | 3 | ||||
| -rw-r--r-- | apps/projects/src/app/pages/home.svelte | 28 | ||||
| -rw-r--r-- | apps/web-shared/src/lib/helpers.ts | 17 |
5 files changed, 39 insertions, 38 deletions
diff --git a/apps/projects/src/app/lib/i18n/en/index.ts b/apps/projects/src/app/lib/i18n/en/index.ts index 9d74481..a85af7b 100644 --- a/apps/projects/src/app/lib/i18n/en/index.ts +++ b/apps/projects/src/app/lib/i18n/en/index.ts @@ -101,13 +101,12 @@ const en: BaseTranslation = { use: "Use", }, home: { - hourSingleChar: "h", - minSingleChar: "m", confirmDeleteEntry: "Are you sure you want to delete this entry?", newEntry: "New entry", editEntry: "Edit entry", deleteEntry: "Delete entry", loggedTimeToday: "Logged time today", + loggedTimeTodayString: "{hours}h{minutes}m", currentTime: "Current time", loading: "Loading", stopwatch: "Stopwatch", diff --git a/apps/projects/src/app/lib/i18n/i18n-types.ts b/apps/projects/src/app/lib/i18n/i18n-types.ts index b0031f6..acba223 100644 --- a/apps/projects/src/app/lib/i18n/i18n-types.ts +++ b/apps/projects/src/app/lib/i18n/i18n-types.ts @@ -344,14 +344,6 @@ type RootTranslation = { } home: { /** - * h - */ - hourSingleChar: string - /** - * m - */ - minSingleChar: string - /** * Are you sure you want to delete this entry? */ confirmDeleteEntry: string @@ -372,6 +364,12 @@ type RootTranslation = { */ loggedTimeToday: string /** + * {hours}h{minutes}m + * @param {unknown} hours + * @param {unknown} minutes + */ + loggedTimeTodayString: RequiredParams<'hours' | 'minutes'> + /** * Current time */ currentTime: string @@ -749,14 +747,6 @@ export type TranslationFunctions = { } home: { /** - * h - */ - hourSingleChar: () => LocalizedString - /** - * m - */ - minSingleChar: () => LocalizedString - /** * Are you sure you want to delete this entry? */ confirmDeleteEntry: () => LocalizedString @@ -777,6 +767,10 @@ export type TranslationFunctions = { */ loggedTimeToday: () => LocalizedString /** + * {hours}h{minutes}m + */ + loggedTimeTodayString: (arg: { hours: unknown, minutes: unknown }) => LocalizedString + /** * Current time */ currentTime: () => LocalizedString diff --git a/apps/projects/src/app/lib/i18n/nb/index.ts b/apps/projects/src/app/lib/i18n/nb/index.ts index 28e4bc1..1638345 100644 --- a/apps/projects/src/app/lib/i18n/nb/index.ts +++ b/apps/projects/src/app/lib/i18n/nb/index.ts @@ -101,8 +101,7 @@ const nb: Translation = { use: "Bruk", }, home: { - hourSingleChar: "t", - minSingleChar: "m", + loggedTimeTodayString: "{hours}t{minutes}m", confirmDeleteEntry: "Er du sikker på at du vil slette denne raden?", newEntry: "Ny tidsoppføring", editEntry: "Rediger rad", diff --git a/apps/projects/src/app/pages/home.svelte b/apps/projects/src/app/pages/home.svelte index ff52275..145ae66 100644 --- a/apps/projects/src/app/pages/home.svelte +++ b/apps/projects/src/app/pages/home.svelte @@ -1,25 +1,26 @@ <script lang="ts"> import LL from "$app/lib/i18n/i18n-svelte"; - import {delete_time_entry, get_time_entries, get_time_entry} from "$shared/lib/api/time-entry"; - import {IconNames, QueryKeys} from "$shared/lib/configuration"; - import {TimeEntryDto} from "$shared/lib/models/TimeEntryDto"; - import {Temporal} from "@js-temporal/polyfill"; - import {useMutation, useQuery, useQueryClient} from "@sveltestack/svelte-query"; - import {onMount} from "svelte"; + import { delete_time_entry, get_time_entries, get_time_entry } from "$shared/lib/api/time-entry"; + import { IconNames, QueryKeys } from "$shared/lib/configuration"; + import { TimeEntryDto } from "$shared/lib/models/TimeEntryDto"; + import { Temporal } from "@js-temporal/polyfill"; + import { useMutation, useQuery, useQueryClient } from "@sveltestack/svelte-query"; + import { onMount } from "svelte"; import Tile from "$shared/components/tile.svelte"; import Button from "$shared/components/button.svelte"; import Stopwatch from "$shared/components/stopwatch.svelte"; - import {Table, THead, TBody, TCell, TRow} from "$shared/components/table"; + import { Table, THead, TBody, TCell, TRow } from "$shared/components/table"; import Layout from "./_layout.svelte"; import EntryFrom from "$app/pages/views/entry-form/index.svelte"; - import {seconds_to_hour_minute_string, unwrap_date_time_from_entry} from "$shared/lib/helpers"; - import {TimeEntryQueryDuration} from "$shared/lib/models/TimeEntryQuery"; + import { seconds_to_hour_minute, unwrap_date_time_from_entry } from "$shared/lib/helpers"; + import { TimeEntryQueryDuration } from "$shared/lib/models/TimeEntryQuery"; let currentTime = ""; let isLoading = false; let EditEntryForm: any; let timeEntries = [] as Array<TimeEntryDto>; - let timeLoggedTodayString = "0" + $LL.home.hourSingleChar() + "0" + $LL.home.minSingleChar(); + let timeLoggedTodayString = $LL.home.loggedTimeTodayString({hours: 0, minutes: 0}); + let loggedSecondsToday = 0; const queryClient = useQueryClient(); const queryResult = useQuery(QueryKeys.entries, async () => await get_time_entries({ @@ -28,7 +29,7 @@ pageSize: 100, })?.data ?? [] ); - + function set_current_time() { currentTime = Temporal.Now.plainTimeISO().toLocaleString(undefined, { timeStyle: "short", @@ -56,6 +57,7 @@ } function on_create_from_stopwatch(event) { + console.log(event.detail); EditEntryForm.set_time({to: event.detail.to, from: event.detail.from}); if (event.detail.description) { EditEntryForm.set_description(event.detail.description); @@ -69,7 +71,7 @@ }, 1e4); queryResult.subscribe((result) => { const newEntries = []; - let loggedSecondsToday = 0; + loggedSecondsToday = 0; for (const entry of result.data?.results ?? []) { const date_time = unwrap_date_time_from_entry(entry); newEntries.push({ @@ -80,7 +82,7 @@ }); loggedSecondsToday += (date_time.duration.hours * 60 * 60) + (date_time.duration.minutes * 60); } - timeLoggedTodayString = seconds_to_hour_minute_string(loggedSecondsToday); + timeLoggedTodayString = $LL.home.loggedTimeTodayString(seconds_to_hour_minute(loggedSecondsToday)); timeEntries = newEntries; }); }); diff --git a/apps/web-shared/src/lib/helpers.ts b/apps/web-shared/src/lib/helpers.ts index 1cf94f4..ad6f280 100644 --- a/apps/web-shared/src/lib/helpers.ts +++ b/apps/web-shared/src/lib/helpers.ts @@ -1,7 +1,7 @@ -import {base_domain, CookieNames} from "$shared/lib/configuration"; -import {TimeEntryDto} from "$shared/lib/models/TimeEntryDto"; -import {UnwrappedEntryDateTime} from "$shared/lib/models/UnwrappedEntryDateTime"; -import {Temporal} from "@js-temporal/polyfill"; +import { base_domain, CookieNames } from "$shared/lib/configuration"; +import { TimeEntryDto } from "$shared/lib/models/TimeEntryDto"; +import { UnwrappedEntryDateTime } from "$shared/lib/models/UnwrappedEntryDateTime"; +import { Temporal } from "@js-temporal/polyfill"; export const EMAIL_REGEX = new RegExp(/^([a-z0-9]+(?:([._\-])[a-z0-9]+)*@(?:[a-z0-9]+(?:(-)[a-z0-9]+)?\.)+[a-z0-9](?:[a-z0-9]*[a-z0-9])?)$/i); export const URL_REGEX = new RegExp(/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-.][a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm); @@ -143,13 +143,20 @@ export function set_emoji_favicon(emoji: string) { // https://stackoverflow.com/a/48400665/11961742 -export function seconds_to_hour_minute_string(seconds: number) { +export function seconds_to_hour_minute_string(seconds: number, hourChar = "h", minuteChar = "m") { const hours = Math.floor(seconds / (60 * 60)); seconds -= hours * (60 * 60); const minutes = Math.floor(seconds / 60); return hours + "h" + minutes + "m"; } +export function seconds_to_hour_minute(seconds: number) { + const hours = Math.floor(seconds / (60 * 60)); + seconds -= hours * (60 * 60); + const minutes = Math.floor(seconds / 60); + return {hours, minutes}; +} + export function get_query_string(params: any = {}): string { const map = Object.keys(params).reduce((arr: Array<string>, key: string) => { if (params[key] !== undefined) { |
