Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dbclient"
version = "0.4.3"
version = "0.4.4"
edition = "2021"

[dependencies]
Expand Down
6 changes: 2 additions & 4 deletions src/ui4/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
)
}
},
Expand Down
3 changes: 1 addition & 2 deletions src/ui4/components/table_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
24 changes: 17 additions & 7 deletions src/ui4/query_area.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -17,12 +17,22 @@ pub struct QueryAreaProps {
pub objects_client: Option<Arc<dyn proto::objects::ObjectsService + Send + Sync>>,
pub queries_client: Option<Arc<dyn proto::queries::QueriesService + Send + Sync>>,
pub state: Arc<Mutex<AppState>>,
pub query_result_cmd_pipe: Option<tokio::sync::mpsc::Sender<QueryResultCmd>>,
pub query_result_cmd_receiver: Option<tokio::sync::mpsc::Receiver<QueryResultCmd>>,
}

#[component]
pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into<AnyElement<'static>> {
pub async fn QueryArea(
props: &mut QueryAreaProps,
mut hooks: Hooks,
) -> impl Into<AnyElement<'static>> {
let chan = hooks.use_state(|| {
let (query_result_cmd_sender, query_result_cmd_reader) =
tokio::sync::mpsc::channel::<QueryResultCmd>(10);
return (
query_result_cmd_sender,
Arc::new(Mutex::new(query_result_cmd_reader)),
);
});

element! {
View (
width: 100pct,
Expand All @@ -31,7 +41,7 @@ pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into<AnyElement<'static>> {
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()
)
}
Expand All @@ -41,8 +51,8 @@ pub fn QueryArea(props: &mut QueryAreaProps) -> impl Into<AnyElement<'static>> {
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()),
)
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/ui4/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct QueryResultProps {
pub objects_client: Option<Arc<dyn proto::objects::ObjectsService + Send + Sync>>,
pub state: Arc<Mutex<AppState>>,
pub cmd_pipe: Option<tokio::sync::mpsc::Sender<QueryResultCmd>>,
pub cmd_receiver: Option<tokio::sync::mpsc::Receiver<QueryResultCmd>>,
pub cmd_receiver: Option<Arc<Mutex<tokio::sync::mpsc::Receiver<QueryResultCmd>>>>,
}

#[component]
Expand All @@ -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!()
}
Expand Down
Loading