Skip to content

Commit

Permalink
update on pages
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiJay committed Mar 21, 2024
1 parent 6213f89 commit 724cb4d
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 267 deletions.
16 changes: 2 additions & 14 deletions src/animation/animation.js
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 removed src/api/geolocation.js
Empty file.
156 changes: 0 additions & 156 deletions src/favourite.html

This file was deleted.

123 changes: 32 additions & 91 deletions src/favourite.js
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);
});
}
};

6 changes: 3 additions & 3 deletions src/about.html → src/pages/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ <h3 class="font-monospace">Chi_She_Mo</h3>
<div class="d-flex justify-content-end">
<ul class="nav">
<li class="nav-item text-decoration-underline">
<a href="./index.html" id="about" class="nav-link link-body-emphasis">Home</a>
<a href="/src/pages/index.html" id="about" class="nav-link link-body-emphasis">Home</a>
</li>
<li class="nav-item text-decoration-underline">
<a href="./favourite.html" id="favourites" class="nav-link link-body-emphasis">Favourites</a>
<a href="/src/pages/favourite.html" id="favourites" class="nav-link link-body-emphasis">Favourites</a>
</li>
<li class="nav-item text-decoration-underline">
<a href="./landing.html" id="logout" class="nav-link link-body-emphasis">Logout</a>
<a href="/src/landing.html" id="logout" class="nav-link link-body-emphasis">Logout</a>
</li>
</ul>
</div>
Expand Down
Loading

0 comments on commit 724cb4d

Please sign in to comment.