Added a show/hide menu for filters

This commit is contained in:
Brendan 2025-01-05 22:43:56 +00:00
parent 8af82a3d22
commit 7ebf8dd983
3 changed files with 55 additions and 53 deletions

View File

@ -13,14 +13,14 @@
<div class="text-center mb-4">
<img src="/images/smolNews_transparent-grey.png" alt="smolNews" class="title-logo">
</div>
<div class="form-group mb-3">
<input type="text" id="searchInput" class="form-control" placeholder="Search for articles...">
</div>
<button id="toggleFilters" class="btn btn-secondary btn-block mb-3">Show/Hide Filters</button>
<div id="filterMenu" class="collapse">
<div class="form-group">
<select id="topicSelect" class="form-control">
<option value="">All Topics</option>
<option value="business">Business</option>
<option value="entertainment">Entertainment</option>
<option value="science">Science</option>
<option value="sports">Sports</option>
<option value="technology">Technology</option>
</select>
</div>
<div class="form-group">
@ -47,10 +47,8 @@
<option value="">All Countries</option>
</select>
</div>
<div class="form-group">
<input type="text" id="searchInput" class="form-control" placeholder="Search for articles...">
</div>
<button id="resetButton" class="btn btn-secondary btn-block mb-2">Reset Filters</button>
<button id="resetButton" class="btn btn-secondary btn-block mb-3">Reset Search/Filters</button>
<button id="searchButton" class="btn btn-primary btn-block">Search</button>
<div id="articles" class="mt-4"></div>
</div>

View File

@ -4,6 +4,11 @@ const apiKeyNYT = 'NQdorI46QZM3Kythn8ymAWID8ojT7ntY';
document.addEventListener('DOMContentLoaded', function() {
configureDropdowns();
fetchNewsArticles();
document.getElementById('toggleFilters').addEventListener('click', function() {
const filterMenu = document.getElementById('filterMenu');
$(filterMenu).collapse('toggle');
});
});
document.getElementById('apiSelect').addEventListener('change', function() {
@ -40,23 +45,6 @@ function fetchTopics() {
const topicSelect = document.getElementById('topicSelect');
topicSelect.innerHTML = '<option value="">All Topics</option>'; // Reset topics dropdown
// Add static topics
const staticTopics = [
{ value: 'business', text: 'Business' },
{ value: 'entertainment', text: 'Entertainment' },
{ value: 'science', text: 'Science' },
{ value: 'sports', text: 'Sports' },
{ value: 'technology', text: 'Technology' },
];
// Add static options first
staticTopics.forEach(topic => {
const option = document.createElement('option');
option.value = topic.value;
option.textContent = topic.text;
topicSelect.appendChild(option);
});
// Loop through the fetched categories from Currents API and add to the dropdown
data.categories.forEach(category => {
const option = document.createElement('option');

View File

@ -31,6 +31,22 @@ body {
}
}
#filterMenu {
background-color: var(--card-dark);
padding: 1rem;
margin-bottom: 1rem;
border-radius: var(--border-radius);
border: 1px solid rgba(255, 255, 255, 0.1);
}
#filterMenu.show {
display: block;
}
#searchInput {
margin: 0;
}
.form-control {
background-color: var(--card-dark);
border: 1px solid rgba(255, 255, 255, 0.1);