use crate::components::{app_body::app_body, app_head::app_head};
use crate::utils::defaults::{DEFAULT_TEXT_ITEM, LANG_EN};
use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
use crate::{
rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html, rumtk_web_set_config,
RUMWebTemplate,
};
use rumtk_core::{rumtk_critical_section_read, rumtk_critical_section_write};
#[derive(RUMWebTemplate)]
#[template(
source = "
<!DOCTYPE html>
<html lang='{{lang}}'>
{{head|safe}}
{{body|safe}}
</html>
",
ext = "html"
)]
pub struct AppShell {
head: RUMString,
lang: RUMString,
body: RUMString,
}
pub fn app_shell(path_components: URLPath, params: URLParams, state: SharedAppState) -> HTMLResult {
let lang = rumtk_web_get_text_item!(params, "lang", LANG_EN);
let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
rumtk_web_set_config!(state).lang = RUMString::from(lang);
rumtk_web_set_config!(state).theme = RUMString::from(theme);
let head = rumtk_web_render_component!(|| -> HTMLResult {
app_head(path_components, params, state.clone())
});
let body = rumtk_web_render_component!(|| -> HTMLResult {
app_body(path_components, params, state.clone())
});
rumtk_web_render_html!(AppShell {
lang: RUMString::from(lang),
head,
body
})
}