Signed in, the server's profile is the truth: sign-in and pairing adopt it and ask once about workouts logged while signed out (Add them / Keep profile as is); the app polls the revision every 30 s and on every resume (GET /api/data/rev) and fetches only what moved; offline and unsynced states show a banner, retry on reconnect and confirm with a toast; pagehide flushes a pending change

This commit is contained in:
Duarte Santos committed 2026-09-12 21:51:36 +02:00
1 parent 28a068b8f0
commit 826432a3a2
30 files changed
+541 -37

No files matched your search

+3 -2
View File
@@ -8,6 +8,7 @@ import { guestAllowed } from '../lib/guest.js'
import { useState, useRef, useEffect } from 'react'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
import { askAddDeviceData } from '../sheets.jsx'
function RegisterSheet({ close }) {
const { setUser, pushState, pullState, loadConfig } = useStore()
@@ -47,11 +48,11 @@ function RegisterSheet({ close }) {
}
export default function Login() {
const { setUser, pullState, setGuest } = useStore()
const { setUser, adoptProfile, setGuest } = useStore()
const config = useStore(s => s.config)
const canGuest = guestAllowed(config)
const signIn = async () => {
try { const u = await passkeyLogin(); setUser(u); await pullState(); useUI.getState().toast(t('Welcome back, {0}', u.name)) }
try { const u = await passkeyLogin(); setUser(u); await adoptProfile(askAddDeviceData); useUI.getState().toast(t('Welcome back, {0}', u.name)) }
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || t('Sign-in failed')) }
}
const head = <>
+2 -1
View File
@@ -7,6 +7,7 @@ import { useUI } from '../store/useUI.js'
import { t } from '../lib/i18n.js'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
import { askAddDeviceData } from '../sheets.jsx'
export function ConnectSheet({ close }) {
const { connectToServer } = useStore()
@@ -18,7 +19,7 @@ export function ConnectSheet({ close }) {
const go = async () => {
if (!url.trim() || !code.trim()) { useUI.getState().toast(t('Enter your server address and the code')); return }
setBusy(true)
try { await connectToServer(url.trim(), code.trim()); close(); useUI.getState().toast(t('Connected')) }
try { await connectToServer(url.trim(), code.trim(), askAddDeviceData); close(); useUI.getState().toast(t('Connected')) }
catch (e) { useUI.getState().toast(e.message || t('Could not connect')) }
finally { setBusy(false) }
}
+3 -3
View File
@@ -15,7 +15,7 @@ import { MOBILE, isAndroid, shareExport, syncReminder } from '../lib/mobile.js'
import { checkForUpdate, downloadAndInstall } from '../lib/update.js'
import { forgetCoach } from '../lib/coach-api.js'
import { ConnectSheet } from './MobileOnboarding.jsx'
import { starterPlanSheet, confirmSheet, importFromApp, importFromHevy, equipmentProfileSheet, menuSheet } from '../sheets.jsx'
import { starterPlanSheet, confirmSheet, importFromApp, importFromHevy, equipmentProfileSheet, menuSheet, askAddDeviceData } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Section, Row, SelectRow, Switch, Segmented, Button, TextField } from '../components/ui.jsx'
@@ -24,7 +24,7 @@ export default function Settings() {
const S = useStore(s => s.S)
const user = useStore(s => s.user)
const coachLocal = useStore(s => s.coachLocal)
const { update, replaceState, setUser, pullState, pushState, signOut, signOutAll, resetDemo, disconnectServer } = useStore()
const { update, replaceState, setUser, pullState, pushState, adoptProfile, signOut, signOutAll, resetDemo, disconnectServer } = useStore()
const toast = useUI(s => s.toast)
const fileRef = useRef(null)
const importRef = useRef(null)
@@ -143,7 +143,7 @@ export default function Settings() {
rd.readAsText(f)
}
const signInHere = async () => {
try { const u = await passkeyLogin(); setUser(u); await pullState(); toast(t('Welcome back, {0}', u.name)) }
try { const u = await passkeyLogin(); setUser(u); await adoptProfile(askAddDeviceData); toast(t('Welcome back, {0}', u.name)) }
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || t('Sign-in failed')) }
}
const registerHere = () => useUI.getState().openSheet(close => <RegisterInline close={close} setUser={setUser} pushState={pushState} pullState={pullState} toast={toast} />)