feat: add profile language preferences and refine toast, dropdown and history UI
This commit is contained in:
+17
-3
@@ -24,6 +24,7 @@ const MODULES: &[&str] = &[
|
||||
"emoji-picker",
|
||||
"image-alias",
|
||||
"image-upload",
|
||||
"i18n",
|
||||
"logger",
|
||||
"line-links",
|
||||
"markdown",
|
||||
@@ -64,7 +65,7 @@ pub fn render_html(
|
||||
urls.stylesheet_path("libs/rustpad-player/player.css"),
|
||||
);
|
||||
let html = template
|
||||
.replace("__APP_THEME_BOOTSTRAP__", theme_bootstrap())
|
||||
.replace("__APP_THEME_BOOTSTRAP__", &format!("{}{}", theme_bootstrap(), language_bootstrap()))
|
||||
.replace("__APP_STYLESHEET__", &app_stylesheets)
|
||||
.replace("__APP_IMPORT_MAP__", &urls.import_map())
|
||||
.replace("__APP_ENTRYPOINT__", &urls.entrypoint(entrypoint))
|
||||
@@ -95,10 +96,22 @@ pub fn theme_bootstrap() -> &'static str {
|
||||
r#"<script>(()=>{const key="rustpad:theme";let theme=matchMedia("(prefers-color-scheme: light)").matches?"light":"dark";try{const saved=localStorage.getItem(key);if(saved==="light"||saved==="dark")theme=saved}catch{}const root=document.documentElement;root.dataset.theme=theme;root.style.colorScheme=theme;const meta=document.querySelector('meta[name="color-scheme"]');if(meta)meta.content=theme})();</script>"#
|
||||
}
|
||||
|
||||
pub fn language_bootstrap() -> &'static str {
|
||||
r#"<script>(()=>{const key="rustpad:language";let lang="en";try{if(localStorage.getItem("rustpad:auth-state")==="1"){const saved=localStorage.getItem(key);if(saved)lang=saved}}catch{}const root=document.documentElement;root.lang=lang;if(lang!=="en"){root.dataset.i18nPending="true";root.style.visibility="hidden"}})();</script>"#
|
||||
}
|
||||
|
||||
pub fn stylesheet_tag(asset_version: &str, name: &str) -> String {
|
||||
AssetUrls::new(asset_version).stylesheet(name)
|
||||
}
|
||||
|
||||
pub fn import_map_tag(asset_version: &str) -> String {
|
||||
AssetUrls::new(asset_version).import_map()
|
||||
}
|
||||
|
||||
pub fn i18n_entrypoint() -> &'static str {
|
||||
r#"<script type="module">import { initI18n } from "@rustpad/i18n";await initI18n();</script>"#
|
||||
}
|
||||
|
||||
fn frontend_config(
|
||||
frontend_log_level: &str,
|
||||
upload_max_size_bytes: usize,
|
||||
@@ -136,9 +149,10 @@ impl<'a> AssetUrls<'a> {
|
||||
}
|
||||
|
||||
fn entrypoint(&self, name: &str) -> String {
|
||||
let entrypoint = self.url(&format!("js/{name}.js"));
|
||||
format!(
|
||||
r#"<script type="module" src="{}"></script>"#,
|
||||
self.url(&format!("js/{name}.js"))
|
||||
r#"<script type="module">import {{ initI18n }} from "@rustpad/i18n";await initI18n();await import("{}");</script>"#,
|
||||
escape_js_string(&entrypoint)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user