PageSourceSearch

https://bikeindex.org/assets/controllers/strava_sync_status_contro…cc6e3e9f532508b1a6c92dfff282f35563f6e748.js

js bikeindex.org collected 2026-10-01 10:25:00 UTC 1,935 bytes, 54 lines download raw bytes

1import { Controller } from '@hotwired/stimulus'
2import { collapse } from 'utils/collapse_utils'
3
4// Polls the Strava sync status endpoint and updates the progress display
5// Connects to data-controller='strava-sync-status'
6export default class extends Controller {
7  static values = { url: String, isPending: Boolean }
8
9  connect () {
10    this.initialStatus = null
11    this.poll()
12  }
13
14  disconnect () {
15    if (this.timer) clearTimeout(this.timer)
16  }
17
18  poll () {
19    fetch(this.urlValue, {
20      headers: { Accept: 'application/json' }
21    })
22      .then(response => response.json())
23      .then(data => {
24        console.log(data)
25        if (this.initialStatus === null) this.initialStatus = data.status
26        if (data.status === 'syncing' || data.status === 'pending') {
27          this.updateProgress(data)
28          this.timer = setTimeout(() => this.poll(), 5000)
29        } else if (data.status === 'synced' || data.status === 'error') {
30          // Only reload if status changed from a non-final state
31          if (this.initialStatus !== data.status) window.location.reload()
32        }
33      })
34      .catch(() => {
35        // Retry after a longer delay on error
36        this.timer = setTimeout(() => this.poll(), 10000)
37      })
38  }
39
40  updateProgress (data) {
41    // If initially pending but now syncing, hide the pending text and show the syncing text
42    if (this.isPendingValue && data.status === 'syncing') {
43      collapse('hide', document.getElementById('strava-pending-message'))
44      collapse('show', document.getElementById('strava-syncing-message'))
45      this.isPendingValue = false
46    }
47
48    const countEl = document.getElementById('strava-download-count')
49    if (countEl) {
50      const fmt = (n) => n == null ? '?' : Number(n).toLocaleString()
51      countEl.textContent = `${data.progress_percent}% (${fmt(data.activities_downloaded_count)} / ${fmt(data.athlete_activity_count)}) downloaded`
52    }
53  }
54};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.