This is the main thrust of the library. I know it is a lot of changes, but I was running out of time and had to hammer them all in.
62 lines
1.1 KiB
Rust
62 lines
1.1 KiB
Rust
use std::collections::HashSet;
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use crate::components::{BlogList, TagSelector};
|
|
use crate::page::Page;
|
|
|
|
|
|
|
|
fn convert_categories(categories: &str) -> HashSet<String>
|
|
{
|
|
categories
|
|
.split('+')
|
|
.filter(|s| !s.is_empty() && *s != "all")
|
|
.map(str::to_string)
|
|
.collect()
|
|
}
|
|
|
|
|
|
|
|
/// Blog page
|
|
#[component]
|
|
pub fn Blog(tag: ReadOnlySignal<String>) -> Element
|
|
{
|
|
let mut show_all: Signal<bool> =
|
|
use_signal(|| tag().is_empty() || tag() == "all");
|
|
|
|
let mut categories: Signal<HashSet<String>> =
|
|
use_signal(|| convert_categories(&tag()));
|
|
|
|
use_effect(move ||
|
|
{
|
|
let new_tags = convert_categories(&tag());
|
|
categories.set(new_tags);
|
|
});
|
|
|
|
println!("Blog Categories: {:?}", categories());
|
|
|
|
rsx!
|
|
{
|
|
main
|
|
{
|
|
class: "blog_style",
|
|
div
|
|
{
|
|
class: "page_content",
|
|
|
|
BlogList
|
|
{
|
|
tags: categories.clone()
|
|
}
|
|
|
|
TagSelector
|
|
{
|
|
show_all: show_all.clone(),
|
|
toggled_tags: categories.clone()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|