101 lines
2.5 KiB
Rust
101 lines
2.5 KiB
Rust
|
|
use leptos::*;
|
||
|
|
use wasm_bindgen::prelude::*;
|
||
|
|
use wasm_bindgen::JsCast;
|
||
|
|
use console_error_panic_hook;
|
||
|
|
use tracing_wasm;
|
||
|
|
|
||
|
|
mod app;
|
||
|
|
mod components;
|
||
|
|
mod pages;
|
||
|
|
mod store;
|
||
|
|
mod utils;
|
||
|
|
mod api;
|
||
|
|
|
||
|
|
use app::App;
|
||
|
|
|
||
|
|
// Main entry point for the Leptos CSR application
|
||
|
|
fn main() {
|
||
|
|
// Initialize panic hook for better error messages in development
|
||
|
|
console_error_panic_hook::set_once();
|
||
|
|
|
||
|
|
// Initialize tracing for logging
|
||
|
|
tracing_wasm::set_as_global_default();
|
||
|
|
|
||
|
|
// Log application startup
|
||
|
|
tracing::info!("Starting Control Center UI");
|
||
|
|
|
||
|
|
// Also log to browser console
|
||
|
|
web_sys::console::log_1(&"🚀 Control Center UI WASM loaded and main() called".into());
|
||
|
|
|
||
|
|
// Try mounting to body first to test basic functionality
|
||
|
|
leptos::mount_to_body(|| {
|
||
|
|
view! {
|
||
|
|
<div style="position: fixed; top: 0; left: 0; z-index: 9999; background: red; color: white; padding: 10px;">
|
||
|
|
"🚀 LEPTOS IS WORKING!"
|
||
|
|
</div>
|
||
|
|
<App/>
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
web_sys::console::log_1(&"✅ Leptos app mounted to body".into());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Export functions that can be called from JavaScript
|
||
|
|
#[wasm_bindgen]
|
||
|
|
extern "C" {
|
||
|
|
#[wasm_bindgen(js_namespace = console)]
|
||
|
|
fn log(s: &str);
|
||
|
|
|
||
|
|
#[wasm_bindgen(js_namespace = localStorage)]
|
||
|
|
fn getItem(key: &str) -> Option<String>;
|
||
|
|
|
||
|
|
#[wasm_bindgen(js_namespace = localStorage)]
|
||
|
|
fn setItem(key: &str, value: &str);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Helper macro for console logging
|
||
|
|
#[allow(unused_macros)]
|
||
|
|
macro_rules! console_log {
|
||
|
|
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
|
||
|
|
}
|
||
|
|
|
||
|
|
#[allow(unused_imports)]
|
||
|
|
pub(crate) use console_log;
|
||
|
|
|
||
|
|
// Utility functions for localStorage interaction
|
||
|
|
pub fn get_local_storage_item(key: &str) -> Option<String> {
|
||
|
|
getItem(key)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn set_local_storage_item(key: &str, value: &str) {
|
||
|
|
setItem(key, value);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Theme utilities
|
||
|
|
pub fn get_saved_theme() -> String {
|
||
|
|
get_local_storage_item("theme").unwrap_or_else(|| "light".to_string())
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn save_theme(theme: &str) {
|
||
|
|
set_local_storage_item("theme", theme);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Performance monitoring
|
||
|
|
#[wasm_bindgen]
|
||
|
|
pub fn mark_performance(name: &str) {
|
||
|
|
#[wasm_bindgen]
|
||
|
|
extern "C" {
|
||
|
|
#[wasm_bindgen(js_namespace = ["window", "performance"], js_name = mark)]
|
||
|
|
fn performance_mark(name: &str);
|
||
|
|
}
|
||
|
|
|
||
|
|
performance_mark(name);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Initialize application
|
||
|
|
#[wasm_bindgen(start)]
|
||
|
|
pub fn start() {
|
||
|
|
// This function is called when the WASM module is instantiated
|
||
|
|
tracing::info!("WASM module initialized");
|
||
|
|
mark_performance("wasm-initialized");
|
||
|
|
}
|