feat: store chat_id to allow multiple chats, use enums in tauri
communication
This commit is contained in:
@@ -72,7 +72,7 @@ pub async fn chat_history(
|
||||
) -> Result<MessageHistory, String> {
|
||||
let mut client = state.grpc_client.lock().await;
|
||||
let result = client
|
||||
.chat_history(ChatHistoryRequest { chat_id: None })
|
||||
.chat_history(ChatHistoryRequest { chat_id: chat_id })
|
||||
.await;
|
||||
match result {
|
||||
Ok(response) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use feshared::daemon::DaemonState;
|
||||
use feshared::{chatmessage::TauriCommand, daemon::DaemonState};
|
||||
use leptos::{prelude::*, reactive::spawn_local};
|
||||
use leptos_router::{
|
||||
components::{Route, Router, Routes},
|
||||
@@ -34,7 +34,7 @@ fn Dashboard() -> impl IntoView {
|
||||
let on_click = move |_ev: leptos::ev::MouseEvent| {
|
||||
spawn_local(async move {
|
||||
let empty_args = serde_wasm_bindgen::to_value(&serde_json::json!({})).unwrap();
|
||||
invoke("toggle_popup", empty_args).await;
|
||||
invoke(TauriCommand::TogglePopup.as_str(), empty_args).await;
|
||||
});
|
||||
};
|
||||
view! {
|
||||
@@ -60,7 +60,7 @@ pub fn DaemonStatusIndicator() -> impl IntoView {
|
||||
);
|
||||
let status = LocalResource::new(move || async move {
|
||||
poll_count.get();
|
||||
let s: DaemonState = invoke_typed("daemon_state", JsValue::NULL).await;
|
||||
let s: DaemonState = invoke_typed(TauriCommand::DaemonState, JsValue::NULL).await;
|
||||
s
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use feshared::chatmessage::TauriCommand;
|
||||
use serde::{de::DeserializeOwned, Deserialize};
|
||||
use wasm_bindgen::prelude::*;
|
||||
#[wasm_bindgen]
|
||||
@@ -9,11 +10,11 @@ extern "C" {
|
||||
pub async fn listen(event: &str, handler: &Closure<dyn FnMut(JsValue)>) -> JsValue;
|
||||
}
|
||||
|
||||
pub async fn invoke_typed<T>(cmd: &str, args: JsValue) -> T
|
||||
pub async fn invoke_typed<T>(cmd: TauriCommand, args: JsValue) -> T
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let response = invoke(cmd, args).await;
|
||||
let response = invoke(cmd.as_str(), args).await;
|
||||
let result: T = serde_wasm_bindgen::from_value(response).unwrap();
|
||||
result
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use feshared::daemon::DaemonState;
|
||||
use feshared::{chatmessage::TauriCommand, daemon::DaemonState};
|
||||
use leptos::{component, prelude::*, reactive::spawn_local, view, IntoView};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasm_bindgen::JsValue;
|
||||
@@ -16,7 +16,7 @@ pub fn DaemonProvider(children: ChildrenFn) -> impl IntoView {
|
||||
);
|
||||
let status_res = LocalResource::new(move || async move {
|
||||
poll_count.get();
|
||||
let s: DaemonState = invoke_typed("daemon_state", JsValue::NULL).await;
|
||||
let s: DaemonState = invoke_typed(TauriCommand::DaemonState, JsValue::NULL).await;
|
||||
s
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ pub fn ThemeProvider(children: Children) -> impl IntoView {
|
||||
pub fn DarkModeToggle() -> impl IntoView {
|
||||
let toggle_dark_mode = |_ev: leptos::ev::MouseEvent| {
|
||||
spawn_local(async {
|
||||
let _ = invoke("toggle_dark_mode", JsValue::UNDEFINED).await;
|
||||
let _ = invoke(TauriCommand::ToggleDarkMode.as_str(), JsValue::UNDEFINED).await;
|
||||
});
|
||||
};
|
||||
view! {
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
components::{DaemonProvider, DarkModeToggle, ThemeProvider},
|
||||
};
|
||||
use feshared::{
|
||||
chatmessage::{Message, MessageHistory},
|
||||
chatmessage::{Message, MessageHistory, TauriCommand},
|
||||
daemon::DaemonState,
|
||||
};
|
||||
use leptos::{ev::keydown, html::Input, prelude::*};
|
||||
@@ -31,7 +31,7 @@ pub fn Popup() -> impl IntoView {
|
||||
|
||||
let init_history = Action::new_local(|(): &()| async move {
|
||||
let history: MessageHistory = invoke_typed(
|
||||
"chat_history",
|
||||
TauriCommand::ChatHistory,
|
||||
serde_wasm_bindgen::to_value(&serde_json::json!({"chat_id": 1})).unwrap(),
|
||||
)
|
||||
.await;
|
||||
@@ -55,7 +55,7 @@ pub fn Popup() -> impl IntoView {
|
||||
let prompt = prompt.clone();
|
||||
async move {
|
||||
let result: Vec<Message> = invoke_typed(
|
||||
"chat",
|
||||
TauriCommand::Chat,
|
||||
serde_wasm_bindgen::to_value(&serde_json::json!({"prompt": prompt})).unwrap(),
|
||||
)
|
||||
.await;
|
||||
@@ -88,7 +88,7 @@ pub fn Popup() -> impl IntoView {
|
||||
let _ = window_event_listener(keydown, move |ev| {
|
||||
if ev.key() == "Escape" {
|
||||
spawn_local(async move {
|
||||
let _ = invoke("toggle_popup", JsValue::UNDEFINED).await;
|
||||
let _ = invoke(TauriCommand::TogglePopup.as_str(), JsValue::UNDEFINED).await;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user