-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMyBorrowedBooks.html
142 lines (129 loc) · 5.6 KB
/
MyBorrowedBooks.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MyBookPal</title>
<link rel="stylesheet" href="bookLending.css" />
</head>
<body>
<header>
<div class="brand">MyBookPal</div>
<nav>
<ul class="nav-menu">
<li><a href="./listAllBooks.html" class="books-icon">Books</a></li>
<!-- <li><a href="#ebooks" class="ebooks-icon"></a></li>
<li><a href="#audiobooks" class="audiobooks-icon">Audiobooks</a></li>
<li><a href="#bestsellers" class="bestsellers-icon">Bestsellers</a></li>
<li><a href="#comingsoon" class="comingsoon-icon">Coming Soon</a></li> -->
<li class="dropdown">
<a href="#" class="bookLending-icon">BookLending</a>
<div class="dropdown-content">
<a href="#listAllLendingBooks.html" id="borrowBookOption">Borrow a book</a>
<a href="#returnBook.html" id="returnBookOption">Return a book</a>
<a href="#MyBorrowedBooks.html" id="myBorrowedBooksOption">My borrowed books</a>
</div>
</li>
<li><a href="./listAllBooks.html" class="books-icon">Selling Books</a></li>
<li class="dropdown">
<a href="#" class="bookLending-icon">Subscriptions</a>
<div class="dropdown-content">
<a href="#subscribeBook.html" id="subscribeBookOption">Subscribe to a book</a>
<a href="#unsubscribeBook.html" id="unsubscribeBookOption">Unsubscribe</a>
</div>
</li>
<li><a href="#Wallet" class="Wallet_icon">Wallet</a></li>
<li><a href="#cart" class="cart-icon"><i class="fa fa-opencart" style="padding:3px;"></i>Cart</a></li>
</ul>
</nav>
<ul class="user-menu">
<!-- <li class="home-button"><a href="listAllBooks.html" class="home-icon">Home</a></li> -->
<li class="dropdown">
<a href="#account" class="account-icon"><i class="fa fa-user" style="padding:3px;"></i>My Account</a>
<div class="dropdown-content">
<a href="#listNotificationPreferences.html" id="notifPref">Update Account</a>
<a href="#listAllLendingBooks.html" id="borrowBookOption">Settings</a>
<a href="#listAllLendingBooks.html" id="borrowBookOption">Logout</a>
<a href="#listAllLendingBooks.html" id="borrowBookOption">Sign In</a
</div>
</li>
</ul>
</header>
<div class="search-bar">
<input type="text" id="searchInput" placeholder="Search for books">
<button>Search</button>
<div class="order-filter">
<label for="orderBy">Sort By:</label>
<select id="orderBy">
<option value="lowToHigh">Low to High</option>
<option value="highToLow">High to Low</option>
</select>
</div>
</div>
<div class = "container">
<div class="book-list" id="book-list">
</div>
</div>
<script>
function generateBookHTML(book) {
return `
<div class="book" data-category="${book.Genre}">
<img src="${book.Photos}" alt="${book.Title}" />
<p>Author: ${book.Author}</p>
<p>Category: ${book.Genre}</p>
</div>
`;
}
function fetchAvailableBooks() {
const backendURL = 'http://localhost:3000';
const bookListContainer = document.getElementById('book-list');
bookListContainer.innerHTML = '';
let endpoint = '/books/borrowed';
fetch(`${backendURL}${endpoint}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(data => {
if (Array.isArray(data)) {
data.forEach(book => {
const bookHTML = generateBookHTML(book);
bookListContainer.innerHTML += bookHTML;
});
}
})
.catch(error => console.error('Error fetching data from backend:', error));
}
document.addEventListener('DOMContentLoaded', () => {
fetchAvailableBooks();
const searchButton = document.querySelector('button');
searchButton.addEventListener('click', fetchAvailableBooks);
document.getElementById('borrowBookOption').addEventListener('click', () => {
window.location.href = 'listAllLendingBooks.html';
});
// Event listener for "Return a book" option
document.getElementById('returnBookOption').addEventListener('click', () => {
window.location.href = 'returnBook.html';
});
// Event listener for "My borrowed books" option
document.getElementById('myBorrowedBooksOption').addEventListener('click', () => {
window.location.href = 'MyBorrowedBooks.html';
});
document.getElementById('subscribeBookOption').addEventListener('click', () => {
window.location.href = 'subscribeBook.html';
});
// Event listener for "Unsubscribe book" option
document.getElementById('unsubscribeBookOption').addEventListener('click', () => {
window.location.href = 'unsubscribeBook.html';
});
// Event listener for "notification preferences" option
document.getElementById('notifPref').addEventListener('click', () => {
window.location.href = 'listNotificationPreferences.html';
});
});
</script>
</body>
</html>