Skip to content

Commit

Permalink
feat(favorites): show profile picture in favorites (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwoodbury authored Mar 21, 2023
1 parent 4572a19 commit e0f1559
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 80 deletions.
24 changes: 12 additions & 12 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
unstable_features = true
force_multiline_blocks = true
imports_layout = "HorizontalVertical"
imports_granularity = "One"
indent_style = "Visual"
use_field_init_shorthand = true
use_try_shorthand = true
fn_single_line = true
normalize_comments = true
reorder_impl_items = true
group_imports = "StdExternalCrate"
struct_field_align_threshold = 30
# unstable_features = true
# force_multiline_blocks = true
# imports_layout = "HorizontalVertical"
# imports_granularity = "One"
# indent_style = "Visual"
# use_field_init_shorthand = true
# use_try_shorthand = true
# fn_single_line = true
# normalize_comments = true
# reorder_impl_items = true
# group_imports = "StdExternalCrate"
# struct_field_align_threshold = 30
106 changes: 40 additions & 66 deletions kit/src/components/user_image_group/mod.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
use crate::{components::user_image::UserImage, elements::label::Label, User};
use dioxus::{
core::Event,
events::{MouseData, MouseEvent},
prelude::*,
};
use dioxus::{events::MouseEvent, prelude::*};

#[derive(Props)]
pub struct Props<'a> {
#[props(optional)]
loading: Option<bool>,
participants: Vec<User>,
#[props(optional)]
onpress: Option<EventHandler<'a, MouseEvent>>,
#[props(optional)]
typing: Option<bool>,
#[props(optional)]
with_username: Option<String>,
}

pub fn emit(cx: &Scope<Props>, e: Event<MouseData>) {
match &cx.props.onpress {
Some(f) => f.call(e),
None => {}
}
}

#[allow(non_snake_case)]
pub fn UserImageGroup<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
let pressable = cx.props.onpress.is_some();
let is_pressable = cx.props.onpress.is_some();
// this is "participants.len() - 3" because:
// UserImageGroup is supposed to render at most 3 participants. the rest are supposed to be added as a "+n" later
// the values for count has 1 subtracted (self counts as 1)
let count = cx.props.participants.len() as i64 - 3;
let group = cx.props.participants.len() > 1;
let username = cx.props.with_username.clone().unwrap_or_default();
let additional_participants = cx.props.participants.len() as i64 - 3;
let is_group = cx.props.participants.len() > 1;

let loading = cx.props.loading.unwrap_or_default() || cx.props.participants.is_empty();

Expand All @@ -47,59 +32,48 @@ pub fn UserImageGroup<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
}
)
} else {
let single_user = &cx.props.participants[0];
rsx! (
div {
class: "user-image-group",
div {
class: {
format_args!("user-image-group-wrap {} {}", if pressable { "pressable" } else { "" }, if group { "group" } else { "" })
format_args!("user-image-group-wrap {} {}", if is_pressable { "pressable" } else { "" }, if is_group { "group" } else { "" })
},
onclick: move |e| emit(&cx, e),
if group {
rsx!(
cx.props.participants.iter().map(|user| {
rsx!(
UserImage {
platform: user.platform,
status: user.status,
image: user.photo.clone(),
onpress: move |e| emit(&cx, e),
}
)
}),
div {
class: "plus-some",
(count > 0).then(|| rsx!(
if cx.props.typing.unwrap_or_default() {
rsx!(
div { class: "dot dot-1" },
div { class: "dot dot-2" },
div { class: "dot dot-3" }
)
} else {
rsx! (
p {
"+{count}"
}
)
}
))
}
)
} else {
rsx!(
UserImage {
platform: single_user.platform,
status: single_user.status,
onpress: move |e| emit(&cx, e),
}
)
}
}
(cx.props.with_username.is_some()).then(|| rsx!(
onclick: move |e| { let _ = cx.props.onpress.as_ref().map(|f| f.call(e)); },
rsx!(
cx.props.participants.iter().map(|user| {
rsx!(
UserImage {
platform: user.platform,
status: user.status,
image: user.photo.clone(),
onpress: move |e| { let _ = cx.props.onpress.as_ref().map(|f| f.call(e)); },
}
)
}),
div {
class: "plus-some",
(additional_participants > 0).then(|| rsx!(
if cx.props.typing.unwrap_or_default() {
rsx!(
div { class: "dot dot-1" },
div { class: "dot dot-2" },
div { class: "dot dot-3" }
)
} else {
rsx! (
p {
"+{additional_participants}"
}
)
}
))
}
)
},
cx.props.with_username.as_ref().map(|username| rsx!(
Label {
text: username
text: username.to_string()
}
))
}
Expand Down
4 changes: 2 additions & 2 deletions native_extensions/emoji_selector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ impl EmojiSelector {
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;
*mouse_over_emoji_selector.write_silent() = false;
eval(focus_script.to_string());
}
},
Expand Down

0 comments on commit e0f1559

Please sign in to comment.