From 79770152a103cf7e2c45212202749b05a9d495bb Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Fri, 27 Feb 2026 21:23:20 +0100 Subject: [PATCH] [refactor] integrated the existing files into svelte structure #TODO: updating the api --- .../{api.ts => api/countdown.client.ts} | 6 +-- .../components/CountdownManager.svelte | 0 src/features/countdown/controller.ts | 48 ------------------- .../{types.ts => model/countdown.types.ts} | 2 +- .../countdown/state/countdown.store.ts | 48 +++++++++++++++++++ src/features/countdown/view.ts | 4 +- 6 files changed, 54 insertions(+), 54 deletions(-) rename src/features/countdown/{api.ts => api/countdown.client.ts} (84%) create mode 100644 src/features/countdown/components/CountdownManager.svelte delete mode 100644 src/features/countdown/controller.ts rename src/features/countdown/{types.ts => model/countdown.types.ts} (86%) create mode 100644 src/features/countdown/state/countdown.store.ts diff --git a/src/features/countdown/api.ts b/src/features/countdown/api/countdown.client.ts similarity index 84% rename from src/features/countdown/api.ts rename to src/features/countdown/api/countdown.client.ts index 96c3cb2..93948e9 100644 --- a/src/features/countdown/api.ts +++ b/src/features/countdown/api/countdown.client.ts @@ -1,6 +1,6 @@ -import {invokeCommand} from "../../shared/tauri/invoke"; -import {CountdownCommand, CountdownSnapshot, CountdownState, Duration} from "./types"; -import {millisToDuration} from "./helper.ts"; +import {invokeCommand} from "../../../shared/tauri/invoke"; +import type {CountdownCommand, CountdownSnapshot, CountdownState} from "../model/countdown.types"; +import {type Duration, millisToDuration} from "../../../shared/time/duration"; type CountdownSnapshotDto = { id: number; diff --git a/src/features/countdown/components/CountdownManager.svelte b/src/features/countdown/components/CountdownManager.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/features/countdown/controller.ts b/src/features/countdown/controller.ts deleted file mode 100644 index 025d1d9..0000000 --- a/src/features/countdown/controller.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - fetchCountdownSnapshot, - pauseCountdown, - resetCountdown, - resumeCountdown, - startCountdown, -} from "./api"; -import { createCountdownView } from "./view"; - -export async function initCountdownController(container: HTMLElement): Promise { - const view = createCountdownView(container); - - const refreshSnapshot = async (): Promise => { - try { - const snapshot = await fetchCountdownSnapshot(); - view.setSnapshot(snapshot); - } catch (error) { - view.setError(`snapshot error: ${String(error)}`); - } - }; - - const runAction = async (action: () => Promise): Promise => { - try { - await action(); - await refreshSnapshot(); - } catch (error) { - view.setError(`command error: ${String(error)}`); - } - }; - - view.onStart(() => { - void runAction(startCountdown); - }); - view.onPause(() => { - void runAction(pauseCountdown); - }); - view.onResume(() => { - void runAction(resumeCountdown); - }); - view.onReset(() => { - void runAction(resetCountdown); - }); - view.onRefresh(() => { - void refreshSnapshot(); - }); - - await refreshSnapshot(); -} diff --git a/src/features/countdown/types.ts b/src/features/countdown/model/countdown.types.ts similarity index 86% rename from src/features/countdown/types.ts rename to src/features/countdown/model/countdown.types.ts index d206929..f64b343 100644 --- a/src/features/countdown/types.ts +++ b/src/features/countdown/model/countdown.types.ts @@ -1,4 +1,4 @@ -import type {Duration} from "../../shared/time/duration"; +import type {Duration} from "../../../shared/time/duration"; export type CountdownState = "Idle" | "Running" | "Paused" | "Finished"; diff --git a/src/features/countdown/state/countdown.store.ts b/src/features/countdown/state/countdown.store.ts new file mode 100644 index 0000000..d194d48 --- /dev/null +++ b/src/features/countdown/state/countdown.store.ts @@ -0,0 +1,48 @@ +import { + fetchCountdownSnapshot, + pauseCountdown, + resetCountdown, + resumeCountdown, + startCountdown, +} from "../api/countdown.client"; +import {createCountdownView} from "../view"; + +export async function initCountdownController(container: HTMLElement): Promise { + const view = createCountdownView(container); + + const refreshSnapshot = async (): Promise => { + try { + const snapshot = await fetchCountdownSnapshot(); + view.setSnapshot(snapshot); + } catch (error) { + view.setError(`snapshot error: ${String(error)}`); + } + }; + + const runAction = async (action: () => Promise): Promise => { + try { + await action(); + await refreshSnapshot(); + } catch (error) { + view.setError(`command error: ${String(error)}`); + } + }; + + view.onStart(() => { + void runAction(startCountdown); + }); + view.onPause(() => { + void runAction(pauseCountdown); + }); + view.onResume(() => { + void runAction(resumeCountdown); + }); + view.onReset(() => { + void runAction(resetCountdown); + }); + view.onRefresh(() => { + void refreshSnapshot(); + }); + + await refreshSnapshot(); +} diff --git a/src/features/countdown/view.ts b/src/features/countdown/view.ts index 7dff44e..ec2bc29 100644 --- a/src/features/countdown/view.ts +++ b/src/features/countdown/view.ts @@ -1,5 +1,5 @@ -import {formatDuration} from "./helper.ts"; -import {CountdownSnapshot} from "./types.ts"; +import type {CountdownSnapshot} from "./model/countdown.types"; +import {formatDuration} from "../../shared/time/duration"; export type CountdownView = { onStart: (handler: () => void) => void;