Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating dashboard.html #37

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions public/webpages/html/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ <h4>Crime</h4>
<section class="featured-books">
<div class="section-header">
<h3>Featured Books</h3>
</div>


<div class="books-grid" id="featured-books-container">
Expand Down Expand Up @@ -321,41 +322,37 @@ <h3>Top 3 Recommendations for You</h3>
searchInput.style.display = "none";
}
}

async function fetchTopRecommendations() {
const API_KEY = 'AIzaSyDHChLI4vatYILeQOWr24nHr4kSap9dwAM'; // Replace with your Google API key
async function fetchTopRecommendations() {
const API_KEY = 'AIzaSyDHChLI4vatYILeQOWr24nHr4kSap9dwAM'; // Replace with your actual API key
const API_URL = `https://www.googleapis.com/books/v1/volumes?q=fiction&maxResults=3&key=${API_KEY}`;

try {

const response = await fetch(API_URL);
const data = await response.json();


const recommendationsContainer = document.getElementById('recommendations-container');
recommendationsContainer.innerHTML = ''; // Clear any previous content


if (data.items) {

data.items.slice(0, 3).forEach((book, index) => {
const bookItem = document.createElement('div');
bookItem.classList.add('recommendation-item');


const number = document.createElement('span');
number.classList.add('number');
number.textContent = index + 1;

const link = document.createElement('a');
link.href = `https://books.google.com/books?id=${book.id}`;
link.target = "_blank"; // Open in a new tab

const image = document.createElement('img');
image.src = book.volumeInfo.imageLinks ? book.volumeInfo.imageLinks.thumbnail : '../../images/placeholder.jpg';
image.alt = book.volumeInfo.title;


link.appendChild(image);
bookItem.appendChild(number);
bookItem.appendChild(image);


bookItem.appendChild(link);
recommendationsContainer.appendChild(bookItem);
});
} else {
Expand All @@ -366,39 +363,32 @@ <h3>Top 3 Recommendations for You</h3>
}
}


fetchTopRecommendations();


async function fetchFeaturedBooks() {
const API_KEY = 'AIzaSyDHChLI4vatYILeQOWr24nHr4kSap9dwAM'; // Replace with your actual API key
const API_URL = `https://www.googleapis.com/books/v1/volumes?q=fiction&maxResults=10&key=${API_KEY}`;

try {

const response = await fetch(API_URL);
const data = await response.json();


const featuredBooksContainer = document.getElementById('featured-books-container');
featuredBooksContainer.innerHTML = ''; // Clear any previous content


if (data.items) {
// Loop through the items and add them to the container
data.items.forEach((book, index) => {
data.items.forEach((book) => {
const bookCard = document.createElement('div');
bookCard.classList.add('book-card');


const link = document.createElement('a');
link.href = `https://books.google.com/books?id=${book.id}`;
link.target = "_blank"; // Open in a new tab

const image = document.createElement('img');
image.src = book.volumeInfo.imageLinks ? book.volumeInfo.imageLinks.thumbnail : '../../images/placeholder.jpg';
image.alt = book.volumeInfo.title;


bookCard.appendChild(image);


link.appendChild(image);
bookCard.appendChild(link);
featuredBooksContainer.appendChild(bookCard);
});
} else {
Expand All @@ -409,8 +399,9 @@ <h3>Top 3 Recommendations for You</h3>
}
}


fetchTopRecommendations();
fetchFeaturedBooks();

</script>

<footer>
Expand Down