- refactor backend service from single countdown to HashMap storage with generated IDs - add create/list/delete commands and make start/pause/resume/reset/snapshot ID-aware - introduce validation and new countdown errors (id/label/duration/state/action/max limit) - update frontend countdown snapshot typing/mapping to match backend DTO changes - add shared base Pico CSS overrides and import base styles
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import {invokeCommand} from "../../shared/tauri/invoke";
|
|
import {CountdownCommand, CountdownSnapshot, CountdownState, Duration} from "./types";
|
|
import {millisToDuration} from "./helper.ts";
|
|
|
|
type CountdownSnapshotDto = {
|
|
id: number;
|
|
label: string;
|
|
duration: number;
|
|
state: CountdownState;
|
|
start_epoch_ms: number | null;
|
|
target_epoch_ms: number | null;
|
|
};
|
|
|
|
export async function fetchCountdownSnapshot(): Promise<CountdownSnapshot> {
|
|
let temp = await invokeCommand<CountdownSnapshotDto>("countdown_snapshot");
|
|
const duration: Duration = millisToDuration(temp.duration);
|
|
return {
|
|
id: temp.id,
|
|
label: temp.label,
|
|
duration: duration,
|
|
state: temp.state,
|
|
start_epoch: temp.start_epoch_ms !== null ? new Date(temp.start_epoch_ms) : null,
|
|
target_epoch: temp.target_epoch_ms !== null ? new Date(temp.target_epoch_ms) : null,
|
|
};
|
|
}
|
|
|
|
async function invokeCountdownCommand(command: CountdownCommand): Promise<void> {
|
|
await invokeCommand<void>(command);
|
|
}
|
|
|
|
export async function startCountdown(): Promise<void> {
|
|
await invokeCountdownCommand("countdown_start");
|
|
}
|
|
|
|
export async function pauseCountdown(): Promise<void> {
|
|
await invokeCountdownCommand("countdown_pause");
|
|
}
|
|
|
|
export async function resumeCountdown(): Promise<void> {
|
|
await invokeCountdownCommand("countdown_resume");
|
|
}
|
|
|
|
export async function resetCountdown(): Promise<void> {
|
|
await invokeCountdownCommand("countdown_reset");
|
|
}
|