Onttraders commited on
Commit
ffab9b7
·
verified ·
1 Parent(s): 24f6450

🐳 13/04 - 09:46 - create a sharelink to share music

Browse files
Files changed (1) hide show
  1. index.html +69 -1
index.html CHANGED
@@ -186,6 +186,7 @@
186
  renderFeed();
187
  initPlayer();
188
  setupUpload();
 
189
  });
190
 
191
  // Setup Upload Interactions
@@ -318,7 +319,9 @@
318
  ${track.likes}
319
  </button>
320
  </div>
321
- <span class="text-xs text-gray-500">${timeAgo(track.timestamp)}</span>
 
 
322
  </div>
323
  </div>
324
  `).join('');
@@ -446,6 +449,71 @@
446
  function scrollToFeed() {
447
  document.getElementById('trackFeed').scrollIntoView({ behavior: 'smooth' });
448
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  </script>
450
  </body>
451
  </html>
 
186
  renderFeed();
187
  initPlayer();
188
  setupUpload();
189
+ checkSharedTrack();
190
  });
191
 
192
  // Setup Upload Interactions
 
319
  ${track.likes}
320
  </button>
321
  </div>
322
+ <button onclick="shareTrack(${track.id})" class="flex items-center gap-1 text-sm text-gray-400 hover:text-accent-blue transition-colors" title="Share track">
323
+ <i data-lucide="share-2" class="w-4 h-4"></i>
324
+ </button>
325
  </div>
326
  </div>
327
  `).join('');
 
449
  function scrollToFeed() {
450
  document.getElementById('trackFeed').scrollIntoView({ behavior: 'smooth' });
451
  }
452
+
453
+ function shareTrack(id) {
454
+ const track = tracks.find(t => t.id === id);
455
+ if (!track) return;
456
+
457
+ const shareUrl = `${window.location.origin}${window.location.pathname}?track=${id}`;
458
+
459
+ if (navigator.share) {
460
+ navigator.share({
461
+ title: `${track.title} by ${track.artist} on Beatfridge`,
462
+ text: `Check out "${track.title}" by ${track.artist} on Beatfridge!`,
463
+ url: shareUrl
464
+ }).catch(() => {
465
+ // Fallback to clipboard if share dialog dismissed
466
+ copyToClipboard(shareUrl);
467
+ });
468
+ } else {
469
+ copyToClipboard(shareUrl);
470
+ }
471
+ }
472
+
473
+ function copyToClipboard(text) {
474
+ const input = document.createElement('input');
475
+ input.value = text;
476
+ document.body.appendChild(input);
477
+ input.select();
478
+ document.execCommand('copy');
479
+ document.body.removeChild(input);
480
+
481
+ // Show feedback
482
+ const feedback = document.createElement('div');
483
+ feedback.className = 'fixed top-4 left-1/2 transform -translate-x-1/2 bg-accent-blue text-white px-6 py-3 rounded-full font-semibold shadow-2xl z-50';
484
+ feedback.textContent = 'Link copied to clipboard!';
485
+ document.body.appendChild(feedback);
486
+
487
+ setTimeout(() => {
488
+ feedback.remove();
489
+ }, 2000);
490
+ }
491
+
492
+ function checkSharedTrack() {
493
+ const params = new URLSearchParams(window.location.search);
494
+ const trackId = params.get('track');
495
+
496
+ if (trackId) {
497
+ const id = parseInt(trackId);
498
+ const track = tracks.find(t => t.id === id);
499
+
500
+ if (track) {
501
+ // Scroll to feed first
502
+ setTimeout(() => {
503
+ renderFeed(); // Ensure DOM is updated
504
+ const trackElement = document.querySelector(`[onclick="playTrack(${id})"]`);
505
+ if (trackElement) {
506
+ trackElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
507
+ }
508
+ // Auto-play the track
509
+ setTimeout(() => playTrack(id), 500);
510
+ }, 100);
511
+ }
512
+ }
513
+ }
514
+
515
+ // Check for shared track on load
516
+ window.addEventListener('load', checkSharedTrack);
517
  </script>
518
  </body>
519
  </html>