-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.html
123 lines (112 loc) · 5.3 KB
/
categories.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NotesShare | Categories</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<!-- Navigation Bar -->
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark shadow">
<div class="container">
<a class="navbar-brand fw-bold" href="index.html">NotesShare</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="categories.html">Categories</a>
</li>
<li class="nav-item">
<a class="nav-link" href="notes.html">All Notes </a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!-- Categories Section -->
<section class="py-5 bg-light">
<div class="container mt-5">
<h1 class="text-center">Categories</h1>
<!-- Search Bar -->
<div class="form-group mb-4">
<div class="input-group">
<input type="text" id="search-input" class="form-control" placeholder="Search categories by name" onkeyup="filterCategories()">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-search"></i></span>
</div>
</div>
</div>
<div id="categories-container" class="row"></div>
</div>
</section>
<script>
let categoriesData = []; // Array to store categories data
let notesData = []; // Array to store notes data
// Fetch categories from the JSON file
fetch('categories.json')
.then(response => response.json())
.then(categories => {
categoriesData = categories; // Store the fetched categories
fetchNotesData(); // Fetch notes data
})
.catch(error => console.error('Error fetching categories:', error));
function fetchNotesData() {
// Fetch notes from the JSON file
fetch('notes.json')
.then(response => response.json())
.then(notes => {
notesData = notes; // Store the fetched notes
renderCategories(categoriesData); // Render categories with notes count
})
.catch(error => console.error('Error fetching notes:', error));
}
function getNotesCountForCategory(categoryId) {
return notesData.filter(note => note.category === categoryId).length;
}
function renderCategories(categories) {
const categoriesContainer = document.getElementById('categories-container');
categoriesContainer.innerHTML = ''; // Clear previous content
categories.forEach(category => {
const count = getNotesCountForCategory(category.id); // Get notes count for the category
const categoryCard = `
<div class="col-md-4 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">${category.header}</h5>
<p class="card-text">${category.description}</p>
<p class="card-text"><small class="text-muted">Notes Available: ${count}</small></p>
<a href="notes.html?category=${category.id}" class="btn btn-primary">View Notes</a>
</div>
</div>
</div>
`;
categoriesContainer.innerHTML += categoryCard;
});
}
function filterCategories() {
const searchInput = document.getElementById('search-input').value.toLowerCase();
const filteredCategories = categoriesData.filter(category =>
category.header.toLowerCase().includes(searchInput)
);
renderCategories(filteredCategories); // Render filtered categories
}
</script>
<!-- Bootstrap JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</body>
</html>