feat: create struct from json response and create a table view

This commit is contained in:
2026-05-03 16:55:23 +02:00
parent 58687643fb
commit 175f5459a8
5 changed files with 61 additions and 15 deletions
Generated
+13 -12
View File
@@ -2,6 +2,19 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "SoftwareManager-rs"
version = "0.1.0"
dependencies = [
"reqwest",
"serde",
"serde_derive",
"serde_json",
"slint",
"slint-build",
"tokio",
]
[[package]]
name = "ab_glyph"
version = "0.2.32"
@@ -4669,18 +4682,6 @@ dependencies = [
"spin_on",
]
[[package]]
name = "slint-rust-template"
version = "0.1.0"
dependencies = [
"reqwest",
"serde",
"serde_json",
"slint",
"slint-build",
"tokio",
]
[[package]]
name = "slotmap"
version = "1.1.1"
+2 -1
View File
@@ -1,11 +1,12 @@
[package]
name = "slint-rust-template"
name = "SoftwareManager-rs"
version = "0.1.0"
edition = "2021"
[dependencies]
reqwest = "0.13.3"
serde = "1.0.228"
serde_derive = "1.0.228"
serde_json = "1.0.145"
slint = "1.14.1"
tokio = { version = "1.52.1", features = ["full"] }
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn Error>> {
ui.on_request_text_input(|text| {
println!("User input: {}", text);
let response = rutracker::search(&text);
let _response = rutracker::search(&text);
});
ui.run()?;
+16
View File
@@ -1,5 +1,16 @@
use serde_derive::Deserialize;
use serde_derive::Serialize;
use serde_json::Value;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Software {
pub author: String,
pub leechers: String,
pub seeders: String,
pub title: String,
pub url: String,
}
#[tokio::main]
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
@@ -7,6 +18,11 @@ pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
let text = results.text().await?;
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
let data = &v["data"];
for item in data.as_array().unwrap() {
let software: Software =
serde_json::from_value(item.clone()).expect("Failed to deserialize");
println!("{:?}", software);
}
println!("{:?}", data);
Ok(v)
}
+29 -1
View File
@@ -1,4 +1,4 @@
import { Button, LineEdit, VerticalBox } from "std-widgets.slint";
import { Button, LineEdit, VerticalBox, HorizontalBox, StandardTableView } from "std-widgets.slint";
export component AppWindow inherits Window {
width: 200px;
@@ -7,13 +7,41 @@ export component AppWindow inherits Window {
in-out property <string> search-text: "";
callback request-text-input(string);
VerticalBox {
alignment: stretch;
// width: 50%;
// height: 50%;
LineEdit {
width: 500px;
placeholder-text: "Search for Software";
accepted(text) => {
root.request-text-input(self.text);
}
}
HorizontalBox {
StandardTableView {
// width: 230px;
// height: 200px;
columns: [
{ title: "Post Title" },
{ title: "Author" },
{ title: "Seeders" },
{ title: "Leechers" },
];
rows: [
[
{ text: "Item 1" }, { text: "Item 2" },
],
[
{ text: "Item 1" }, { text: "Item 2" },
],
[
{ text: "Item 1" }, { text: "Item 2" },
]
];
}
}
}
}