@@ -4,20 +4,66 @@ import '../styles/globals.scss';
4
4
import Card from " ./ui/Card.astro" ;
5
5
---
6
6
7
+ <script >
8
+ const inspire = document.getElementById('inspirationAmount');
9
+ const personal = document.getElementById('personalAmount');
10
+ const commerce = document.getElementById('commerceAmount');
11
+ const resources = document.getElementById('resourcesAmount');
12
+ const free = document.getElementById('freeAmount');
13
+ const all = document.getElementById('totalAmount');
14
+
15
+ let items = document.querySelectorAll('.item');
16
+
17
+ const myList = document.getElementById('contentWrap');
18
+
19
+ const typeCounts = {};
20
+
21
+ for (const listItem of myList.children) {
22
+ const itemType = listItem.firstElementChild.textContent.toLowerCase().trim();
23
+
24
+ if (typeCounts[itemType]) {
25
+ typeCounts[itemType]++;
26
+ } else {
27
+ typeCounts[itemType] = 1;
28
+ }
29
+ }
30
+
31
+ let inspireType = 'inspiration',
32
+ personalType = 'personal',
33
+ commerceType = 'commerce',
34
+ resourcesType = 'resources',
35
+ freeType = 'free';
36
+
37
+ let total = 0;
38
+ for (const type in typeCounts) {
39
+ console.log(`Type "${type}": ${typeCounts[type]} occurrences`);
40
+ total += typeCounts[type];
41
+
42
+
43
+ inspire.textContent = `${typeCounts[inspireType]}`.toString();
44
+ personal.textContent = `${typeCounts[personalType]}`.toString();
45
+ commerce.textContent = `${typeCounts[commerceType]}`.toString();
46
+ resources.textContent = `${typeCounts[resourcesType]}`.toString();
47
+ free.textContent = `${typeCounts[freeType]}`.toString();
48
+ all.textContent = `${total}`.toString();
49
+ }
50
+
51
+ </script >
52
+
7
53
<section >
8
54
<div id =" filterList" >
9
55
<div >
10
56
<section class =" filterMenu" >
11
57
<h3 >Filter</h3 >
12
58
<div class =" filterButtonList" >
13
- <button class =" active" id =" filterAll" >All</button >
59
+ <button class =" active" id =" filterAll" >All<span id = " totalAmount " ></ span >< /button >
14
60
</div >
15
61
<div class =" filterButtonList" >
16
- <button class =' filterButton' aria-label =' Inspiration contentt' >Inspiration</button >
17
- <button class =' filterButton' aria-label =' Personal websites, portfolios, blogs' >Personal</button >
18
- <button class =' filterButton' aria-label =' Commerce tools' >Commerce</button >
19
- <button class =' filterButton' aria-label =' Resources' >Resources</button >
20
- <button class =' filterButton' aria-label =' Free resources' >Free</button >
62
+ <button class =' filterButton' aria-label =' Inspiration contentt' >< a > Inspiration</ a >< span id = " inspirationAmount " ></ span > </button >
63
+ <button class =' filterButton' aria-label =' Personal websites, portfolios, blogs' >< a > Personal</ a >< span id = " personalAmount " ></ span > </button >
64
+ <button class =' filterButton' aria-label =' Commerce tools' >< a > Commerce</ a >< span id = " commerceAmount " ></ span > </button >
65
+ <button class =' filterButton' aria-label =' Resources' >< a > Resources</ a >< span id = " resourcesAmount " ></ span > </button >
66
+ <button class =' filterButton' aria-label =' Free resources' >< a > Free</ a >< span id = " freeAmount " ></ span > </button >
21
67
</div >
22
68
</section >
23
69
</div >
@@ -141,18 +187,13 @@ import Card from "./ui/Card.astro";
141
187
font-size: 1rem !important;
142
188
}
143
189
144
- @media screen and (max-width: 800px) {
145
- section {
146
- flex-direction: row;
147
- padding: 1rem;
148
- border-radius: 0;
149
- }
150
190
151
- }
152
191
153
192
154
193
.filterButton, #filterAll {
155
194
display: flex;
195
+ align-items: center;
196
+ gap: 0.2rem;
156
197
}
157
198
158
199
.filterButton, #filterAll {
@@ -193,9 +234,21 @@ import Card from "./ui/Card.astro";
193
234
background-color: rgba(53, 115, 240, 0.25);
194
235
}
195
236
237
+ .filterButton span, #totalAmount {
238
+ font-size: 0.7rem !important;
239
+ position: relative;
240
+ top: 1px;
241
+ font-weight: 600;
242
+ opacity: 0.5;
243
+ @apply p-1;
244
+ }
245
+
196
246
</style >
197
247
198
248
<script >
249
+
250
+
251
+
199
252
let filters = new Set();
200
253
let buttons = document.querySelectorAll('.filterButton');
201
254
let items = document.querySelectorAll('.item');
@@ -206,10 +259,10 @@ import Card from "./ui/Card.astro";
206
259
btn.addEventListener('click', () => {
207
260
if (btn.classList.contains('active')) {
208
261
btn.classList.remove('active');
209
- filters.delete(btn.innerHTML .toUpperCase());
262
+ filters.delete(btn.firstElementChild.textContent .toUpperCase());
210
263
} else {
211
264
btn.classList.add('active');
212
- filters.add(btn.innerHTML .toUpperCase());
265
+ filters.add(btn.firstElementChild.textContent .toUpperCase());
213
266
}
214
267
215
268
if (showAll.classList.contains('active')) {
@@ -256,9 +309,6 @@ import Card from "./ui/Card.astro";
256
309
} else {
257
310
258
311
items.forEach(item => {
259
- console.log(item.querySelector('p') + ' item');
260
-
261
- item.firstElementChild.textContent;
262
312
263
313
let itemText = item.firstElementChild.textContent.toUpperCase().trim();
264
314
0 commit comments