2025-09-12 13:52:35 -04:00
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
2025-09-08 10:01:02 -04:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
2025-09-12 13:57:43 -04:00
|
|
|
use crate::components::{BlogList, TagSelector};
|
2025-09-08 18:39:30 -04:00
|
|
|
use crate::page::Page;
|
2025-09-08 10:01:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-12 13:52:35 -04:00
|
|
|
fn convert_categories(categories: &str) -> HashSet<String>
|
|
|
|
|
{
|
2025-09-24 19:50:38 -04:00
|
|
|
categories
|
|
|
|
|
.split('+')
|
|
|
|
|
.filter(|s| !s.is_empty() && *s != "all")
|
|
|
|
|
.map(str::to_string)
|
|
|
|
|
.collect()
|
2025-09-12 13:52:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-08 10:01:02 -04:00
|
|
|
/// Blog page
|
|
|
|
|
#[component]
|
2025-09-24 19:50:38 -04:00
|
|
|
pub fn Blog(tag: ReadOnlySignal<String>) -> Element
|
2025-09-08 10:01:02 -04:00
|
|
|
{
|
2025-09-24 19:50:38 -04:00
|
|
|
let mut show_all: Signal<bool> =
|
|
|
|
|
use_signal(|| tag().is_empty() || tag() == "all");
|
|
|
|
|
|
2025-09-12 13:52:35 -04:00
|
|
|
let mut categories: Signal<HashSet<String>> =
|
2025-09-24 19:50:38 -04:00
|
|
|
use_signal(|| convert_categories(&tag()));
|
2025-09-08 10:01:02 -04:00
|
|
|
|
2025-09-24 19:50:38 -04:00
|
|
|
use_effect(move ||
|
2025-09-08 10:01:02 -04:00
|
|
|
{
|
2025-09-24 19:50:38 -04:00
|
|
|
let new_tags = convert_categories(&tag());
|
|
|
|
|
categories.set(new_tags);
|
|
|
|
|
});
|
2025-09-08 10:01:02 -04:00
|
|
|
|
2025-09-24 19:50:38 -04:00
|
|
|
println!("Blog Categories: {:?}", categories());
|
2025-09-08 10:01:02 -04:00
|
|
|
|
2025-09-24 19:50:38 -04:00
|
|
|
rsx!
|
|
|
|
|
{
|
2025-09-08 10:01:02 -04:00
|
|
|
main
|
|
|
|
|
{
|
|
|
|
|
class: "blog_style",
|
|
|
|
|
div
|
|
|
|
|
{
|
|
|
|
|
class: "page_content",
|
2025-09-12 13:52:35 -04:00
|
|
|
|
2025-09-08 10:01:02 -04:00
|
|
|
BlogList
|
|
|
|
|
{
|
2025-09-24 19:50:38 -04:00
|
|
|
tags: categories.clone()
|
2025-09-08 10:01:02 -04:00
|
|
|
}
|
2025-09-12 13:57:43 -04:00
|
|
|
|
|
|
|
|
TagSelector
|
|
|
|
|
{
|
2025-09-24 19:50:38 -04:00
|
|
|
show_all: show_all.clone(),
|
|
|
|
|
toggled_tags: categories.clone()
|
2025-09-12 13:57:43 -04:00
|
|
|
}
|
2025-09-08 10:01:02 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|