Skip to content

Keep the units choice in step with the account - #8

Merged
aderaaij merged 1 commit into
mainfrom
units-sync
Nov 12, 2026
Merged

aderaaij merged 1 commit into
mainfrom
units-sync

Conversation

@aderaaij

Copy link
Copy Markdown
Owner

Stacked on #7. Needs the server change in aderaaij/loopback-training-server#12 to do anything; against an older server it changes nothing.

The server now stores the units preference on the user (GET/PUT /api/me/units), so the dashboard and the coach can follow the same choice as the phone.

What changes

  • Pull on launch and on every return to the foreground. If the account holds a choice, this device adopts it.
  • Push when the picker in Settings → Training changes.
  • First contact. If the account has no choice yet, the app offers its own: an explicit pick, or a device default of miles. A metric default is not sent. The server already reads "unset" as metric, and sending it could overwrite a miles choice still waiting in the athlete's browser.
  • Settings footer now says the choice also applies to the dashboard and the coach.

Failures are silent: no endpoint or no network leaves the local choice alone.

Checked

On the simulator against a local server built from the server PR:

  • Account on imperial, phone on Kilometers: after sign-in the phone switched to Miles.
  • Picking Kilometers on the phone: the account read metric within a couple of seconds.
  • Account changed to imperial through the API while the app was in the background: the picker read Miles on return.

Not checked: the first-contact offer from a miles-default device, and the log line for the fallback against a server without the endpoint (the app kept working against the 0.1.15 demo server, which is all I saw).

Deliberately not done

requiredServerVersion is not raised. The sync degrades to today's behaviour on an older server, so a "server is missing features" warning for it seemed like noise. Say so if you'd rather keep the gate strict.

The server now stores the units preference on the user, so the
dashboard and the coach can follow it. The app pulls it on launch and
on foreground, and pushes when the picker in Settings changes.

The server wins once it holds a choice. Until then the app offers its
own, except a metric default: the server already reads "unset" as
metric, and sending it could overwrite a miles choice still waiting in
the athlete's browser from before the preference moved server-side.

A server without the endpoint, or no network, leaves the local choice
as it was; nothing is shown to the athlete.
@aderaaij
aderaaij changed the base branch from readable-speed-alerts to main November 12, 2026 17:53
@aderaaij
aderaaij merged commit 17d20d5 into main Nov 12, 2026
@aderaaij aderaaij mentioned this pull request Nov 12, 2026
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