Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mytral/blueprints/strava_api_uri_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ def strava_api_developer():
)


@flask_app.route("/strava/sync/menu")
def strava_sync_from_menu():
"""One-click Strava sync triggered from the top-menu sync icon.

If a refresh token is available, authenticate silently (when the access
token is missing or expired) and start syncing new activities right away.
Without a refresh token, fall back to the interactive developer page so the
user can authenticate first - same as the Data / Import / Strava API flow.
"""
Comment on lines +140 to +146
user_id = flask.session.get(COOKIE_USER)
if not user_id:
return flask.redirect(flask.url_for("login"))
user_profile = ds.profile(user_id)
Comment on lines +147 to +150

# no refresh token -> keep the interactive flow on the developer page
if not strava.is_refresh_token_valid(user_profile):
return flask.redirect(flask.url_for("strava_api_developer"))

# refresh token available -> start the sync (silent refresh handled inside)
return strava_sync_new_to_current()
Comment on lines +152 to +157


@flask_app.route("/strava/api-secrets", methods=["GET", "POST"])
def strava_api_secrets():
"""Page to set (or clear) the encrypted Strava API client credentials."""
Expand Down
2 changes: 1 addition & 1 deletion mytral/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<div class="d-none d-md-flex">
{% if user_profile.strava_client_id and user_profile.strava_client_secret %}
<div class="nav-item">
<a href="{{ url_for('strava_api_developer') }}" class="nav-link px-0 position-relative" title="Synchronize activities w/ your favorite sport tracker service" data-bs-toggle="tooltip" data-bs-placement="bottom">
<a href="{{ url_for('strava_sync_from_menu') }}" class="nav-link px-0 position-relative" title="Synchronize activities w/ your favorite sport tracker service" data-bs-toggle="tooltip" data-bs-placement="bottom">
<span class="position-relative">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-refresh"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" /><path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" /></svg>
{% if sync_locked %}
Expand Down
Loading