Skip to content

Commit 06eed29

Browse files
committed
Updated on 2024-08-13
1 parent f48301a commit 06eed29

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

papers_read.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ <h1>Here's where I keep a list of papers I have read.</h1>
3838
<p id="paperCount">
3939
So far, we have read 0 papers. Let's keep it up!
4040
</p>
41+
<small id="searchCount">
42+
your search returned 0 papers. nice!
43+
</small>
4144

4245
<div class="search-inputs">
4346
<input type="text" id="titleSearch" placeholder="Search title...">
@@ -79,6 +82,7 @@ <h1>Here's where I keep a list of papers I have read.</h1>
7982
description: document.getElementById('descriptionSearch')
8083
};
8184
const paperCountElement = document.getElementById('paperCount');
85+
const searchCountElement = document.getElementById('searchCount');
8286
let sortOrder = {};
8387

8488
// Load papers from JSON file
@@ -87,6 +91,8 @@ <h1>Here's where I keep a list of papers I have read.</h1>
8791
.then(papers => {
8892
populateTable(papers);
8993
updatePaperCount(papers.length);
94+
// set search count as paper count initially
95+
updateSearchCount(papers.length);
9096
setupEventListeners();
9197
})
9298
.catch(error => console.error('Error loading papers:', error));
@@ -118,6 +124,9 @@ <h1>Here's where I keep a list of papers I have read.</h1>
118124
function updatePaperCount(count) {
119125
paperCountElement.textContent = `So far, we have read ${count} papers. Let's keep it up!`;
120126
}
127+
function updateSearchCount(count) {
128+
searchCount.textContent = `your search returned ${count} papers. nice!`;
129+
}
121130

122131
function setupEventListeners() {
123132
for (let key in searchInputs) {
@@ -143,6 +152,7 @@ <h1>Here's where I keep a list of papers I have read.</h1>
143152

144153
function searchTable() {
145154
const rows = tbody.getElementsByTagName('tr');
155+
var numRowsMatch = 0;
146156
for (let i = 0; i < rows.length; i++) {
147157
const row = rows[i];
148158
const cells = row.getElementsByTagName('td');
@@ -157,8 +167,14 @@ <h1>Here's where I keep a list of papers I have read.</h1>
157167
}
158168
}
159169

160-
row.style.display = foundMatch ? '' : 'none';
170+
if(foundMatch){
171+
row.style.display = ''
172+
numRowsMatch ++;
173+
}else{
174+
row.style.display = 'none'
175+
}
161176
}
177+
updateSearchCount(numRowsMatch)
162178
}
163179

164180
function sortTable(column, dataType, order) {

0 commit comments

Comments
 (0)