Skip to content

Commit b496da9

Browse files
authored
Merge pull request #134 from DenisValeev/codex/onboard-new-dad-jokes-and-categorize
Surface joke categories and add new dad jokes
2 parents ce714a5 + e0c807f commit b496da9

9 files changed

Lines changed: 656 additions & 9 deletions

File tree

apps/jokes/all-jokes-compact.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
--table-stripe: rgba(15, 23, 42, 0.03);
2020
--table-border: rgba(15, 23, 42, 0.1);
2121
--badge-bg: rgba(74, 99, 255, 0.14);
22+
--category-pill-bg: rgba(74, 99, 255, 0.14);
23+
--category-pill-text: rgba(31, 50, 143, 0.92);
2224
background-color: var(--bg-color);
2325
color: var(--text-primary);
2426
}
@@ -36,6 +38,8 @@
3638
--table-stripe: rgba(255, 255, 255, 0.04);
3739
--table-border: rgba(148, 163, 209, 0.12);
3840
--badge-bg: rgba(105, 128, 255, 0.16);
41+
--category-pill-bg: rgba(105, 128, 255, 0.18);
42+
--category-pill-text: rgba(225, 232, 255, 0.92);
3943
}
4044

4145
.filter input[type="search"] {
@@ -143,6 +147,26 @@
143147
color: inherit;
144148
}
145149

150+
.category-list {
151+
display: flex;
152+
flex-wrap: wrap;
153+
gap: 6px;
154+
margin: 0;
155+
padding: 0;
156+
list-style: none;
157+
}
158+
159+
.category-pill {
160+
display: inline-flex;
161+
align-items: center;
162+
padding: 4px 10px;
163+
border-radius: 999px;
164+
font-size: 0.8rem;
165+
font-weight: 600;
166+
background: var(--category-pill-bg);
167+
color: var(--category-pill-text);
168+
}
169+
146170
.filter {
147171
display: flex;
148172
flex-direction: column;
@@ -284,17 +308,19 @@ <h1>All Jokes (Compact)</h1>
284308
<th scope="col">#</th>
285309
<th scope="col">Joke</th>
286310
<th scope="col">Punchline</th>
311+
<th scope="col">Categories</th>
287312
</tr>
288313
</thead>
289314
<tbody>
290315
<tr>
291-
<td colspan="3">Loading jokes…</td>
316+
<td colspan="4">Loading jokes…</td>
292317
</tr>
293318
</tbody>
294319
</table>
295320
</div>
296321
</main>
297322
<script src="jokes.js" defer></script>
323+
<script src="joke-categories.js" defer></script>
298324
<script src="render-all.js" defer></script>
299325
</body>
300326
</html>

apps/jokes/all-jokes.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
border-color: rgba(241, 245, 255, 0.35);
5353
color: inherit;
5454
}
55+
56+
.category-pill {
57+
background: rgba(148, 163, 209, 0.24);
58+
color: rgba(241, 245, 255, 0.9);
59+
}
5560
}
5661

5762
main {
@@ -109,6 +114,26 @@
109114
font-weight: 600;
110115
}
111116

117+
.category-list {
118+
display: flex;
119+
flex-wrap: wrap;
120+
gap: 6px;
121+
margin: 12px 0 0;
122+
padding: 0;
123+
list-style: none;
124+
}
125+
126+
.category-pill {
127+
display: inline-flex;
128+
align-items: center;
129+
padding: 4px 10px;
130+
border-radius: 999px;
131+
font-size: 0.85rem;
132+
font-weight: 600;
133+
background: rgba(48, 86, 211, 0.12);
134+
color: rgba(48, 56, 140, 0.92);
135+
}
136+
112137
.filter {
113138
margin-top: 1.5rem;
114139
display: flex;
@@ -180,7 +205,7 @@
180205
</a>
181206
</nav>
182207
<h1>All Jokes</h1>
183-
<p>Every joke from the dataset in one place. Use the filter to zero in on a favourite.</p>
208+
<p>Every joke from the dataset in one place—complete with quick-hit categories. Use the filter to zero in on a favourite or explore a topic.</p>
184209
<p class="count">Showing <span data-count>0</span> of <span data-total>0</span> jokes</p>
185210
<form class="filter" data-filter-form>
186211
<label for="joke-filter">Filter jokes</label>
@@ -196,6 +221,7 @@ <h1>All Jokes</h1>
196221
</table>
197222
</main>
198223
<script src="jokes.js" defer></script>
224+
<script src="joke-categories.js" defer></script>
199225
<script src="render-all.js" defer></script>
200226
</body>
201227
</html>

apps/jokes/app.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const prevButton = document.getElementById('prev-button');
55
const nextButton = document.getElementById('next-button');
66
const revealButton = document.getElementById('reveal-button');
7+
const categoryList = document.getElementById('joke-categories');
78

89
if (!setupEl || !punchlineEl || !prevButton || !nextButton || !revealButton) {
910
return;
@@ -17,6 +18,35 @@
1718
let index = 0;
1819
let punchlineVisible = false;
1920

21+
const categorize =
22+
window.jokeCategoryHelper && typeof window.jokeCategoryHelper.categorize === 'function'
23+
? window.jokeCategoryHelper.categorize
24+
: null;
25+
26+
const fallbackCategory =
27+
window.jokeCategoryHelper && typeof window.jokeCategoryHelper.fallback === 'string'
28+
? window.jokeCategoryHelper.fallback
29+
: 'Classic Dad';
30+
31+
function renderCategories(values) {
32+
if (!categoryList) {
33+
return;
34+
}
35+
36+
categoryList.textContent = '';
37+
38+
const items = Array.isArray(values) && values.length ? values : [fallbackCategory];
39+
40+
items.forEach((label) => {
41+
const pill = document.createElement('li');
42+
pill.className = 'category-pill';
43+
pill.textContent = label;
44+
categoryList.appendChild(pill);
45+
});
46+
47+
categoryList.hidden = false;
48+
}
49+
2050
function shuffle(array) {
2151
const copy = array.slice();
2252
for (let i = copy.length - 1; i > 0; i -= 1) {
@@ -51,19 +81,27 @@
5181
revealButton.hidden = true;
5282
prevButton.disabled = true;
5383
nextButton.disabled = true;
84+
if (categoryList) {
85+
categoryList.textContent = '';
86+
categoryList.hidden = true;
87+
}
5488
return;
5589
}
5690

5791
ensureDeck();
5892
const current = deck[index];
5993
const hasPunchline = typeof current.punchline === 'string' && current.punchline.trim().length > 0;
6094
const punchlineText = hasPunchline ? current.punchline : '💩';
95+
const categories = categorize
96+
? categorize(current.joke, current.punchline)
97+
: [fallbackCategory];
6198

6299
setupEl.textContent = current.joke;
63100
punchlineEl.textContent = punchlineText;
64101
revealButton.hidden = false;
65102

66103
setPunchlineVisible(false);
104+
renderCategories(categories);
67105

68106
const buttonsDisabled = deck.length <= 1;
69107
prevButton.disabled = buttonsDisabled;

apps/jokes/index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@
7575
gap: 20px;
7676
}
7777

78+
.category-list {
79+
display: flex;
80+
flex-wrap: wrap;
81+
gap: 8px;
82+
margin: 0;
83+
padding: 0;
84+
list-style: none;
85+
}
86+
87+
.category-pill {
88+
display: inline-flex;
89+
align-items: center;
90+
gap: 6px;
91+
padding: 4px 12px;
92+
border-radius: 999px;
93+
font-size: 0.85rem;
94+
font-weight: 600;
95+
background: rgba(48, 86, 211, 0.12);
96+
color: var(--accent);
97+
}
98+
99+
@media (prefers-color-scheme: dark) {
100+
.category-pill {
101+
background: rgba(112, 132, 255, 0.18);
102+
color: #b8c1ff;
103+
}
104+
}
105+
78106
.home-nav {
79107
display: flex;
80108
justify-content: flex-start;
@@ -219,6 +247,7 @@
219247
</nav>
220248
<article class="card" aria-live="polite">
221249
<div class="card__content">
250+
<ul id="joke-categories" class="category-list" aria-label="Joke categories" hidden></ul>
222251
<p id="joke-setup">Loading joke…</p>
223252
<p id="joke-punchline" aria-hidden="true"></p>
224253
</div>
@@ -234,6 +263,7 @@
234263
</div>
235264
</main>
236265
<script src="jokes.js" defer></script>
266+
<script src="joke-categories.js" defer></script>
237267
<script src="app.js" defer></script>
238268
</body>
239269
</html>

0 commit comments

Comments
 (0)