From 649d33ca68889669d62817765bf8d6a3441b6949 Mon Sep 17 00:00:00 2001 From: Colin Reeder Date: Sat, 8 Aug 2020 16:32:21 -0600 Subject: Use SVG icons instead of emoji --- Cargo.lock | 24 ++++++++++++++++++++ Cargo.toml | 4 ++++ icons/Cargo.toml | 10 ++++++++ icons/res/notifications-some.svg | 7 ++++++ icons/res/notifications.svg | 5 ++++ icons/res/person.svg | 4 ++++ icons/src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++++ res/main.css | 10 ++++---- src/components/mod.rs | 23 ++++++++++++++++--- src/routes/static.rs | 9 ++++++++ 10 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 icons/Cargo.toml create mode 100644 icons/res/notifications-some.svg create mode 100644 icons/res/notifications.svg create mode 100644 icons/res/person.svg create mode 100644 icons/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1ef69b7..0f7d4c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,6 +294,7 @@ dependencies = [ "fluent-langneg", "futures-util", "ginger", + "hitide_icons", "http", "hyper", "hyper-tls", @@ -309,6 +310,13 @@ dependencies = [ "urlencoding", ] +[[package]] +name = "hitide_icons" +version = "0.1.0" +dependencies = [ + "phf", +] + [[package]] name = "html5ever" version = "0.25.1" @@ -662,7 +670,9 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" dependencies = [ + "phf_macros", "phf_shared", + "proc-macro-hack", ] [[package]] @@ -685,6 +695,20 @@ dependencies = [ "rand", ] +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "phf_shared" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index e159cfc..dbd0dfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[workspace] +members = ["icons"] + [package] name = "hitide" version = "0.5.0-pre" @@ -28,3 +31,4 @@ fluent = "0.12.0" lazy_static = "1.4.0" unic-langid = { version = "0.9.0", features = ["macros"] } futures-util = "0.3.5" +hitide_icons = { path = "./icons" } diff --git a/icons/Cargo.toml b/icons/Cargo.toml new file mode 100644 index 0000000..48bb80b --- /dev/null +++ b/icons/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "hitide_icons" +version = "0.1.0" +authors = ["Colin Reeder "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +phf = { version = "0.8.0", features = ["macros"] } diff --git a/icons/res/notifications-some.svg b/icons/res/notifications-some.svg new file mode 100644 index 0000000..5eef1fa --- /dev/null +++ b/icons/res/notifications-some.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/icons/res/notifications.svg b/icons/res/notifications.svg new file mode 100644 index 0000000..45a55d1 --- /dev/null +++ b/icons/res/notifications.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/icons/res/person.svg b/icons/res/person.svg new file mode 100644 index 0000000..78d7385 --- /dev/null +++ b/icons/res/person.svg @@ -0,0 +1,4 @@ + + + + diff --git a/icons/src/lib.rs b/icons/src/lib.rs new file mode 100644 index 0000000..355e674 --- /dev/null +++ b/icons/src/lib.rs @@ -0,0 +1,49 @@ +pub struct Icon { + pub path: &'static str, + pub content: &'static str, +} + +macro_rules! icons_consts { + ($i:ident => $p:expr) => { + pub const $i: Icon = Icon { + path: $p, + content: include_str!(concat!("../res/", $p)), + }; + }; + ($i1:ident => $p1:expr, $($i2:ident => $p2:expr),+) => { + icons_consts! { $i1 => $p1 } + icons_consts! { $($i2 => $p2),+ } + } +} + +macro_rules! icons_map { + ($($i:ident => $p:expr),+) => { + pub const ICONS_MAP: phf::Map<&'static str, &'static Icon> = phf::phf_map! { + $($p => &icons::$i),+ + }; + } +} + +macro_rules! icons { + ($($i:ident => $p:expr),+) => { + pub mod icons { + use super::Icon; + + icons_consts! { + $($i => $p),+ + } + } + + icons_map! { + $($i => $p),+ + } + } +} + +icons! { + NOTIFICATIONS => "notifications.svg", + NOTIFICATIONS_SOME => "notifications-some.svg", + PERSON => "person.svg" +} + +pub use icons::*; diff --git a/res/main.css b/res/main.css index 2ff6a0c..1ce5be8 100644 --- a/res/main.css +++ b/res/main.css @@ -53,10 +53,6 @@ body { margin-bottom: 0; } -.notification-indicator.unread { - color: #FF8F00; -} - .notification-item.unread { border-left: 5px solid #FDD835; padding-left: 5px; @@ -75,6 +71,12 @@ body { border: 1px dashed black; } +.icon { + height: 1.2em; + display: inline; + vertical-align: text-bottom; +} + @media (max-width: 768px) { .communitySidebar { display: none; /* TODO still show this somewhere */ diff --git a/src/components/mod.rs b/src/components/mod.rs index e3cd604..9527972 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -226,11 +226,18 @@ pub fn HTPage<'a, Children: render::Render>( <> - {"🔔︎"} + { + if login.user.has_unread_notifications { + hitide_icons::NOTIFICATIONS_SOME.img() + } else { + hitide_icons::NOTIFICATIONS.img() + } + } + + + {hitide_icons::PERSON.img()} - {"👤︎"} }) } else { @@ -501,3 +508,13 @@ impl<'a> render::Render for NotificationItem<'a> { write!(writer, "") } } + +trait IconExt { + fn img(&self) -> render::SimpleElement<()>; +} + +impl IconExt for hitide_icons::Icon { + fn img(&self) -> render::SimpleElement<()> { + render::rsx! { } + } +} diff --git a/src/routes/static.rs b/src/routes/static.rs index 60a0084..d319efe 100644 --- a/src/routes/static.rs +++ b/src/routes/static.rs @@ -1,3 +1,4 @@ +use hitide_icons::ICONS_MAP; use std::sync::Arc; const FILE_MAIN_CSS: &[u8] = include_bytes!("../../res/main.css"); @@ -19,6 +20,14 @@ async fn handler_static_get( hyper::header::HeaderValue::from_static("text/css"), ); + Ok(resp) + } else if let Some(icon) = ICONS_MAP.get(params.0.as_str()) { + let mut resp = hyper::Response::new(icon.content.into()); + resp.headers_mut().insert( + hyper::header::CONTENT_TYPE, + hyper::header::HeaderValue::from_static("image/svg+xml"), + ); + Ok(resp) } else { Err(crate::Error::RoutingError(trout::RoutingFailure::NotFound)) -- cgit v1.2.3