From 010efc185501c884067d43c9e9988cb479afacb9 Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Thu, 26 Feb 2026 20:51:37 +0100 Subject: [PATCH] fixed codex AI slop --- AGENTS.md | 1 + src/features/countdown/api.ts | 28 +++++--- src/features/countdown/helper.ts | 14 ++++ src/features/countdown/types.ts | 39 ++++++---- src/features/countdown/view.ts | 118 +++++++++++++++---------------- src/shared/time/format.ts | 17 ----- 6 files changed, 118 insertions(+), 99 deletions(-) create mode 100644 src/features/countdown/helper.ts delete mode 100644 src/shared/time/format.ts diff --git a/AGENTS.md b/AGENTS.md index 827c9c9..f6e77f7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,6 +10,7 @@ This is a learning project. The assistant is a guide, not an implementer. - If asked to implement code, the assistant should refuse and provide a clear plan the developer can execute. - If asked about a file, function, module, or crate, the assistant must read the current code first before answering. - Reviews and guidance must be based strictly on the current file contents, not earlier snapshots. +- Before each technical answer, the assistant must re-open the relevant files/outputs and verify against current on-disk state, never relying on memory from earlier turns. ## Project Structure & Module Organization This repository is a Tauri app with a TypeScript frontend and Rust backend. diff --git a/src/features/countdown/api.ts b/src/features/countdown/api.ts index 3679728..0f7be8f 100644 --- a/src/features/countdown/api.ts +++ b/src/features/countdown/api.ts @@ -1,26 +1,36 @@ -import { invokeCommand } from "../../shared/tauri/invoke"; -import type { CountdownCommand, CountdownSnapshotDto } from "./types"; +import {invokeCommand} from "../../shared/tauri/invoke"; +import type {CountdownCommand, CountdownSnapshot, CountdownSnapshotDto, Duration} from "./types"; +import {millisToDuration} from "./helper.ts"; -export async function fetchCountdownSnapshot(): Promise { - return invokeCommand("countdown_snapshot"); +export async function fetchCountdownSnapshot(): Promise { + let temp = await invokeCommand("countdown_snapshot"); + let duration: Duration = millisToDuration(temp.duration); + return { + id: temp.id, + label: temp.label, + duration: duration, + state: temp.state, + start_epoch_ms: temp.start_epoch_ms ? new Date(temp.start_epoch_ms) : null, + target_epoch_ms: temp.target_epoch_ms ? new Date(temp.target_epoch_ms) : null, + }; } async function invokeCountdownCommand(command: CountdownCommand): Promise { - await invokeCommand(command); + await invokeCommand(command); } export async function startCountdown(): Promise { - await invokeCountdownCommand("countdown_start"); + await invokeCountdownCommand("countdown_start"); } export async function pauseCountdown(): Promise { - await invokeCountdownCommand("countdown_pause"); + await invokeCountdownCommand("countdown_pause"); } export async function resumeCountdown(): Promise { - await invokeCountdownCommand("countdown_resume"); + await invokeCountdownCommand("countdown_resume"); } export async function resetCountdown(): Promise { - await invokeCountdownCommand("countdown_reset"); + await invokeCountdownCommand("countdown_reset"); } diff --git a/src/features/countdown/helper.ts b/src/features/countdown/helper.ts new file mode 100644 index 0000000..317e3ab --- /dev/null +++ b/src/features/countdown/helper.ts @@ -0,0 +1,14 @@ +import {Duration} from "./types.ts"; + +export function millisToDuration(millis: number): Duration { + return { + hours: Math.floor(millis / 3600000), + minutes: Math.floor((millis % 3600000) / 60000), + seconds: Math.floor((millis % 60000) / 1000), + millis: millis % 1000, + } +} + +export function formatDuration(duration: Duration): string { + return `${duration.hours.toString().padStart(2, '0')}:${duration.minutes.toString().padStart(2, '0')}:${duration.seconds.toString().padStart(2, '0')}.${duration.millis.toString().padStart(3, '0')}`; +} \ No newline at end of file diff --git a/src/features/countdown/types.ts b/src/features/countdown/types.ts index d3edc7c..3e98bbb 100644 --- a/src/features/countdown/types.ts +++ b/src/features/countdown/types.ts @@ -1,21 +1,32 @@ export type CountdownState = "Idle" | "Running" | "Paused" | "Finished"; -export type CountdownDuration = { - secs: number; - nanos: number; -}; +export type Duration = { + hours: number; + minutes: number; + seconds: number; + millis: number; +} export type CountdownSnapshotDto = { - id: number; - label: string; - duration: CountdownDuration; - state: CountdownState; - start_epoch_ms: number | null; - target_epoch_ms: number | null; + id: number; + label: string; + duration: number; + state: CountdownState; + start_epoch_ms: number | null; + target_epoch_ms: number | null; }; +export type CountdownSnapshot = { + id: number; + label: string; + duration: Duration; + state: CountdownState; + start_epoch_ms: Date | null; + target_epoch_ms: Date | null; +} + export type CountdownCommand = - | "countdown_start" - | "countdown_pause" - | "countdown_resume" - | "countdown_reset"; + | "countdown_start" + | "countdown_pause" + | "countdown_resume" + | "countdown_reset"; diff --git a/src/features/countdown/view.ts b/src/features/countdown/view.ts index 38a5903..2b7cb5a 100644 --- a/src/features/countdown/view.ts +++ b/src/features/countdown/view.ts @@ -1,77 +1,77 @@ -import { formatDuration } from "../../shared/time/format"; -import type { CountdownSnapshotDto } from "./types"; +import {formatDuration} from "./helper.ts"; +import {CountdownSnapshot} from "./types.ts"; export type CountdownView = { - onStart: (handler: () => void) => void; - onPause: (handler: () => void) => void; - onResume: (handler: () => void) => void; - onReset: (handler: () => void) => void; - onRefresh: (handler: () => void) => void; - setSnapshot: (snapshot: CountdownSnapshotDto) => void; - setError: (message: string) => void; + onStart: (handler: () => void) => void; + onPause: (handler: () => void) => void; + onResume: (handler: () => void) => void; + onReset: (handler: () => void) => void; + onRefresh: (handler: () => void) => void; + setSnapshot: (snapshot: CountdownSnapshot) => void; + setError: (message: string) => void; }; function makeButton(label: string): HTMLButtonElement { - const button = document.createElement("button"); - button.type = "button"; - button.textContent = label; - return button; + const button = document.createElement("button"); + button.type = "button"; + button.textContent = label; + return button; } export function createCountdownView(container: HTMLElement): CountdownView { - const panel = document.createElement("section"); - panel.className = "countdown-panel"; + const panel = document.createElement("section"); + panel.className = "countdown-panel"; - const title = document.createElement("h2"); - title.textContent = "Countdown Controls"; + const title = document.createElement("h2"); + title.textContent = "Countdown Controls"; - const actions = document.createElement("div"); - actions.className = "countdown-actions"; + const actions = document.createElement("div"); + actions.className = "countdown-actions"; - const startButton = makeButton("Start"); - const pauseButton = makeButton("Pause"); - const resumeButton = makeButton("Resume"); - const resetButton = makeButton("Reset"); - const refreshButton = makeButton("Refresh"); + const startButton = makeButton("Start"); + const pauseButton = makeButton("Pause"); + const resumeButton = makeButton("Resume"); + const resetButton = makeButton("Reset"); + const refreshButton = makeButton("Refresh"); - actions.append(startButton, pauseButton, resumeButton, resetButton, refreshButton); + actions.append(startButton, pauseButton, resumeButton, resetButton, refreshButton); - const summary = document.createElement("p"); - summary.className = "countdown-summary"; - summary.textContent = "Waiting for snapshot..."; + const summary = document.createElement("p"); + summary.className = "countdown-summary"; + summary.textContent = "Waiting for snapshot..."; - const error = document.createElement("p"); - error.className = "countdown-error"; + const error = document.createElement("p"); + error.className = "countdown-error"; - const snapshot = document.createElement("pre"); - snapshot.className = "countdown-snapshot"; + const snapshot = document.createElement("pre"); + snapshot.className = "countdown-snapshot"; - panel.append(title, actions, summary, error, snapshot); - container.appendChild(panel); + panel.append(title, actions, summary, error, snapshot); + container.appendChild(panel); - return { - onStart(handler) { - startButton.addEventListener("click", handler); - }, - onPause(handler) { - pauseButton.addEventListener("click", handler); - }, - onResume(handler) { - resumeButton.addEventListener("click", handler); - }, - onReset(handler) { - resetButton.addEventListener("click", handler); - }, - onRefresh(handler) { - refreshButton.addEventListener("click", handler); - }, - setSnapshot(value) { - error.textContent = ""; - summary.textContent = `State: ${value.state} | Remaining: ${formatDuration(value.duration)}`; - snapshot.textContent = JSON.stringify(value, null, 2); - }, - setError(message) { - error.textContent = message; - }, - }; + return { + onStart(handler) { + startButton.addEventListener("click", handler); + }, + onPause(handler) { + pauseButton.addEventListener("click", handler); + }, + onResume(handler) { + resumeButton.addEventListener("click", handler); + }, + onReset(handler) { + resetButton.addEventListener("click", handler); + }, + onRefresh(handler) { + refreshButton.addEventListener("click", handler); + }, + setSnapshot(value) { + error.textContent = ""; + summary.textContent = `State: ${value.state} | Remaining: ${formatDuration(value.duration)}`; + snapshot.textContent = JSON.stringify(value, null, 2); + }, + setError(message) { + error.textContent = message; + }, + }; } diff --git a/src/shared/time/format.ts b/src/shared/time/format.ts deleted file mode 100644 index a117ef5..0000000 --- a/src/shared/time/format.ts +++ /dev/null @@ -1,17 +0,0 @@ -type DurationLike = { - secs?: number; - nanos?: number; -}; - -export function formatDuration(value: DurationLike): string { - const totalSeconds = Math.max(0, Math.floor(value.secs ?? 0)); - const hours = Math.floor(totalSeconds / 3600) - .toString() - .padStart(2, "0"); - const minutes = Math.floor((totalSeconds % 3600) / 60) - .toString() - .padStart(2, "0"); - const seconds = (totalSeconds % 60).toString().padStart(2, "0"); - - return `${hours}:${minutes}:${seconds}`; -}