This commit is contained in:
Johannes Heuel
2023-03-04 17:38:50 +01:00
parent ac27cba766
commit 26dab06063
6 changed files with 654 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ use crate::hooks::use_user_context;
use gloo_net::http::Request;
use js_sys::Array;
use serde::{Deserialize, Serialize};
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
use web_sys::{DataTransferItemList, File, FileSystemDirectoryEntry, FileSystemEntry};
use weblog::console_log;
@@ -12,6 +13,15 @@ use yew_hooks::prelude::*;
use common::OutputPicture;
#[derive(Debug, Deserialize, Serialize)]
pub struct PhotosWrapper {
photos: Vec<String>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct PhotosUrlsWrapper {
photos: Vec<(String, String)>,
}
#[function_component(Home)]
pub fn home() -> Html {
let user_ctx = use_user_context();
@@ -92,7 +102,7 @@ pub fn home() -> Html {
let uiae: Vec<String> = files
.iter()
.map(|x| {
if let Ok(filepath) = js_sys::Reflect::get(&x, &JsValue::from_str("filepath")) {
if let Ok(filepath) = js_sys::Reflect::get(x, &JsValue::from_str("filepath")) {
filepath.as_string().unwrap_or("".to_string())
} else {
"".to_string()
@@ -100,6 +110,17 @@ pub fn home() -> Html {
})
.collect();
console_log!("end", uiae.join("\n"));
let url = "/api/photos/upload";
let photos: PhotosUrlsWrapper = Request::post(url)
.json(&PhotosWrapper { photos: uiae })
.unwrap()
.send()
.await
.unwrap()
.json()
.await
.unwrap();
console_log!("{}", serde_json::to_string(&photos).unwrap());
});
});