Changeset 084d1c0 in Klonkt


Ignore:
Timestamp:
06/30/2026 02:10:36 AM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
e0a1ec1
Parents:
f2eacca
Message:

fix(admin-audio): fediverse-share toggle is now AJAX (no page jump)

The new per-track fedi-share toggle used a form POST + redirect, so clicking it reloaded the
page and jumped to the top. It now toggles via AJAX in place, mirroring the download toggle.

  • src/views/pages/admin-audio.ejs — fedi button -> data-track-fedi + an AJAX click handler
  • src/routes/admin-audio.js — the /api/:id field-update route now accepts fedi_open

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

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/routes/admin-audio.js

    rf2eacca r084d1c0  
    494494    fields.push('downloadable = ?'); values.push(body.downloadable ? 1 : 0);
    495495  }
     496  if (Object.prototype.hasOwnProperty.call(body, 'fedi_open')) {
     497    fields.push('fedi_open = ?'); values.push(body.fedi_open ? 1 : 0);
     498  }
    496499  if (Object.prototype.hasOwnProperty.call(body, 'credit')) {
    497500    fields.push('credit = ?'); values.push(String(body.credit || '').trim() || null);
  • src/views/pages/admin-audio.ejs

    rf2eacca r084d1c0  
    123123                        style="<%= t.downloadable ? 'color:var(--accent,#6b8f71)' : 'opacity:.5' %>">⬇</button>
    124124              <% } %>
    125               <form action="/admin/audio/<%= t.id %>/fedi-open" method="post" class="ax-track-fedi" style="display:inline">
    126                 <button type="submit" class="ax-icon-btn"
    127                         aria-label="<%= t.fedi_open ? _aaudFediOn : _aaudFediOff %>" title="<%= t.fedi_open ? _aaudFediOn : _aaudFediOff %>"
    128                         style="<%= t.fedi_open ? 'color:var(--accent,#6b8f71)' : 'opacity:.5' %>">🌐</button>
    129               </form>
     125              <button type="button" class="ax-icon-btn" data-track-fedi data-id="<%= t.id %>" data-on="<%= t.fedi_open ? '1' : '0' %>"
     126                      aria-label="<%= t.fedi_open ? _aaudFediOn : _aaudFediOff %>" title="<%= t.fedi_open ? _aaudFediOn : _aaudFediOff %>"
     127                      style="<%= t.fedi_open ? 'color:var(--accent,#6b8f71)' : 'opacity:.5' %>">🌐</button>
    130128              <form action="/admin/audio/<%= t.id %>/delete" method="post" data-confirm="<%= _aaudDelConfirm %>" class="ax-track-delete">
    131129                <button type="submit" class="ax-icon-btn ax-icon-btn-danger" aria-label="<%= _aaudDelete %>" title="<%= _aaudDelete %>">🗑</button>
     
    10111009    });
    10121010  });
     1011
     1012  // Fediverse-share (fedi_open) toggle — AJAX, no page reload (mirrors the download toggle).
     1013  document.querySelectorAll('[data-track-fedi]').forEach(btn => {
     1014    btn.addEventListener('click', async () => {
     1015      if (btn.disabled) return;
     1016      const want = btn.dataset.on === '1' ? 0 : 1;
     1017      btn.disabled = true;
     1018      try {
     1019        const res = await fetch('/admin/audio/api/' + btn.dataset.id, {
     1020          method: 'POST',
     1021          headers: { 'Content-Type': 'application/json' },
     1022          body: JSON.stringify({ fedi_open: !!want }),
     1023        });
     1024        if (!res.ok) throw new Error('HTTP ' + res.status);
     1025        btn.dataset.on = String(want);
     1026        btn.style.color = want ? 'var(--accent,#6b8f71)' : '';
     1027        btn.style.opacity = want ? '1' : '.5';
     1028        btn.title = want ? '<%= t('aaud.fedi_on') %>' : '<%= t('aaud.fedi_off') %>';
     1029      } catch (e) {
     1030        alert('<%= t('aaud.change_failed') %>: ' + (e.message || e));
     1031      } finally {
     1032        btn.disabled = false;
     1033      }
     1034    });
     1035  });
    10131036})();
    10141037</script>
Note: See TracChangeset for help on using the changeset viewer.