-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add listBucket function to wasm
- Loading branch information
Showing
9 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use js_sys::Promise; | ||
use serde_json::{Value}; | ||
use wasm_bindgen::JsValue; | ||
use wasm_bindgen_futures::{spawn_local, JsFuture}; | ||
use yew::{prelude::{function_component, html}, use_context, use_effect, use_state, use_effect_with_deps}; | ||
use web_sys::{console}; | ||
use serde_wasm_bindgen::from_value; | ||
use serde::{Deserialize}; | ||
|
||
use crate::constants::app::AppContext; | ||
|
||
#[derive(Deserialize)] | ||
pub struct File { | ||
Key: Value, | ||
Size: Value, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct BucketInfo { | ||
Contents: Vec<File>, | ||
} | ||
|
||
|
||
#[function_component(Bucket)] | ||
pub fn bucket() -> Html { | ||
let list_fetch_in_content = use_context::<AppContext>() | ||
.expect("no ctx list_fetch_in_content found").list_bucket; | ||
let list = use_state(|| None); | ||
let fetched = use_state(|| false); | ||
|
||
{ | ||
let list_fetch_in_content = list_fetch_in_content.clone(); | ||
let list_clone = list.clone(); | ||
let fetched_clone = fetched.clone(); | ||
use_effect_with_deps( | ||
move |&fetched| { | ||
let cleanup = || {}; | ||
if fetched { | ||
return cleanup; | ||
} | ||
spawn_local(async move { | ||
let result = list_fetch_in_content.call0(&JsValue::NULL).unwrap(); | ||
let promise = Promise::from(result); | ||
let data = JsFuture::from(promise).await.unwrap(); | ||
console::log_2(&JsValue::from_str("data"), &data); | ||
let info: BucketInfo = from_value(data).unwrap(); | ||
list_clone.set(Some(info.Contents)); | ||
fetched_clone.set(true); | ||
}); | ||
cleanup | ||
}, | ||
*fetched | ||
) | ||
} | ||
|
||
html! { | ||
<div> | ||
<h2>{"Bucket"}</h2> | ||
<ul> | ||
</ul> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ pub mod graph; | |
mod header; | ||
mod login; | ||
mod me; | ||
pub mod bucket; | ||
|
||
pub use header::*; | ||
pub use login::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters