Changeset fa08981 in Klonkt for src/assets/js/audio-player.js


Ignore:
Timestamp:
06/20/2026 01:52:46 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
8f6225c
Parents:
230e446
Message:

fix(player): scroll-to-track works for site-wide tracks too

Site-wide tracks (PCMS_SITE_TRACKS) were not getting an id → no anchor; and
no postUrl → no jump. Now: id included in the queue; mini-player click uses
postUrl when known, otherwise looks up the post via new endpoint
GET /audio/track/:id/post (newest post with [[track:<id>]]) and jumps +
scrolls to the track. audio-player.js?v=18.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/assets/js/audio-player.js

    r230e446 rfa08981  
    592592    const t = queue[currentIndex];
    593593    const isDesktop = window.matchMedia && window.matchMedia('(min-width: 768px)').matches;
    594     if (isDesktop && t && t.postUrl) { goToPost(t.postUrl, t.id); return; }
     594    if (isDesktop && t) {
     595      // 1) Track speelde vanuit een post → die URL kennen we al.
     596      if (t.postUrl) { goToPost(t.postUrl, t.id); return; }
     597      // 2) Site-brede track (geen postUrl) → zoek de post op via de track-id.
     598      if (t.id) {
     599        fetch('/audio/track/' + encodeURIComponent(t.id) + '/post')
     600          .then((r) => (r.ok ? r.json() : null))
     601          .then((d) => { if (d && d.url) goToPost(d.url, t.id); else openSheet(); })
     602          .catch(() => openSheet());
     603        return;
     604      }
     605    }
    595606    openSheet();
    596607  });
     
    831842    if (Array.isArray(window.PCMS_SITE_TRACKS) && window.PCMS_SITE_TRACKS.length) {
    832843      queue = window.PCMS_SITE_TRACKS.map(t => ({
     844        id:     t.id || null,
    833845        url:    t.media_url || t.url,
    834846        title:  t.title  || 'Untitled',
Note: See TracChangeset for help on using the changeset viewer.