use super::{match_route, RouteVerdict};
use crate::{reactor::Reactor, template::BrowserNodeType};
use sycamore::prelude::Scope;
use sycamore_router::Route;
pub(crate) struct PerseusRoute<'cx> {
pub verdict: RouteVerdict,
pub cx: Option<Scope<'cx>>,
}
impl<'cx> Default for PerseusRoute<'cx> {
fn default() -> Self {
Self {
verdict: RouteVerdict::NotFound {
locale: "xx-XX".to_string(),
},
cx: None,
}
}
}
impl<'cx> PerseusRoute<'cx> {
pub fn get_verdict(&self) -> &RouteVerdict {
&self.verdict
}
}
impl<'cx> Route for PerseusRoute<'cx> {
fn match_route(&self, path: &[&str]) -> Self {
let path = path.join("/");
let path = js_sys::decode_uri_component(&path)
.unwrap()
.as_string()
.unwrap();
let path_segments = path
.split('/')
.filter(|s| !s.is_empty())
.collect::<Vec<&str>>();
let reactor = Reactor::<BrowserNodeType>::from_cx(self.cx.unwrap()); let verdict = match_route(
&path_segments,
&reactor.render_cfg,
&reactor.entities,
&reactor.locales,
);
Self {
verdict,
cx: self.cx,
}
}
}