Skip to content

add stopwatcxh and timer#444

Merged
ingoau merged 2 commits intomainfrom
more-tools
Aug 8, 2025
Merged

add stopwatcxh and timer#444
ingoau merged 2 commits intomainfrom
more-tools

Conversation

@ingoau
Copy link
Member

@ingoau ingoau commented Aug 8, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a combined stopwatch and timer tool with separate tabs for each.
    • Stopwatch includes start, pause, reset, lap recording, and lap removal features.
    • Timer supports setting custom durations, quick preset buttons, start, pause, reset, progress bar, and status indicators.
    • Timer completion triggers a notification sound and visual alert.
    • Responsive and user-friendly interface with clear controls and indicators.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

A new Svelte page component was introduced at src/routes/tools/stopwatch-timer/+page.svelte, providing a combined stopwatch and timer tool. The component implements independent stopwatch and timer functionalities with separate controls, state management, lap tracking, timer presets, sound notifications, and a responsive UI using reusable components.

Changes

Cohort / File(s) Change Summary
Stopwatch & Timer Page Component
src/routes/tools/stopwatch-timer/+page.svelte
Added a Svelte page component implementing a combined stopwatch and timer tool with independent controls, lap tracking, presets, sound notifications, and responsive UI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StopwatchTimerPage
    participant WebAudioAPI

    User->>StopwatchTimerPage: Select Stopwatch or Timer tab
    alt Stopwatch tab
        User->>StopwatchTimerPage: Start/Pause/Reset/Lap
        StopwatchTimerPage->>StopwatchTimerPage: Update elapsed time, laps
    else Timer tab
        User->>StopwatchTimerPage: Set time / Start / Pause / Reset / Preset
        StopwatchTimerPage->>StopwatchTimerPage: Update countdown, progress
        StopwatchTimerPage-->>WebAudioAPI: Play notification sound (on finish)
        StopwatchTimerPage->>User: Show finished alert
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch more-tools

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
src/routes/tools/stopwatch-timer/+page.svelte (5)

10-10: Remove unused import onMount

The onMount lifecycle hook is imported but never used in the component.

-import { onMount, onDestroy } from 'svelte';
+import { onDestroy } from 'svelte';

27-31: Update comment to reflect actual formatting

The comment says "MM:SS.mmm" but the function actually formats to "MM:SS.cc" (centiseconds/hundredths of seconds, not milliseconds).

-// Format time from milliseconds to MM:SS.mmm
+// Format time from milliseconds to MM:SS.cc (centiseconds)

123-123: Improve type safety for webkit-prefixed AudioContext

Using as any bypasses TypeScript's type safety. Consider adding proper type declaration.

Add this type declaration at the top of the script section:

declare global {
  interface Window {
    webkitAudioContext: typeof AudioContext;
  }
}

Then update the line:

-const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
+const audioContext = new (window.AudioContext || window.webkitAudioContext)();

143-149: Remove unused effect or store the progress value

The effect calculates progress but doesn't store or use the value. The same calculation is duplicated in the template at line 338.

Either remove this unused effect:

-// Calculate timer progress percentage
-$effect(() => {
-  if (timerTotalTime > 0) {
-    const progress = ((timerTotalTime - timerCurrentTime) / timerTotalTime) * 100;
-    // You could use this for a progress bar if needed
-  }
-});

Or store the progress value for use in the template:

+let timerProgress = $state(0);

 // Calculate timer progress percentage
 $effect(() => {
   if (timerTotalTime > 0) {
-    const progress = ((timerTotalTime - timerCurrentTime) / timerTotalTime) * 100;
-    // You could use this for a progress bar if needed
+    timerProgress = ((timerTotalTime - timerCurrentTime) / timerTotalTime) * 100;
   }
 });

Then update line 338 to use {timerProgress}% instead of recalculating.


309-309: Extract timer presets to improve readability

The inline array of timer presets is quite long and makes the template harder to read.

Add this constant after the state declarations:

const TIMER_PRESETS = [
  { label: '1 min', minutes: 1, seconds: 0 },
  { label: '5 min', minutes: 5, seconds: 0 },
  { label: '10 min', minutes: 10, seconds: 0 },
  { label: '15 min', minutes: 15, seconds: 0 },
  { label: '25 min', minutes: 25, seconds: 0 },
  { label: '30 min', minutes: 30, seconds: 0 },
  { label: '45 min', minutes: 45, seconds: 0 },
  { label: '1 hour', minutes: 60, seconds: 0 }
];

Then update the template:

-{#each [{ label: '1 min', minutes: 1, seconds: 0 }, { label: '5 min', minutes: 5, seconds: 0 }, { label: '10 min', minutes: 10, seconds: 0 }, { label: '15 min', minutes: 15, seconds: 0 }, { label: '25 min', minutes: 25, seconds: 0 }, { label: '30 min', minutes: 30, seconds: 0 }, { label: '45 min', minutes: 45, seconds: 0 }, { label: '1 hour', minutes: 60, seconds: 0 }] as preset}
+{#each TIMER_PRESETS as preset}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59f6aa1 and ff10d95.

📒 Files selected for processing (1)
  • src/routes/tools/stopwatch-timer/+page.svelte (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.*

⚙️ CodeRabbit Configuration File

**/*.*: Do not correct spelling errors or grammar mistakes.

Files:

  • src/routes/tools/stopwatch-timer/+page.svelte
🔇 Additional comments (1)
src/routes/tools/stopwatch-timer/+page.svelte (1)

240-240: Verify browser support for toReversed() or add a fallback

Based on MDN data, Array.prototype.toReversed() is supported in:

  • Chrome 110+, Edge 110+, Firefox 115+, Safari 16.4+, Opera 96+
    If your target environments include older browsers, please choose one of the following:

• Polyfill at application startup:

// e.g. in src/app.js or a global helper
if (!Array.prototype.toReversed) {
  Array.prototype.toReversed = function() {
    return Array.from(this).reverse();
  };
}

• Use the built-in reverse on a shallow copy:

--- src/routes/tools/stopwatch-timer/+page.svelte
@@ Line 240
-{#each stopwatchLaps.toReversed() as lap, index}
+{#each [...stopwatchLaps].reverse() as lap, index}

• Or confirm that your project’s browser-support policy covers ES2023 features.

let stopwatchTime = $state(0); // in milliseconds
let stopwatchRunning = $state(false);
let stopwatchLaps = $state<number[]>([]);
let stopwatchInterval: NodeJS.Timeout | null = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Use correct browser timer type instead of NodeJS.Timeout

In browser environments, setInterval returns a number, not NodeJS.Timeout. Using Node.js types in a browser component can cause type errors.

-let stopwatchInterval: NodeJS.Timeout | null = null;
+let stopwatchInterval: number | null = null;
-let timerInterval: NodeJS.Timeout | null = null;
+let timerInterval: number | null = null;

Also applies to: 24-24

🤖 Prompt for AI Agents
In src/routes/tools/stopwatch-timer/+page.svelte at lines 16 and 24, replace the
type annotation NodeJS.Timeout with number for variables storing the result of
setInterval, as in browser environments setInterval returns a number, not a
NodeJS.Timeout. Update the type declarations accordingly to avoid type errors.

@ingoau ingoau merged commit 20ae0fe into main Aug 8, 2025
5 checks passed
@delete-merged-branch delete-merged-branch bot deleted the more-tools branch August 8, 2025 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant