[refactor] integrated the existing files into svelte structure
#TODO: updating the api
This commit is contained in:
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
48
src/features/countdown/state/countdown.store.ts
Normal file
48
src/features/countdown/state/countdown.store.ts
Normal 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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user