-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ad28af
commit 99e1ce3
Showing
19 changed files
with
394 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::rc::Rc; | ||
|
||
use utils::js_wrappers::download_url; | ||
|
||
use super::QrDialog; | ||
|
||
impl QrDialog { | ||
pub fn download(self: &Rc<Self>) { | ||
download_url(&self.file_label, &self.url) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
frontend/apps/crates/components/src/qr_dialog/callbacks.rs
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,11 @@ | ||
pub struct QrDialogCallbacks { | ||
pub on_close: Box<dyn Fn()>, | ||
} | ||
|
||
impl QrDialogCallbacks { | ||
pub fn new(on_close: impl Fn() + 'static) -> Self { | ||
Self { | ||
on_close: Box::new(on_close), | ||
} | ||
} | ||
} |
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,50 @@ | ||
use std::rc::Rc; | ||
|
||
use dominator::{clone, DomBuilder, EventOptions}; | ||
use utils::{component::Component, dialog, events}; | ||
use web_sys::ShadowRoot; | ||
|
||
use super::QrDialog; | ||
|
||
impl Component<QrDialog> for Rc<QrDialog> { | ||
fn styles() -> &'static str { | ||
include_str!("./styles.css") | ||
} | ||
|
||
fn dom(&self, dom: DomBuilder<ShadowRoot>) -> DomBuilder<ShadowRoot> { | ||
let state = self; | ||
dom.child(dialog! { | ||
.class("qr-dialog") | ||
.event_with_options(&EventOptions::bubbles(), clone!(state => move |e: events::Click| { | ||
e.stop_propagation(); | ||
(state.callbacks.on_close)(); | ||
})) | ||
.child(html!("div", { | ||
.class("body") | ||
.event_with_options(&EventOptions::bubbles(), |e: events::Click| { | ||
e.stop_propagation(); | ||
}) | ||
.child(html!("fa-button", { | ||
.class("close") | ||
.prop("icon", "fa-regular fa-xmark") | ||
.event(clone!(state => move |_: events::Click| { | ||
(state.callbacks.on_close)(); | ||
})) | ||
})) | ||
.child(html!("img", { | ||
.style("max-height", "5cm") | ||
.style("max-width", "5cm") | ||
.prop("src", &state.url) | ||
})) | ||
.child(html!("fa-button", { | ||
.class("download") | ||
.prop("icon", "fa-solid fa-square-down") | ||
.prop("title", "Download") | ||
.event(clone!(state => move |_: events::Click| { | ||
state.download(); | ||
})) | ||
})) | ||
})) | ||
}) | ||
} | ||
} |
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,8 @@ | ||
mod actions; | ||
mod callbacks; | ||
mod dom; | ||
mod state; | ||
|
||
pub use callbacks::*; | ||
pub use dom::*; | ||
pub use state::*; |
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,45 @@ | ||
use std::rc::Rc; | ||
|
||
use qrcode_generator::QrCodeEcc; | ||
use utils::{routes::Route, unwrap::UnwrapJiExt}; | ||
use wasm_bindgen::JsValue; | ||
|
||
use super::QrDialogCallbacks; | ||
|
||
pub struct QrDialog { | ||
pub url: String, | ||
pub file_label: String, | ||
pub callbacks: QrDialogCallbacks, | ||
} | ||
|
||
impl QrDialog { | ||
pub fn new(route: Route, file_label: String, callbacks: QrDialogCallbacks) -> Rc<Self> { | ||
let url = qr_core_file_from_route(route); | ||
Rc::new(Self { | ||
url, | ||
file_label, | ||
callbacks, | ||
}) | ||
} | ||
} | ||
|
||
fn file_to_object_url(filetype: &str, data: &str) -> String { | ||
let data = JsValue::from_str(data); | ||
let blob = web_sys::Blob::new_with_str_sequence_and_options( | ||
&js_sys::Array::from_iter(vec![data]), | ||
web_sys::BlobPropertyBag::new().type_(filetype), | ||
) | ||
.unwrap_ji(); | ||
let url = web_sys::Url::create_object_url_with_blob(&blob).unwrap_ji(); | ||
url | ||
} | ||
|
||
pub fn qr_core_file_from_route(route: Route) -> String { | ||
let result: String = | ||
qrcode_generator::to_svg_to_string(route.to_string(), QrCodeEcc::High, 200, None::<&str>) | ||
.unwrap(); | ||
|
||
let url = file_to_object_url("image/svg+xml", &result); | ||
|
||
url | ||
} |
Oops, something went wrong.