1use super::data::{format_tag, get_all_tags, get_articles, get_articles_by_tag};
4use crate::ui::components::footer::Footer;
5use crate::ui::components::main_nav::{ActivePage, MainNav};
6use crate::ui::router::Route;
7use crate::ui::seo::{
8 breadcrumb_schema, organization_schema, pages as seo_pages, BreadcrumbItem, JsonLdMultiple,
9 PageHead,
10};
11use dioxus::prelude::*;
12#[cfg(all(feature = "split", target_arch = "wasm32"))]
13use dioxus::wasm_split;
14
15const NEWS_STYLES: &str = r#"
16.news-page {
17 min-height: 100vh;
18 background: var(--bg-dark, #060814);
19 display: flex;
20 flex-direction: column;
21}
22
23.news-layout {
24 flex: 1;
25 display: flex;
26 max-width: 1200px;
27 margin: 0 auto;
28 padding: 48px 24px;
29 width: 100%;
30 gap: 48px;
31}
32
33/* Sidebar - Desktop only */
34.news-sidebar {
35 width: 240px;
36 flex-shrink: 0;
37 position: sticky;
38 top: 100px;
39 height: fit-content;
40}
41
42.news-sidebar-section {
43 margin-bottom: 32px;
44}
45
46.news-sidebar-title {
47 font-size: var(--font-caption-md, 12px);
48 font-weight: 600;
49 color: var(--text-tertiary, #909090);
50 text-transform: uppercase;
51 letter-spacing: 1px;
52 margin: 0 0 16px;
53 padding-bottom: 8px;
54 border-bottom: 1px solid rgba(255, 255, 255, 0.08);
55}
56
57.news-search {
58 position: relative;
59 margin-bottom: 24px;
60}
61
62.news-search-input {
63 width: 100%;
64 padding: 10px 14px 10px 38px;
65 background: rgba(255, 255, 255, 0.05);
66 border: 1px solid rgba(255, 255, 255, 0.1);
67 border-radius: var(--radius-lg, 12px);
68 color: var(--text-primary, #f0f0f0);
69 font-size: var(--font-body-sm, 14px);
70 outline: none;
71 transition: all 0.2s ease;
72}
73
74.news-search-input::placeholder {
75 color: var(--text-tertiary, #909090);
76}
77
78.news-search-input:focus {
79 border-color: rgba(102, 126, 234, 0.5);
80 background: rgba(255, 255, 255, 0.08);
81}
82
83.news-search-icon {
84 position: absolute;
85 left: 12px;
86 top: 50%;
87 transform: translateY(-50%);
88 color: var(--text-tertiary, #909090);
89 pointer-events: none;
90}
91
92.news-tag-list {
93 display: flex;
94 flex-direction: column;
95 gap: 6px;
96}
97
98.news-filter-tag {
99 display: flex;
100 align-items: center;
101 justify-content: space-between;
102 padding: 8px 12px;
103 background: transparent;
104 border: 1px solid transparent;
105 border-radius: var(--radius-md, 8px);
106 color: var(--text-secondary, #b0b0b0);
107 font-size: var(--font-body-sm, 14px);
108 cursor: pointer;
109 transition: all 0.2s ease;
110 text-align: left;
111 width: 100%;
112}
113
114.news-filter-tag:hover {
115 background: rgba(255, 255, 255, 0.05);
116 color: var(--text-primary, #f0f0f0);
117}
118
119.news-filter-tag.active {
120 background: rgba(102, 126, 234, 0.15);
121 border-color: rgba(102, 126, 234, 0.3);
122 color: var(--color-accent-blue, #60a5fa);
123}
124
125.news-filter-tag-count {
126 font-size: 11px;
127 padding: 2px 8px;
128 background: rgba(255, 255, 255, 0.1);
129 border-radius: var(--radius-full, 9999px);
130 color: var(--text-tertiary, #909090);
131}
132
133.news-filter-tag.active .news-filter-tag-count {
134 background: rgba(102, 126, 234, 0.3);
135 color: var(--color-accent-blue, #60a5fa);
136}
137
138.news-clear-filter {
139 margin-top: 12px;
140 padding: 8px 12px;
141 background: transparent;
142 border: 1px solid rgba(255, 255, 255, 0.1);
143 border-radius: var(--radius-md, 8px);
144 color: var(--text-secondary, #b0b0b0);
145 font-size: var(--font-body-sm, 14px);
146 cursor: pointer;
147 transition: all 0.2s ease;
148 width: 100%;
149}
150
151.news-clear-filter:hover {
152 background: rgba(255, 255, 255, 0.05);
153 border-color: rgba(255, 255, 255, 0.2);
154 color: var(--text-primary, #f0f0f0);
155}
156
157/* Main content area */
158.news-main {
159 flex: 1;
160 min-width: 0;
161}
162
163.news-header {
164 margin-bottom: 48px;
165}
166
167.news-header h1 {
168 font-size: var(--font-display-lg, 42px);
169 font-weight: 800;
170 background: linear-gradient(180deg, #ffffff 0%, rgba(229,231,235,0.85) 100%);
171 -webkit-background-clip: text;
172 -webkit-text-fill-color: transparent;
173 background-clip: text;
174 margin: 0 0 16px;
175}
176
177.news-header p {
178 color: var(--text-secondary, #b0b0b0);
179 font-size: var(--font-body-lg, 18px);
180 margin: 0;
181}
182
183.news-active-filter {
184 display: flex;
185 align-items: center;
186 gap: 12px;
187 margin-top: 16px;
188 padding: 12px 16px;
189 background: rgba(102, 126, 234, 0.1);
190 border: 1px solid rgba(102, 126, 234, 0.2);
191 border-radius: var(--radius-lg, 12px);
192}
193
194.news-active-filter-label {
195 color: var(--text-secondary, #b0b0b0);
196 font-size: var(--font-body-sm, 14px);
197}
198
199.news-active-filter-tag {
200 display: inline-flex;
201 align-items: center;
202 gap: 8px;
203 padding: 4px 12px;
204 background: rgba(102, 126, 234, 0.2);
205 border-radius: var(--radius-full, 9999px);
206 color: var(--color-accent-blue, #60a5fa);
207 font-size: var(--font-body-sm, 14px);
208 font-weight: 600;
209 letter-spacing: 0.3px;
210}
211
212.news-active-filter-clear {
213 background: transparent;
214 border: none;
215 color: var(--text-tertiary, #909090);
216 cursor: pointer;
217 padding: 2px;
218 display: flex;
219 align-items: center;
220 justify-content: center;
221 transition: color 0.2s ease;
222}
223
224.news-active-filter-clear:hover {
225 color: var(--text-primary, #f0f0f0);
226}
227
228.news-list {
229 display: flex;
230 flex-direction: column;
231 gap: 24px;
232}
233
234.news-card {
235 background: rgba(255, 255, 255, 0.03);
236 border: 1px solid rgba(255, 255, 255, 0.08);
237 border-radius: var(--radius-xl, 16px);
238 padding: 24px;
239 transition: all 0.2s ease;
240 text-decoration: none;
241 display: block;
242}
243
244.news-card:hover {
245 background: rgba(255, 255, 255, 0.06);
246 border-color: rgba(255, 255, 255, 0.12);
247 transform: translateY(-2px);
248}
249
250.news-card-date {
251 font-size: var(--font-caption-md, 12px);
252 color: var(--text-tertiary, #909090);
253 margin-bottom: 8px;
254 text-transform: uppercase;
255 letter-spacing: 0.5px;
256}
257
258.news-card-title {
259 font-size: var(--font-heading-md, 22px);
260 font-weight: 700;
261 color: var(--text-primary, #f0f0f0);
262 margin: 0 0 12px;
263 line-height: 1.3;
264}
265
266.news-card-summary {
267 font-size: var(--font-body-md, 16px);
268 color: var(--text-secondary, #b0b0b0);
269 line-height: 1.6;
270 margin: 0 0 16px;
271}
272
273.news-card-tags {
274 display: flex;
275 gap: 8px;
276 flex-wrap: wrap;
277}
278
279.news-tag {
280 font-size: 11px;
281 padding: 4px 10px;
282 border-radius: var(--radius-full, 9999px);
283 background: rgba(102, 126, 234, 0.15);
284 color: var(--color-accent-blue, #60a5fa);
285 letter-spacing: 0.3px;
286 font-weight: 600;
287}
288
289.news-no-results {
290 text-align: center;
291 padding: 48px 24px;
292 color: var(--text-secondary, #b0b0b0);
293}
294
295.news-no-results h3 {
296 font-size: var(--font-heading-md, 22px);
297 color: var(--text-primary, #f0f0f0);
298 margin: 0 0 12px;
299}
300
301.news-no-results p {
302 margin: 0;
303}
304
305/* Mobile filter (bottom) */
306.news-mobile-filters {
307 display: none;
308 padding: 16px;
309 background: rgba(255, 255, 255, 0.03);
310 border: 1px solid rgba(255, 255, 255, 0.08);
311 border-radius: var(--radius-xl, 16px);
312 margin-bottom: 24px;
313}
314
315.news-mobile-filters-header {
316 display: flex;
317 align-items: center;
318 justify-content: space-between;
319 margin-bottom: 12px;
320}
321
322.news-mobile-filters-title {
323 font-size: var(--font-body-sm, 14px);
324 font-weight: 600;
325 color: var(--text-secondary, #b0b0b0);
326}
327
328.news-mobile-tags {
329 display: flex;
330 gap: 8px;
331 flex-wrap: wrap;
332}
333
334.news-mobile-tag {
335 padding: 6px 12px;
336 background: rgba(255, 255, 255, 0.05);
337 border: 1px solid rgba(255, 255, 255, 0.1);
338 border-radius: var(--radius-full, 9999px);
339 color: var(--text-secondary, #b0b0b0);
340 font-size: 12px;
341 cursor: pointer;
342 transition: all 0.2s ease;
343 letter-spacing: 0.3px;
344 font-weight: 600;
345}
346
347.news-mobile-tag:hover {
348 background: rgba(255, 255, 255, 0.1);
349}
350
351.news-mobile-tag.active {
352 background: rgba(102, 126, 234, 0.2);
353 border-color: rgba(102, 126, 234, 0.4);
354 color: var(--color-accent-blue, #60a5fa);
355}
356
357/* Mobile */
358@media (max-width: 900px) {
359 .news-sidebar {
360 display: none;
361 }
362
363 .news-mobile-filters {
364 display: block;
365 }
366
367 .news-layout {
368 padding: 32px 16px;
369 flex-direction: column;
370 gap: 0;
371 }
372
373 .news-header h1 {
374 font-size: var(--font-display-md, 32px);
375 }
376
377 .news-card {
378 padding: 20px;
379 }
380
381 .news-card-title {
382 font-size: var(--font-heading-sm, 18px);
383 }
384}
385"#;
386
387#[component(lazy)]
388pub fn News(tag: Option<String>) -> Element {
389 #[cfg(target_arch = "wasm32")]
391 {
392 let untagged = tag.is_none();
393 use_effect(move || {
394 if untagged {
395 crate::ui::router::replace_bar_url("/news");
396 }
397 });
398 }
399
400 let mut active_tag = use_signal(move || tag.clone());
401 let mut search_query = use_signal(|| String::new());
402
403 let all_tags = get_all_tags();
404 let all_articles = get_articles();
405
406 let tag_counts: std::collections::HashMap<&str, usize> = all_tags
408 .iter()
409 .map(|tag| (*tag, get_articles_by_tag(tag).len()))
410 .collect();
411
412 let filtered_articles: Vec<_> = {
414 let query = search_query.read().to_lowercase();
415 let tag_filter = active_tag.read().clone();
416
417 all_articles
418 .into_iter()
419 .filter(|article| {
420 let tag_match = match &tag_filter {
422 Some(tag) => article.tags.contains(&tag.as_str()),
423 None => true,
424 };
425
426 let search_match = if query.is_empty() {
428 true
429 } else {
430 article.title.to_lowercase().contains(&query)
431 || article.summary.to_lowercase().contains(&query)
432 || article
433 .tags
434 .iter()
435 .any(|t| t.to_lowercase().contains(&query))
436 };
437
438 tag_match && search_match
439 })
440 .collect()
441 };
442
443 let breadcrumbs = vec![
444 BreadcrumbItem {
445 name: "Home",
446 path: "/",
447 },
448 BreadcrumbItem {
449 name: "News",
450 path: "/news",
451 },
452 ];
453
454 let schemas = vec![organization_schema(), breadcrumb_schema(&breadcrumbs)];
455
456 rsx! {
457 PageHead {
458 title: seo_pages::NEWS.title,
459 description: seo_pages::NEWS.description,
460 canonical_path: seo_pages::NEWS.canonical_path,
461 }
462 style { "{NEWS_STYLES}" }
463 JsonLdMultiple { schemas }
464
465 div { class: "news-page",
466 MainNav { active: ActivePage::News, subtitle: Some("Latest updates") }
467
468 div { class: "news-layout",
469 aside { class: "news-sidebar",
471 div { class: "news-search",
473 span { class: "news-search-icon", "🔍" }
474 input {
475 class: "news-search-input",
476 r#type: "text",
477 placeholder: "Search articles...",
478 value: "{search_query}",
479 oninput: move |e| search_query.set(e.value())
480 }
481 }
482
483 div { class: "news-sidebar-section",
485 h3 { class: "news-sidebar-title", "Filter by Topic" }
486 div { class: "news-tag-list",
487 for tag in all_tags.iter() {
488 {
489 let tag_str = *tag;
490 let tag_display = format_tag(tag_str);
491 let is_active = active_tag.read().as_deref() == Some(tag_str);
492 let count = tag_counts.get(tag_str).copied().unwrap_or(0);
493 rsx! {
494 button {
495 class: if is_active { "news-filter-tag active" } else { "news-filter-tag" },
496 onclick: move |_| {
497 if active_tag.read().as_deref() == Some(tag_str) {
498 active_tag.set(None);
499 } else {
500 active_tag.set(Some(tag_str.to_string()));
501 }
502 },
503 span { "{tag_display}" }
504 span { class: "news-filter-tag-count", "{count}" }
505 }
506 }
507 }
508 }
509 }
510
511 if active_tag.read().is_some() {
512 button {
513 class: "news-clear-filter",
514 onclick: move |_| active_tag.set(None),
515 "Clear filter"
516 }
517 }
518 }
519 }
520
521 main { class: "news-main",
523 header { class: "news-header",
524 h1 { "News" }
525 p { "Latest updates, release notes, and announcements" }
526
527 if let Some(tag) = active_tag.read().as_ref() {
529 {
530 let tag_display = format_tag(tag);
531 rsx! {
532 div { class: "news-active-filter",
533 span { class: "news-active-filter-label", "Showing:" }
534 span { class: "news-active-filter-tag",
535 "{tag_display}"
536 button {
537 class: "news-active-filter-clear",
538 onclick: move |_| active_tag.set(None),
539 "✕"
540 }
541 }
542 }
543 }
544 }
545 }
546 }
547
548 div { class: "news-mobile-filters",
550 div { class: "news-mobile-filters-header",
551 span { class: "news-mobile-filters-title", "Filter by topic" }
552 if active_tag.read().is_some() {
553 button {
554 class: "news-clear-filter",
555 onclick: move |_| active_tag.set(None),
556 "Clear"
557 }
558 }
559 }
560 div { class: "news-mobile-tags",
561 for tag in all_tags.iter() {
562 {
563 let tag_str = *tag;
564 let tag_display = format_tag(tag_str);
565 let is_active = active_tag.read().as_deref() == Some(tag_str);
566 rsx! {
567 button {
568 class: if is_active { "news-mobile-tag active" } else { "news-mobile-tag" },
569 onclick: move |_| {
570 if active_tag.read().as_deref() == Some(tag_str) {
571 active_tag.set(None);
572 } else {
573 active_tag.set(Some(tag_str.to_string()));
574 }
575 },
576 "{tag_display}"
577 }
578 }
579 }
580 }
581 }
582 }
583
584 if filtered_articles.is_empty() {
585 div { class: "news-no-results",
586 h3 { "No articles found" }
587 p { "Try adjusting your search or filter." }
588 }
589 } else {
590 div { class: "news-list",
591 for article in filtered_articles {
592 Link {
593 to: Route::NewsArticle { slug: article.slug.to_string() },
594 class: "news-card",
595 div { class: "news-card-date", "{article.date}" }
596 h2 { class: "news-card-title", "{article.title}" }
597 p { class: "news-card-summary", "{article.summary}" }
598 div { class: "news-card-tags",
599 for tag in article.tags.iter() {
600 {
601 let tag_display = format_tag(tag);
602 rsx! { span { class: "news-tag", "{tag_display}" } }
603 }
604 }
605 }
606 }
607 }
608 }
609 }
610 }
611 }
612
613 Footer {}
614 }
615 }
616}