feat: create struct from json response and create a table view
This commit is contained in:
Generated
+13
-12
@@ -2,6 +2,19 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "SoftwareManager-rs"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"slint",
|
||||||
|
"slint-build",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ab_glyph"
|
name = "ab_glyph"
|
||||||
version = "0.2.32"
|
version = "0.2.32"
|
||||||
@@ -4669,18 +4682,6 @@ dependencies = [
|
|||||||
"spin_on",
|
"spin_on",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "slint-rust-template"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"reqwest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"slint",
|
|
||||||
"slint-build",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slotmap"
|
name = "slotmap"
|
||||||
version = "1.1.1"
|
version = "1.1.1"
|
||||||
|
|||||||
+2
-1
@@ -1,11 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "slint-rust-template"
|
name = "SoftwareManager-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = "0.13.3"
|
reqwest = "0.13.3"
|
||||||
serde = "1.0.228"
|
serde = "1.0.228"
|
||||||
|
serde_derive = "1.0.228"
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
slint = "1.14.1"
|
slint = "1.14.1"
|
||||||
tokio = { version = "1.52.1", features = ["full"] }
|
tokio = { version = "1.52.1", features = ["full"] }
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
ui.on_request_text_input(|text| {
|
ui.on_request_text_input(|text| {
|
||||||
println!("User input: {}", text);
|
println!("User input: {}", text);
|
||||||
let response = rutracker::search(&text);
|
let _response = rutracker::search(&text);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.run()?;
|
ui.run()?;
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
use serde_derive::Serialize;
|
||||||
use serde_json::Value;
|
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]
|
#[tokio::main]
|
||||||
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
|
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
|
||||||
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
|
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 text = results.text().await?;
|
||||||
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
|
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
|
||||||
let data = &v["data"];
|
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);
|
println!("{:?}", data);
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-1
@@ -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 {
|
export component AppWindow inherits Window {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
@@ -7,13 +7,41 @@ export component AppWindow inherits Window {
|
|||||||
in-out property <string> search-text: "";
|
in-out property <string> search-text: "";
|
||||||
callback request-text-input(string);
|
callback request-text-input(string);
|
||||||
VerticalBox {
|
VerticalBox {
|
||||||
|
alignment: stretch;
|
||||||
|
// width: 50%;
|
||||||
|
// height: 50%;
|
||||||
|
|
||||||
LineEdit {
|
LineEdit {
|
||||||
|
width: 500px;
|
||||||
placeholder-text: "Search for Software";
|
placeholder-text: "Search for Software";
|
||||||
accepted(text) => {
|
accepted(text) => {
|
||||||
root.request-text-input(self.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" },
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user