Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

869 B
Raw Blame
import { useEffect } from 'react'
import { useUI } from '../store/useUI.js'

// Flips the app's real light/dark theme on and off twice (~2.4s) instead of laying an
// opaque black/white rectangle over the screen — the alert reads as the app itself
// blinking, and it always settles back on whatever theme the user actually had.
export default function TimerFlash() {
  const id = useUI(s => s.timerFlashId)
  useEffect(() => {
    if (!id) return
    const de = document.documentElement
    const original = de.dataset.theme
    const opposite = original === 'light' ? 'dark' : 'light'
    const steps = [opposite, original, opposite, original]
    const timers = steps.map((theme, i) => setTimeout(() => { de.dataset.theme = theme }, i * 600))
    return () => {
      timers.forEach(clearTimeout)
      de.dataset.theme = original
    }
  }, [id])
  return null
}