From 3a0a55362fd98c74bfb14df320bcacafd0c57835 Mon Sep 17 00:00:00 2001 From: jelemux Date: Mon, 19 Oct 2020 22:46:45 +0200 Subject: break things down into their most basic parts --- src/view.rs | 72 +++++++++++++------------------------------------------------ 1 file changed, 15 insertions(+), 57 deletions(-) (limited to 'src/view.rs') diff --git a/src/view.rs b/src/view.rs index 81634ed..9b95691 100644 --- a/src/view.rs +++ b/src/view.rs @@ -1,83 +1,41 @@ -use crate::model::BCard; +use crate::pdfgen; use wasm_bindgen::prelude::*; +use js_sys; use yew::prelude::*; struct Form { - link: ComponentLink, - bcard: BCard, } -impl Component for Form { // probably not necessary but who knows +impl Component for Form { type Message = (); type Properties = (); - fn create(_: Self::Properties, link: ComponentLink) -> Self { - Self { link } + fn create(_props: Self::Properties, _link: ComponentLink) -> Self { + Self { } } - fn update(&mut self, _: Self::Message) -> ShouldRender { + fn update(&mut self, _msg: Self::Message) -> ShouldRender { false } - fn change(&mut self, _: Self::Properties) -> ShouldRender { - false - } - - fn view(&self) -> Html { - html! { - - } - } -} - -// example - -struct Model { - link: ComponentLink, - value: i64, -} - -enum Msg { - AddOne, - Input(BCard), -} - -impl Component for Model { - type Message = Msg; - type Properties = (); - - fn create(_: Self::Properties, link: ComponentLink) -> Self { - Self { - link, - value: 0, - } - } - - fn update(&mut self, msg: Self::Message) -> ShouldRender { - match msg { - Msg::AddOne => self.value += 1 - } - true - } - fn change(&mut self, _props: Self::Properties) -> ShouldRender { - // Should only return "true" if new properties are different to - // previously received properties. - // This component has no properties so we will always return "false". false } fn view(&self) -> Html { - html! { -
- -

{ self.value }

-
+ let pdf_raw = /*include_bytes!("../demo.pdf"); // this works */pdfgen::genpdf(); // this doesn't work + let pdf = std::str::from_utf8(&pdf_raw).expect("should be able to convert to string"); + let uri_component: String = js_sys::encode_uri_component(pdf).into(); + let href = format!{"data:application/pdf;charset=utf-8,{}", uri_component }; + html!{ + + { "Download PDF" } + } } } #[wasm_bindgen(start)] pub fn run_app() { - App::::new().mount_to_body(); + App::
::new().mount_to_body(); } \ No newline at end of file -- cgit v1.2.3