summaryrefslogtreecommitdiff
path: root/src/view/input_objects/utility.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2020-11-24 21:58:51 +0100
committerjelemux <jeremias.weber@protonmail.com>2020-11-24 21:58:51 +0100
commit5a03734b6767fed04c0913384584d8f59dc597ea (patch)
tree62ef0a0afc0ab56dd36da1a662db768fd8c22eda /src/view/input_objects/utility.rs
parent49588f22f7d20193f899226107c9e323a82c6951 (diff)
downloadwasm-card-5a03734b6767fed04c0913384584d8f59dc597ea.tar.gz
wasm-card-5a03734b6767fed04c0913384584d8f59dc597ea.tar.bz2
add traits for viewmodel and view
Diffstat (limited to 'src/view/input_objects/utility.rs')
-rw-r--r--src/view/input_objects/utility.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/view/input_objects/utility.rs b/src/view/input_objects/utility.rs
new file mode 100644
index 0000000..a296c1e
--- /dev/null
+++ b/src/view/input_objects/utility.rs
@@ -0,0 +1,39 @@
+#[derive(Clone)]
+pub struct Download {
+ pub file_name: String,
+ pub content: String,
+ pub mime_type: MimeType,
+}
+
+impl Download {
+ pub fn as_data_link(&self) -> String {
+ let data = base64::encode(&*self.content);
+ let uri_component: String = js_sys::encode_uri_component(&data).into();
+
+ format!("data:{};base64,{}", self.mime_type.as_text(), uri_component)
+ }
+}
+
+#[derive(Clone, Copy)]
+pub enum MimeType {
+ PDF,
+ VCard,
+ SVG,
+}
+
+impl MimeType {
+ pub fn as_text(&self) -> &str {
+ match self {
+ MimeType::PDF => "application/pdf",
+ MimeType::VCard => "text/vcard",
+ MimeType::SVG => "image/svg+xml",
+ }
+ }
+}
+
+#[derive(Clone, Copy)]
+pub enum DownloadOption {
+ PDF,
+ VCard,
+ QrCode,
+} \ No newline at end of file