2025-05-24 16:47:32 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const bookId = urlParams.get('id');
|
2025-05-24 19:23:52 +02:00
|
|
|
const bookDetails = document.getElementById('book-details');
|
|
|
|
|
|
|
|
if (!bookId) {
|
|
|
|
bookDetails.innerHTML = `
|
|
|
|
<div class="col-12 text-center py-5">
|
|
|
|
<h2 class="text-danger">Nieprawidłowe ID książki</h2>
|
|
|
|
<a href="/" class="btn btn-gothic mt-3">Powrót do strony głównej</a>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
return;
|
|
|
|
}
|
2025-05-24 16:47:32 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await fetch(`/api/ksiazki/${bookId}`);
|
2025-05-24 19:23:52 +02:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Status: ${response.status}`);
|
|
|
|
}
|
2025-05-24 16:47:32 +02:00
|
|
|
const book = await response.json();
|
|
|
|
|
|
|
|
document.getElementById('book-title').textContent = book.tytul;
|
|
|
|
document.getElementById('book-author').textContent = `Autor: ${book.autor}`;
|
|
|
|
document.getElementById('book-price').textContent = `Cena: ${book.cena} PLN`;
|
2025-05-24 19:23:52 +02:00
|
|
|
document.getElementById('book-description').textContent = book.opis;
|
|
|
|
document.getElementById('book-cover').src = book.obraz_url;
|
2025-05-24 16:47:32 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Błąd:', error);
|
2025-05-24 19:23:52 +02:00
|
|
|
bookDetails.innerHTML = `
|
|
|
|
<div class="col-12 text-center py-5">
|
|
|
|
<h2 class="text-danger">Błąd ładowania książki</h2>
|
|
|
|
<p>${error.message}</p>
|
2025-05-24 16:47:32 +02:00
|
|
|
<a href="/" class="btn btn-gothic mt-3">Powrót do strony głównej</a>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
});
|