summaryrefslogtreecommitdiff
path: root/src/view.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2020-10-19 22:46:45 +0200
committerjelemux <jeremias.weber@protonmail.com>2020-10-19 22:46:45 +0200
commit3a0a55362fd98c74bfb14df320bcacafd0c57835 (patch)
treead7f91af95df638bfbc58c48c97f34340ae37a8c /src/view.rs
parent84c2dab4200c37c818d83c95f85445ee00d83bf6 (diff)
downloadwasm-card-3a0a55362fd98c74bfb14df320bcacafd0c57835.tar.gz
wasm-card-3a0a55362fd98c74bfb14df320bcacafd0c57835.tar.bz2
break things down into their most basic parts
Diffstat (limited to 'src/view.rs')
-rw-r--r--src/view.rs72
1 files changed, 15 insertions, 57 deletions
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<Self>,
- 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 {
- Self { link }
+ fn create(_props: Self::Properties, _link: ComponentLink<Self>) -> 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! {
- <BCardForm/>
- }
- }
-}
-
-// example
-
-struct Model {
- link: ComponentLink<Self>,
- value: i64,
-}
-
-enum Msg {
- AddOne,
- Input(BCard),
-}
-
-impl Component for Model {
- type Message = Msg;
- type Properties = ();
-
- fn create(_: Self::Properties, link: ComponentLink<Self>) -> 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! {
- <div>
- <button onclick=self.link.callback(|_| Msg::AddOne)>{ "+1" }</button>
- <p>{ self.value }</p>
- </div>
+ 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!{
+ <a href=href download="demo.pdf" >
+ { "Download PDF" }
+ </a>
}
}
}
#[wasm_bindgen(start)]
pub fn run_app() {
- App::<Model>::new().mount_to_body();
+ App::<Form>::new().mount_to_body();
} \ No newline at end of file