use crate::components::app::app_body::AppBody;
use crate::components::app::app_head::AppShellHead;
use crate::components::{app::app_body::app_body, app::app_head::app_head};
use crate::defaults::DEFAULT_THEME_ITEM;
use crate::utils::defaults::LANG_EN;
use crate::utils::types::{RUMString, SharedAppState, URLParams, URLPath};
use crate::{rumtk_web_get_text_item, rumtk_web_set_config, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
#[derive(RUMWebTemplate)]
#[template(
source = "
<!DOCTYPE html>
<html lang='{{lang}}'>
{{head}}
{{body}}
</html>
",
ext = "html"
)]
pub struct AppShell {
head: AppShellHead,
lang: RUMString,
body: AppBody,
}
impl RUMWebTemplateSafe for AppShell {}
pub fn app_shell<'a>(path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<AppShell> {
let lang = rumtk_web_get_text_item!(params, "lang", LANG_EN).to_string();
let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_THEME_ITEM).to_string();
rumtk_web_set_config!(state).lang = lang.clone();
rumtk_web_set_config!(state).theme = theme;
Ok(AppShell {
lang,
head: app_head(path_components, params, state.clone())?,
body: app_body(path_components, params, state.clone())?
})
}