Commit 00dcf15dd8

00dcf15dd874ae2898dcc4dbb41c0094584c6b92

parent: 2d1fa66fad

Unsigned

Alicia Sykes <alicia@omg.lol> 路 2024-02-18 19:34 UTC

Added route for viewing everything, all at once

Layout: unified 路 split

web/src/pages/browse.astro added +154
@@ -0,0 +1,154 @@
1---
2
3import Layout from '@layouts/Layout.astro';
4import SectionList from '@components/things/SectionList.astro';
5
6import { fetchData } from '@utils/fetch-data';
7
8const categories = (await fetchData())?.categories;
9---
10
11<Layout title="Browse">
12
13<div class="head-wrap">
14 <h2>Browse</h2>
15 <input type="search" placeholder="Start typing to filter..." />
16</div>
17
18<ul class="categories">
19 {categories.map((category) => (
20 <li class="category">
21 <SectionList title={category.name} sections={category.sections} />
22 </li>
23 ))}
24</ul>
25
26<div class="no-results">
27 <p class="zilch">Nothing found 馃槩</p>
28 <p>Try a <a href="/search">deep search</a> instead</p>
29</div>
30</Layout>
31
32<script>
33 const filterInput = document.querySelector('input');
34 const categories = document.querySelectorAll('.category');
35
36 filterInput?.addEventListener('input', (e) => {
37 let resultsCount = 0;
38 const filter = e.target.value.toLowerCase();
39 categories.forEach((category) => {
40 const title = category.querySelector('.category-title').textContent.toLowerCase();
41 const sections = category.querySelectorAll('.section');
42 let count = 0;
43 sections.forEach((section) => {
44 const sectionTitle = section?.textContent?.toLowerCase();
45 if (sectionTitle?.includes(filter)) {
46 section.style.display = 'block';
47 count++;
48 resultsCount++;
49 } else {
50 section.style.display = 'none';
51 }
52 });
53 if (title.includes(filter)) {
54 category.style.display = 'inline-flex';
55 resultsCount++;
56 } else if (count === 0) {
57 category.style.display = 'none';
58 }
59 });
60 const noResults = document.querySelector('.no-results');
61 noResults.style.display = resultsCount === 0 ? 'block' : 'none';
62 });
63</script>
64
65
66<style lang="scss">
67
68.head-wrap {
69 margin: 1rem auto;
70 width: 85vw;
71 display: flex;
72 align-items: center;
73 justify-content: space-between;
74 flex-wrap: wrap;
75 input {
76 padding: 0.5rem;
77 border: 2px solid var(--foreground);
78 border-radius: var(--curve-sm);
79 font-size: 1.2rem;
80 box-shadow: 3px 3px 0 var(--foreground);
81 color: var(--accent-3);
82 &:focus {
83 outline: none;
84 box-shadow: 4px 4px 0 var(--foreground);
85 }
86 }
87 h2 {
88 font-family: "Lekton", sans-serif;
89 font-weight: bold;
90 font-size: 3rem;
91 margin: 0;
92 color: var(--accent-3);
93 }
94}
95
96.no-results {
97 text-align: center;
98 width: 85vw;
99 margin: 2rem auto 4rem auto;
100 display: none;
101 .zilch {
102 font-size: 2rem;
103 color: var(--accent-3);
104 opacity: 0.5;
105 font-weight: bold;
106 }
107 p {
108 margin: 0.25rem;
109 }
110}
111
112.categories {
113 columns: 6 300px;
114 column-gap: 1rem;
115 margin: 0 auto;
116 width: 85vw;
117 max-width: 1800px;
118 padding: 2rem 0;
119 .category {
120 background: var(--accent-fg);
121 border: 2px solid var(--foreground);
122 border-radius: var(--curve-sm);
123 box-shadow: 4px 4px 0 var(--foreground);
124 padding: 1rem;
125 width: 85%;
126 display: inline-flex;
127 flex-direction: column;
128 margin: 1rem;
129 .category-title {
130 text-decoration: none;
131 color: var(--foreground);
132 }
133 h3 {
134 font-family: "Lekton", sans-serif;
135 font-weight: bold;
136 margin: 0;
137 font-size: 1.8rem;
138 }
139 .sections {
140 padding-left: 1rem;
141 .section {
142 a {
143 text-decoration: none;
144 color: var(--foreground);
145 }
146 .service-count {
147 color: var(--accent-3);
148 }
149 }
150 }
151 }
152}
153
154</style>