[refactor] integrated the existing files into svelte structure

#TODO: updating the api
This commit is contained in:
2026-02-27 21:23:20 +01:00
parent 1b82ef653e
commit 79770152a1
6 changed files with 54 additions and 54 deletions

View File

@@ -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;

View File

@@ -1,48 +0,0 @@
import {
fetchCountdownSnapshot,
pauseCountdown,
resetCountdown,
resumeCountdown,
startCountdown,
} from "./api";
import { createCountdownView } from "./view";
export async function initCountdownController(container: HTMLElement): Promise<void> {
const view = createCountdownView(container);
const refreshSnapshot = async (): Promise<void> => {
try {
const snapshot = await fetchCountdownSnapshot();
view.setSnapshot(snapshot);
} catch (error) {
view.setError(`snapshot error: ${String(error)}`);
}
};
const runAction = async (action: () => Promise<void>): Promise<void> => {
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();
}

View File

@@ -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";

View File

@@ -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<void> {
const view = createCountdownView(container);
const refreshSnapshot = async (): Promise<void> => {
try {
const snapshot = await fetchCountdownSnapshot();
view.setSnapshot(snapshot);
} catch (error) {
view.setError(`snapshot error: ${String(error)}`);
}
};
const runAction = async (action: () => Promise<void>): Promise<void> => {
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();
}

View File

@@ -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;