add new rows based on the json response

This commit is contained in:
2026-07-01 21:21:35 +02:00
parent 922c28d426
commit 08915e1359
4 changed files with 38 additions and 9 deletions
Generated
+2
View File
@@ -4140,7 +4140,9 @@ dependencies = [
"base64", "base64",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-channel",
"futures-core", "futures-core",
"futures-util",
"h2", "h2",
"http", "http",
"http-body", "http-body",
+1 -1
View File
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
reqwest = "0.13.3" reqwest = { version = "0.13.3", features = ["blocking"] }
serde = "1.0.228" serde = "1.0.228"
serde_derive = "1.0.228" serde_derive = "1.0.228"
serde_json = "1.0.145" serde_json = "1.0.145"
+34 -7
View File
@@ -2,6 +2,7 @@
mod rutracker; mod rutracker;
use slint::{ModelRc, StandardListViewItem, VecModel}; use slint::{ModelRc, StandardListViewItem, VecModel};
use std::cell::RefCell;
use std::error::Error; use std::error::Error;
use std::rc::Rc; use std::rc::Rc;
@@ -9,23 +10,49 @@ slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?; let ui = AppWindow::new()?;
let response = Rc::new(RefCell::new(None));
let items = Rc::new(RefCell::new(Vec::<StandardListViewItem>::new()));
ui.on_request_text_input(|text| { let value = items.clone();
ui.on_request_text_input(move |text| {
println!("User input: {}", text); println!("User input: {}", text);
let _response = rutracker::search(&text); *response.borrow_mut() = Some(rutracker::search(&text));
//let response = rutracker::search(&text);
let response = response.borrow();
let new_items: Vec<StandardListViewItem> = response
.iter()
.map(|r| {
let text = match r {
Ok(value) => value.to_string(),
Err(err) => format!("Error: {}", err),
};
StandardListViewItem::from(text.as_str())
})
.collect();
*value.borrow_mut() = new_items;
}); });
let table_vec: Vec<ModelRc<StandardListViewItem>> = vec![]; let table_vec: Vec<ModelRc<StandardListViewItem>> = vec![];
let table_model = Rc::new(VecModel::from(table_vec)); let table_model = Rc::new(VecModel::from(table_vec));
let test = "test";
ui.set_table_data(table_model.to_owned().into()); ui.set_table_data(table_model.to_owned().into());
ui.on_add_row({ ui.on_add_row({
//let response = response.clone();
//move || {
// if let Some(_resp) = items.borrow().as_ref() {
// table_model.push(VecModel::from_slice(&[StandardListViewItem::from(
// //slint::SharedString::from(_resp),
// StandardListViewItem::from(_resp),
// )]));
// }
let items = items.clone();
move || { move || {
table_model.push(VecModel::from_slice(&[ let items = items.borrow();
StandardListViewItem::from(slint::SharedString::from(test)), for item in items.iter() {
//StandardListViewItem::from("<new>"), table_model.push(VecModel::from_slice(&[item.clone()]));
])); }
} }
}); });
+1 -1
View File
@@ -23,6 +23,6 @@ pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
serde_json::from_value(item.clone()).expect("Failed to deserialize"); serde_json::from_value(item.clone()).expect("Failed to deserialize");
println!("{:?}", software); println!("{:?}", software);
} }
println!("{:?}", data); //println!("{:?}", data);
Ok(v) Ok(v)
} }