-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
// initializeThemeToggle(); | ||
|
||
// Theme toggling and like button interactions | ||
// function initializeThemeToggle() { | ||
// const lightThemeButton = document.getElementById('lightTheme'); | ||
// const darkThemeButton = document.getElementById('darkTheme'); | ||
// const bodyElement = document.body; | ||
|
||
// lightThemeButton.addEventListener('click', () => bodyElement.classList.remove('dark-theme')); | ||
// darkThemeButton.addEventListener('click', () => bodyElement.classList.add('dark-theme')); | ||
// } | ||
function aboutPageAnimation() { | ||
const dots = document.querySelectorAll('.dot'); // Use querySelectorAll to get all elements with class 'dot' | ||
const items = document.querySelectorAll('.item'); // Get all items for reference | ||
|
||
dots.forEach((dot, index) => { | ||
dot.addEventListener('click', () => { | ||
const item = items[index]; // Get the corresponding item | ||
const item = items[index]; | ||
item.scrollIntoView({ | ||
behavior: 'smooth', | ||
inline: 'center' // Changed from 'start' to 'center' to align item in the center | ||
inline: 'center' | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
// Call this function when the about page is loaded | ||
document.addEventListener('DOMContentLoaded', aboutPageAnimation); |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,33 @@ | ||
export function initializeLikeButtons() { | ||
const likeButtons = document.querySelectorAll(".likeButton"); | ||
|
||
likeButtons.forEach((button) => { | ||
button.addEventListener("click", function () { | ||
const heartIcon = this.querySelector(".i-heart"); | ||
|
||
heartIcon.classList.toggle("bi-heart"); | ||
heartIcon.classList.toggle("bi-heart-fill"); | ||
|
||
const isFavourite = heartIcon.classList.contains("bi-heart-fill"); | ||
const container = button.closest('.card-body'); | ||
const name = container.querySelector(".resName").textContent; | ||
const placeID = container.querySelector(".resLink").href.split("place_id:")[1]; | ||
|
||
const restaurantIndex = currentResults.findIndex(restaurant => restaurant.place_id === placeID); | ||
|
||
if (restaurantIndex !== -1) { | ||
currentResults[restaurantIndex].isLiked = !currentResults[restaurantIndex].isLiked; | ||
heartIcon.classList.toggle("bi-heart"); | ||
heartIcon.classList.toggle("bi-heart-fill"); | ||
} else { | ||
console.error("Restaurant not found in current results"); | ||
} | ||
|
||
const userResDB = { | ||
userID: sessionStorage.getItem("userId"), | ||
resName: name, | ||
placeID: placeID | ||
}; | ||
|
||
if (isFavourite) { | ||
addToFavourites(userResDB, heartIcon); | ||
} else { | ||
removeFromFavourites(userResDB, heartIcon); | ||
} | ||
window.onload = () => { | ||
const userId = sessionStorage.getItem('userId'); | ||
if (!userId) { | ||
window.location.href = '/src/login.html'; | ||
} else { | ||
fetch(`http://localhost:5501/api/user_restaurants?userID=${userId}`) | ||
.then(resp => resp.json()) | ||
.then(restaurants => { | ||
const container = document.querySelector('.row.justify-content-center'); // The container where the rows will be appended | ||
container.innerHTML = ''; // Clear existing content | ||
restaurants.forEach(restaurant => { | ||
const cardHtml = ` | ||
<div class="container"> | ||
<div class="col"> | ||
<div class="card my-2 p-2"> | ||
<div class="card-body d-flex justify-content-between align-items-center"> | ||
<a href="https://www.google.com/maps/place/?q=place_id:${restaurant.placeID}" class="resLink text-decoration-none text-dark" target=_blank> | ||
<span class="resName fw-medium">${restaurant.resName}</span> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
container.insertAdjacentHTML('beforeend', cardHtml); | ||
}); | ||
}); | ||
} | ||
|
||
function addToFavourites(userResDB, heartIcon) { | ||
// console.log('Sent items: ', userResDB); | ||
// Send data to user_restaurants database | ||
fetch('http://localhost:5501/api/user_restaurants', { | ||
method: 'POST', // Specify the method | ||
headers: { | ||
'Content-Type': 'application/json', // Set the content type header for JSON | ||
}, | ||
body: JSON.stringify(userResDB) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log('Sent to userRes DB:', data); | ||
heartIcon.classList.add("bi-heart-fill"); | ||
heartIcon.classList.remove("bi-heart"); | ||
alert('Restaurant added to favourites'); | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
heartIcon.classList.remove("bi-heart-fill"); | ||
heartIcon.classList.add("bi-heart"); | ||
alert('An error occurred while adding the restaurant.'); | ||
}); | ||
} | ||
|
||
function removeFromFavourites(userResDB, heartIcon) { | ||
// console.log(userResDB); | ||
fetch(`http://localhost:5501/api/delete_user_restaurants?userID=${userResDB.userID}&placeID=${userResDB.placeID}`, { | ||
method: 'DELETE', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
} | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
console.log('Deleted from userRes DB:', data); | ||
heartIcon.classList.remove("bi-heart-fill"); | ||
heartIcon.classList.add("bi-heart"); | ||
alert('Restaurant removed from favourites'); | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
heartIcon.classList.add("bi-heart-fill"); | ||
heartIcon.classList.remove("bi-heart"); | ||
alert('An error occurred while removing the restaurant.'); | ||
}); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error("Error:", error); | ||
}); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.