Skip to content

Commit

Permalink
fix(emojis): Hide unsupported emojis and add missing food category (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 authored Oct 26, 2023
1 parent 7e0fa46 commit 4320616
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
47 changes: 22 additions & 25 deletions native_extensions/emoji_selector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use common::{
state::{scope_ids::ScopeIds, ui::EmojiDestination, Action, State},
};
use dioxus::prelude::*;
use emojis::Group;
use emojis::{Group, UnicodeVersion};
use extensions::{export_extension, Details, Extension, Location, Meta, Type};
use futures::StreamExt;
use kit::{
Expand Down Expand Up @@ -35,6 +35,11 @@ fn group_to_str(group: emojis::Group) -> String {
}
}

fn is_supported(unicode_version: UnicodeVersion) -> bool {
let (major, minor, _) = std::char::UNICODE_VERSION;
unicode_version.major() <= major as u32 && unicode_version.minor() <= minor as u32
}

#[component(no_case_check)]
fn build_nav(cx: Scope<'_>) -> Element<'_> {
let routes = vec![
Expand Down Expand Up @@ -62,6 +67,14 @@ fn build_nav(cx: Scope<'_>) -> Element<'_> {
loading: None,
..Route::default()
},
Route {
to: "Food & Drink",
name: group_to_str(Group::FoodAndDrink),
icon: Icon::Cake,
with_badge: None,
loading: None,
..Route::default()
},
Route {
to: "Travel & Places",
name: group_to_str(Group::TravelAndPlaces),
Expand All @@ -81,7 +94,7 @@ fn build_nav(cx: Scope<'_>) -> Element<'_> {
Route {
to: "Objects",
name: group_to_str(Group::Objects),
icon: Icon::Cake,
icon: Icon::Clock,
with_badge: None,
loading: None,
..Route::default()
Expand Down Expand Up @@ -133,9 +146,7 @@ fn render_selector<'a>(
nav: Element<'a>,
) -> Element<'a> {
let state = use_shared_state::<State>(cx)?;
#[cfg(not(target_os = "macos"))]
let mouse_over_emoji_selector = use_ref(cx, || false);
#[cfg(not(target_os = "macos"))]
let eval = use_eval(cx);

let focus_script = r#"
Expand Down Expand Up @@ -175,17 +186,11 @@ fn render_selector<'a>(
cx.render(rsx! (
div {
onmouseenter: |_| {
#[cfg(not(target_os = "macos"))]
{
*mouse_over_emoji_selector.write_silent() = true;
}
*mouse_over_emoji_selector.write_silent() = true;
},
onmouseleave: |_| {
#[cfg(not(target_os = "macos"))]
{
*mouse_over_emoji_selector.write_silent() = false;
let _ = eval(focus_script);
}
*mouse_over_emoji_selector.write_silent() = false;
let _ = eval(focus_script);
},
id: "emoji_selector",
aria_label: "emoji-selector",
Expand All @@ -195,17 +200,8 @@ fn render_selector<'a>(
state.write().mutate(Action::SetEmojiDestination(
Some(common::state::ui::EmojiDestination::Chatbar),
));
#[cfg(target_os = "macos")]
{
if !*mouse_over_emoji_button.read() {
state.write().mutate(Action::SetEmojiPickerVisible(false));
}
}
#[cfg(not(target_os = "macos"))]
{
if !*mouse_over_emoji_button.read() && !*mouse_over_emoji_selector.read() {
state.write().mutate(Action::SetEmojiPickerVisible(false));
}
if !*mouse_over_emoji_button.read() && !*mouse_over_emoji_selector.read() {
state.write().mutate(Action::SetEmojiPickerVisible(false));
}
},
div {
Expand All @@ -222,7 +218,7 @@ fn render_selector<'a>(
div {
class: "emojis-container",
aria_label: "emojis-container",
group.emojis().map(|emoji| {
group.emojis().filter(|emoji|is_supported(emoji.unicode_version())).map(|emoji| {
rsx!(
div {
aria_label: emoji.as_str(),
Expand Down Expand Up @@ -274,6 +270,7 @@ fn render_1(cx: Scope, _unused: bool) -> Element {
let state = use_shared_state::<State>(cx)?;
let mouse_over_emoji_button = use_ref(cx, || false);
let visible = state.read().ui.emoji_picker_visible;
log::debug!("vis {}", visible);

use_effect(cx, (), |_| {
to_owned![state];
Expand Down
3 changes: 2 additions & 1 deletion native_extensions/emoji_selector/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

#emoji_selector .emojis-container {
width: calc(100% - var(--gap));
display: inline-flex;
display: grid;
grid-template-columns: repeat(7, 0fr);
flex-wrap: wrap;
margin-bottom: var(--gap);
gap: var(--gap);
Expand Down

0 comments on commit 4320616

Please sign in to comment.