From e17d3c00383932411096db200de96be97c034794 Mon Sep 17 00:00:00 2001 From: HeavyPunk Date: Thu, 8 Oct 2026 04:12:08 +0500 Subject: [PATCH 1/2] fix: save cmd channel into hook context to avoid desync --- src/ui4/app_state.rs | 6 ++---- src/ui4/components/table_view.rs | 3 +-- src/ui4/query_area.rs | 24 +++++++++++++++++------- src/ui4/query_result.rs | 20 ++++++++++++-------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/ui4/app_state.rs b/src/ui4/app_state.rs index 6448b85..1e0ff13 100644 --- a/src/ui4/app_state.rs +++ b/src/ui4/app_state.rs @@ -2,9 +2,9 @@ use std::{sync::Arc, time::Duration}; use iocraft::{ component, - components::{Text, View}, + components::View, element, - hooks::{UseFuture, UseState, UseTerminalEvents, UseTerminalSize}, + hooks::{UseFuture, UseState, UseTerminalSize}, AnyElement, Hooks, Props, }; use tokio::sync::Mutex; @@ -115,8 +115,6 @@ pub fn AppContainer( queries_client: props.queries_client.clone(), objects_client: props.objects_client.clone(), state: props.state.clone(), - query_result_cmd_pipe: props.query_result_cmd_pipe.clone(), - query_result_cmd_receiver: props.query_result_cmd_receiver.take(), ) } }, diff --git a/src/ui4/components/table_view.rs b/src/ui4/components/table_view.rs index 039d98d..1c77249 100644 --- a/src/ui4/components/table_view.rs +++ b/src/ui4/components/table_view.rs @@ -5,8 +5,7 @@ use iocraft::{ components::{BorderStyle, ScrollView, ScrollViewHandle, Text, View}, element, hooks::{UseRef, UseState}, - AnyElement, Color, Edges, FlexDirection, Hooks, KeyCode, KeyEventKind, KeyModifiers, - Props, + AnyElement, Color, Edges, FlexDirection, Hooks, KeyCode, KeyEventKind, KeyModifiers, Props, }; use crate::{core::proto::common::db_field::Field, ui4::control::UseHotkeys}; diff --git a/src/ui4/query_area.rs b/src/ui4/query_area.rs index c91b092..952b337 100644 --- a/src/ui4/query_area.rs +++ b/src/ui4/query_area.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use iocraft::{component, components::View, element, AnyElement, Props}; +use iocraft::{component, components::View, element, hooks::UseState, AnyElement, Hooks, Props}; use tokio::sync::Mutex; use crate::{ @@ -17,12 +17,22 @@ pub struct QueryAreaProps { pub objects_client: Option>, pub queries_client: Option>, pub state: Arc>, - pub query_result_cmd_pipe: Option>, - pub query_result_cmd_receiver: Option>, } #[component] -pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into> { +pub async fn QueryArea( + props: &mut QueryAreaProps, + mut hooks: Hooks, +) -> impl Into> { + let chan = hooks.use_state(|| { + let (query_result_cmd_sender, query_result_cmd_reader) = + tokio::sync::mpsc::channel::(10); + return ( + query_result_cmd_sender, + Arc::new(Mutex::new(query_result_cmd_reader)), + ); + }); + element! { View ( width: 100pct, @@ -31,7 +41,7 @@ pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into> { View (width: 30pct) { DbObjects( objects_client: props.objects_client.clone(), - cmd_pipe: props.query_result_cmd_pipe.clone(), + cmd_pipe: Some(chan.read().0.clone()), state: props.state.clone() ) } @@ -41,8 +51,8 @@ pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into> { queries_client: props.queries_client.clone(), objects_client: props.objects_client.clone(), state: props.state.clone(), - cmd_pipe: props.query_result_cmd_pipe.clone(), - cmd_receiver: props.query_result_cmd_receiver.take(), + cmd_pipe: Some(chan.read().0.clone()), + cmd_receiver: Some(chan.read().1.clone()), ) } } diff --git a/src/ui4/query_result.rs b/src/ui4/query_result.rs index eaa8251..cf73d11 100644 --- a/src/ui4/query_result.rs +++ b/src/ui4/query_result.rs @@ -36,7 +36,7 @@ pub struct QueryResultProps { pub objects_client: Option>, pub state: Arc>, pub cmd_pipe: Option>, - pub cmd_receiver: Option>, + pub cmd_receiver: Option>>>, } #[component] @@ -58,15 +58,19 @@ pub fn QueryResult( View }; }; - let cmd_receiver = props.cmd_receiver.take(); - hooks.use_future(async move { - let Some(mut cmd_receiver) = cmd_receiver else { - return; + let Some(cmd_receiver) = props.cmd_receiver.clone() else { + // TODO: maybe log this branch + return element! { + View }; + }; + hooks.use_future(async move { loop { - tokio::time::sleep(Duration::from_millis(50)).await; // TODO: move to channels instead - // of shared state - match cmd_receiver.recv().await { + let cmd = { + let mut receiver = cmd_receiver.lock().await; + receiver.recv().await + }; + match cmd { Some(QueryResultCmd::ExecuteRawQuery) => { todo!() } From 1ceddf3a281e549d4e338dbd30c1ad536f192490 Mon Sep 17 00:00:00 2001 From: HeavyPunk Date: Thu, 8 Oct 2026 04:20:27 +0500 Subject: [PATCH 2/2] fix: update version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d6e544..07d8bb7 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -318,7 +318,7 @@ dependencies = [ [[package]] name = "dbclient" -version = "0.4.3" +version = "0.4.4" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index eb66f63..07e387d 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dbclient" -version = "0.4.3" +version = "0.4.4" edition = "2021" [dependencies]