Skip to content

Commit 39a8eb4

Browse files
committed
- playing around with the spotify API
1 parent 604cbc4 commit 39a8eb4

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

tools/spotify_test.html

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,38 @@
175175
function createQRCard(track) {
176176
const card = document.createElement('div');
177177
card.className = 'card';
178-
card.innerHTML = `
179-
<div class="card-inner">
180-
<div class="card-front" id="qr-${track.id}"></div>
181-
<div class="card-back">
182-
<div class="p-4">
183-
<h3 class="text-xl font-bold">${track.name}</h3>
184-
<p class="text-gray-600">${track.artist}</p>
185-
<p class="text-gray-500">${track.year}</p>
186-
</div>
187-
</div>
188-
</div>
189-
`;
190-
191-
new QRCode(document.getElementById(`qr-${track.id}`), {
192-
text: `https://www.gptgames.dev/tools/spotify_test.html?track=${track.id}`,
193-
width: 200,
194-
height: 200
195-
});
178+
179+
// Create the inner structure first
180+
const cardInner = document.createElement('div');
181+
cardInner.className = 'card-inner';
182+
183+
const cardFront = document.createElement('div');
184+
cardFront.className = 'card-front';
185+
cardFront.id = `qr-${track.id}`;
186+
187+
const cardBack = document.createElement('div');
188+
cardBack.className = 'card-back';
189+
cardBack.innerHTML = `
190+
<div class="p-4">
191+
<h3 class="text-xl font-bold">${track.name}</h3>
192+
<p class="text-gray-600">${track.artist}</p>
193+
<p class="text-gray-500">${track.year}</p>
194+
</div>
195+
`;
196+
197+
// Assemble the card
198+
cardInner.appendChild(cardFront);
199+
cardInner.appendChild(cardBack);
200+
card.appendChild(cardInner);
201+
202+
// Generate QR code after the element is in the DOM
203+
setTimeout(() => {
204+
new QRCode(cardFront, {
205+
text: `https://www.gptgames.dev/tools/spotify_test.html?track=${track.id}`,
206+
width: 200,
207+
height: 200
208+
});
209+
}, 0);
196210

197211
return card;
198212
}

0 commit comments

Comments
 (0)