diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-06-13 21:08:22 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-06-13 21:08:22 +0200 |
| commit | 3ff255b3f75d3c2d860ccd84aa06032f840ce0e6 (patch) | |
| tree | a693e36f007e5e4f3c20ecfffc91b2f2ad77b0ce /apps/projects/src/app | |
| parent | 39735309b2f2831ea8fe94104139fa0e9f6ace56 (diff) | |
| download | greatoffice-3ff255b3f75d3c2d860ccd84aa06032f840ce0e6.tar.xz greatoffice-3ff255b3f75d3c2d860ccd84aa06032f840ce0e6.zip | |
refactor: Introduce templated translation string for getting logged time today string
Diffstat (limited to 'apps/projects/src/app')
| -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 |
4 files changed, 27 insertions, 33 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; }); }); |
