use super::canvas::Canvas; use crate::agents::audio_agent::{self, AudioAgent}; use crate::components::Player; use web_sys::{File, HtmlInputElement}; use yew::agent::Dispatcher; use yew::prelude::*; use yew::services::ConsoleService; use wasm_bindgen::prelude::*; use weblog::*; #[wasm_bindgen(module = "/static/player.js")] extern "C" { fn get_val() -> i32; fn load_file(file: &str) -> i32; } pub struct Container { link: ComponentLink, file_input: NodeRef, audio_agent: Dispatcher, zoom_factor: i32, } pub enum Msg { SubmitForm, ZoomButtonClicked(i32), } impl Component for Container { type Message = Msg; type Properties = (); fn create(_: Self::Properties, link: ComponentLink) -> Self { Self { link, file_input: NodeRef::default(), audio_agent: AudioAgent::dispatcher(), zoom_factor: 1, } } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::SubmitForm => { if let Err(e) = self.handle_upload() { ConsoleService::error(&e); }; } Msg::ZoomButtonClicked(factor) => { self.zoom_factor = factor; } }; true } fn change(&mut self, _: Self::Properties) -> ShouldRender { true } fn view(&self) -> Html { html! {

{ "Zoom" }

} } } impl Container { fn handle_upload(&mut self) -> Result<(), String> { let file_input = self .file_input .cast::() .ok_or("could not cast file_input")?; let file_list = file_input.files().ok_or("could not get file list")?; let file = file_list.get(0).ok_or("could not get file")?; load_file("oh!"); console_log!("Done."); Ok(()) } }