From 7e2b515ffb765e1fbe929b3e4f9ac1b4539fbe2e Mon Sep 17 00:00:00 2001 From: Jacob Morgan Date: Sat, 20 Apr 2024 22:29:10 +0200 Subject: [PATCH] Initial settings functions broke overall app. Restored functionality with different approach for settings --- assets/style.css | 4 ++-- src/site/app.rs | 50 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/assets/style.css b/assets/style.css index 94735f1..2ae194a 100644 --- a/assets/style.css +++ b/assets/style.css @@ -64,7 +64,7 @@ .workload-update-available { color: #5944AD; /* Cool, deep purple */ font-weight: bold; - order: 1!important; + order: 2!important; } .workload-version, .workload-image, .workload-namespace, .workload-last-scanned, .workload-latest-version { @@ -114,6 +114,6 @@ padding: 20px; border-radius: 8px; background: white; - order: 2; margin: 20px; + order: 1!important; } diff --git a/src/site/app.rs b/src/site/app.rs index d75d854..0cb8552 100644 --- a/src/site/app.rs +++ b/src/site/app.rs @@ -1,6 +1,7 @@ #![allow(non_snake_case, unused)] use dioxus::prelude::*; +use dioxus::prelude::server_fn::response::Res; use dioxus::prelude::ServerFnError; use serde_derive::{Deserialize, Serialize}; use wasm_bindgen_futures::spawn_local; @@ -20,7 +21,7 @@ enum Route { SettingsPage {}, } -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Deserialize, Serialize, Clone)] #[allow(unused)] pub struct AppSettings { pub settings: Settings, @@ -53,7 +54,7 @@ fn SettingsCard(props: AppSettings) -> Element { #[component] fn SettingsPage() -> Element { - let settings_context = use_context::>(); + let settings_context = use_context::>(); let settings = settings_context.read(); rsx! { //div { @@ -67,21 +68,21 @@ fn SettingsPage() -> Element { div { class: "settings-section-header", "System Settings" }, div { class: "settings-item", span { class: "settings-item-key", "Schedule: " }, - span { class: "settings-item-value", "{settings.settings.system.schedule}" } + span { class: "settings-item-value", "{settings.system.schedule}" } }, div { class: "settings-item", span { class: "settings-item-key", "Data Directory: " }, - span { class: "settings-item-value", "{settings.settings.system.data_dir}" } + span { class: "settings-item-value", "{settings.system.data_dir}" } }, div { class: "settings-item", span { class: "settings-item-key", "Run at Startup: " }, - span { class: "settings-item-value", "{settings.settings.system.run_at_startup}" } + span { class: "settings-item-value", "{settings.system.run_at_startup}" } } }, div { class: "settings-section", div { class: "settings-section-header", "Gitops Settings" }, - for gitops in settings.clone().settings.gitops.unwrap().iter() { + for gitops in settings.clone().gitops.unwrap().iter() { div { class: "settings-item", span { class: "settings-item-key", "Name: " } span { class: "settings-item-value", "{gitops.name}" } @@ -174,6 +175,7 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element { button {onclick: move |_| { to_owned![data, props.workload]; async move { + println!("Refresh button clicked"); if let Ok(_) = update_workload(data()).await { } } @@ -188,6 +190,7 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element { br {} button { onclick: move |_| { async move { + println!("Upgrade button clicked"); if let Ok(_) = upgrade_workload(data()).await { } } @@ -200,17 +203,32 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element { pub fn App() -> Element { println!("App started"); - use_context_provider(|| Signal::new(AppSettings { settings: Settings::new().unwrap_or_else( - |err| { - log::error!("Failed to load settings: {}", err); - panic!("Failed to load settings: {}", err); - } - ) })); + let settings = use_server_future(load_settings)?; + if let Some(Err(err)) = settings() { + return rsx! { div { "Error: {err}" } }; + } + if let Some(Ok(settings)) = settings() { + println!("Settings: {:?}", settings); + use_context_provider(|| Signal::new(settings)); + } + //use_context_provider(|| { + // //Signal::new(settings) + //}); + +// use_context_provider(|| Signal::new(Appsettings:settings) ); +// use_context_provider(|| Signal::new(load_settings) ); //load config rsx! { Router:: {} } } +#[server] +async fn load_settings() -> Result { + let settings = Settings::new().unwrap(); + Ok(settings) + +} + #[component] fn RefreshAll() -> Element { let refresh = use_server_future(refresh_all)?; @@ -285,10 +303,11 @@ fn All() -> Element { #[component] fn NextScheduledTimeCard() -> Element { - let settings_context = use_context::>().clone(); + let settings_context = use_context::>(); + log::info!("settings context: {:?}", settings_context); let mut next_schedule = use_server_future(move || async move { let settings = settings_context.read(); - get_next_schedule_time(settings.settings.clone()).await + get_next_schedule_time(settings.clone()).await })?; match next_schedule() { Some(Ok(next_schedule)) => { @@ -296,6 +315,7 @@ fn NextScheduledTimeCard() -> Element { div { class: "next-scheduled-time", div { class: "system-info", "System Info" }, div { "Next Run: {next_schedule}" } + a { href: "/refresh-all", "Click to Run Now" } } } }, @@ -360,8 +380,6 @@ async fn refresh_all() -> Result<(), ServerFnError> { #[server] async fn get_all() -> Result, ServerFnError> { use crate::database::client::return_all_workloads; - let settings_context = consume_context::>(); - log::info!("settings_context: {:?}", settings_context); let workloads = return_all_workloads(); log::info!("get_all_workloads: {:?}", workloads); Ok(workloads.unwrap())