Importing a plan whose exercise ids this build doesn't know — a
hand-edited file, an export from a build with a different dataset — put
those ids straight into a routine. The routine editor skipped them
silently (you could neither see nor delete them), and starting the
routine reached for ex.n on undefined: white screen, no tab bar, no way
back. The running workout is persisted, so it came back on every reload.
Three layers, so this class of bug can't reach the screen again:
· parsePlan() drops ids that resolve to neither the library nor a
custom exercise carried in the same file, and the import sheet says
how many were left out.
· exOr() renders an unresolvable id as a placeholder, so the routine
editor shows it (and lets you remove it) instead of hiding it, and
the workout view survives one.
· an ErrorBoundary around the routes: it keeps the tab bar alive,
offers a reload, and can discard a running workout that can't be
drawn. It is keyed on the route, so switching tabs clears it.
Turning the schedule switch on now really replaces Mon–Sun, as the
switch has always claimed. It only wrote the days the shared plan filled,
so days it left empty kept your own routine and you silently ended up
training a mix of two plans.
Also here, because they sit in the same lines: the tags that carry a unit
or a whole sentence opt out of the capitalise rule ("Best: 85 Kg", "Last
Time You Hit All Reps"), and the workout header's "best" now includes the
working weight you confirmed, so it agrees with the sheet that asked for
it.
94 lines
3.7 KiB
React
94 lines
3.7 KiB
React
import { useEffect } from 'react'
|
|
import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation } from 'react-router-dom'
|
|
import { useStore } from './store/useStore.js'
|
|
import { useUI } from './store/useUI.js'
|
|
import { bindUI } from './components/ui.jsx'
|
|
import { ACCENTS } from './lib/format.js'
|
|
import { setLang, useLang } from './lib/i18n.js'
|
|
import { setNav } from './lib/nav.js'
|
|
import { startFlow } from './sheets.jsx'
|
|
import Icon from './components/Icon.jsx'
|
|
import TabBar from './components/TabBar.jsx'
|
|
import ErrorBoundary from './components/ErrorBoundary.jsx'
|
|
import Modals from './components/Modals.jsx'
|
|
import Toast from './components/Toast.jsx'
|
|
import RestTimer from './components/RestTimer.jsx'
|
|
import Login from './views/Login.jsx'
|
|
import Home from './views/Home.jsx'
|
|
import Plan from './views/Plan.jsx'
|
|
import RoutineEdit from './views/RoutineEdit.jsx'
|
|
import Workout from './views/Workout.jsx'
|
|
import Stats from './views/Stats.jsx'
|
|
import History from './views/History.jsx'
|
|
import Library from './views/Library.jsx'
|
|
import Settings from './views/Settings.jsx'
|
|
import Admin from './views/Admin.jsx'
|
|
|
|
bindUI(useUI) // lets the shared controls open sheets without importing the store at module scope
|
|
|
|
function applyPrefs(theme, accent) {
|
|
const de = document.documentElement
|
|
de.dataset.theme = theme === 'light' ? 'light' : 'dark'
|
|
de.dataset.accent = ACCENTS[accent] ? accent : 'lime'
|
|
const meta = document.querySelector('meta[name="theme-color"]')
|
|
if (meta) meta.content = de.dataset.theme === 'light' ? '#f2f2f7' : '#000000'
|
|
}
|
|
|
|
function Shell() {
|
|
const navigate = useNavigate()
|
|
const loc = useLocation()
|
|
const { S, user, ready } = useStore()
|
|
const isGuest = useStore(s => s.isGuest())
|
|
const langV = useLang() // re-renders the whole shell when the language (pack) changes
|
|
useEffect(() => { setNav(navigate) }, [navigate])
|
|
useEffect(() => { applyPrefs(S.theme, S.accent) }, [S.theme, S.accent])
|
|
useEffect(() => { setLang(S.lang || 'en') }, [S.lang])
|
|
useEffect(() => { document.documentElement.lang = S.lang || 'en' }, [langV, S.lang])
|
|
// every tab/route change starts at the top of the page
|
|
useEffect(() => { window.scrollTo(0, 0) }, [loc.pathname])
|
|
|
|
const authed = user || isGuest
|
|
if (!ready && !authed) return (
|
|
<div id="app">
|
|
<div style={{ paddingTop: '44vh', display: 'flex', justifyContent: 'center', fontSize: 34, color: 'var(--label-3)' }}>
|
|
<Icon name="dumbbell" />
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<>
|
|
{/* keyed on the route: a view that throws is contained, and switching tabs
|
|
re-mounts the boundary, so the tab bar is always a way out */}
|
|
<div id="app" className="vfade" key={loc.pathname}>
|
|
<ErrorBoundary>
|
|
{!authed ? <Login /> : (
|
|
<Routes>
|
|
<Route path="/home" element={<Home />} />
|
|
<Route path="/plan" element={<Plan />} />
|
|
<Route path="/plan/r/:id" element={<RoutineEdit />} />
|
|
<Route path="/workout" element={<Workout />} />
|
|
<Route path="/stats" element={<Stats />} />
|
|
<Route path="/history" element={<History />} />
|
|
<Route path="/library" element={<Library />} />
|
|
<Route path="/settings" element={<Settings />} />
|
|
<Route path="/admin" element={user?.admin ? <Admin /> : <Navigate to="/home" replace />} />
|
|
<Route path="*" element={<Navigate to="/home" replace />} />
|
|
</Routes>
|
|
)}
|
|
</ErrorBoundary>
|
|
</div>
|
|
<TabBar onStart={startFlow} />
|
|
<RestTimer />
|
|
<Modals />
|
|
<Toast />
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default function App() {
|
|
const boot = useStore(s => s.boot)
|
|
useEffect(() => { boot() }, [boot])
|
|
return <HashRouter><Shell /></HashRouter>
|
|
}
|