WIP on persisting chat history on daemon
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
use crate::bridge::invoke;
|
||||
use feshared::chatmessage::{Message, MessageHistory};
|
||||
use leptos::{ev::keydown, html::Input, prelude::*};
|
||||
use wasm_bindgen::{prelude::Closure, JsCast, JsValue};
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Message {
|
||||
id: usize,
|
||||
text: String,
|
||||
is_user: bool,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Popup() -> impl IntoView {
|
||||
// Prompt signals and and action
|
||||
@@ -34,7 +28,7 @@ pub fn Popup() -> impl IntoView {
|
||||
if let Some(result) = prompt_action.value().get() {
|
||||
set_messages.update(|previous| {
|
||||
previous.push(Message {
|
||||
id: previous.len(),
|
||||
id: previous.len() as i64,
|
||||
text: result,
|
||||
is_user: false,
|
||||
});
|
||||
@@ -66,6 +60,12 @@ pub fn Popup() -> impl IntoView {
|
||||
}
|
||||
});
|
||||
|
||||
spawn_local(async move {
|
||||
let response = invoke("chat_history", JsValue::bigint_from_str("1")).await;
|
||||
let history: MessageHistory = serde_wasm_bindgen::from_value(response).unwrap();
|
||||
set_messages.set(history.history.clone());
|
||||
});
|
||||
|
||||
view! {
|
||||
<main class="window-shell rounded-container">
|
||||
<h3>"AI quick action"</h3>
|
||||
@@ -79,7 +79,7 @@ pub fn Popup() -> impl IntoView {
|
||||
if ev.key() == "Enter" {
|
||||
set_messages.update(|previous| {
|
||||
previous.push(Message {
|
||||
id: previous.len(),
|
||||
id: previous.len() as i64,
|
||||
text: prompt_text.get(),
|
||||
is_user: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user