Skip to content

Commit

Permalink
refactor: list items
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasGrandl committed Mar 6, 2024
1 parent 9e4da4e commit b99b6f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/commands/bitwarden/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use std::{
collections::HashMap,
path::PathBuf,
sync::{OnceLock},
time::Duration,
};
use std::{collections::HashMap, path::PathBuf, sync::OnceLock, time::Duration};

use async_std::{
channel,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/matrix/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub(super) struct Message {
}

impl Message {
fn render(&mut self, selected: bool, cx: &WindowContext) -> Div {
fn render(&mut self, selected: bool, cx: &WindowContext) -> AnyElement {
let theme = cx.global::<Theme>();
let show_avatar = !self.me && self.first;
let show_reactions = !self.reactions.inner.is_empty();
Expand Down Expand Up @@ -267,6 +267,7 @@ impl Message {
.child(self.reactions.clone()),
),
)
.into_any_element()
}
fn actions(&self, _client: &Client, _cx: &mut AsyncWindowContext) -> Vec<Action> {
let mut actions = vec![Action::new(
Expand Down
7 changes: 4 additions & 3 deletions src/components/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub struct Item {
pub weight: Option<u16>,
selected: bool,
pub meta: Box<dyn Meta>,
render: Option<fn(Self, bool, &WindowContext) -> Div>,
render: Option<fn(&Self, bool, &WindowContext) -> AnyElement>,
}

pub trait Meta: std::any::Any {
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Item {
actions: Vec<Action>,
weight: Option<u16>,
meta: Option<Box<dyn Meta>>,
render: Option<fn(Self, bool, &WindowContext) -> Div>,
render: Option<fn(&Self, bool, &WindowContext) -> AnyElement>,
) -> Self {
let mut s = DefaultHasher::new();
t.hash(&mut s);
Expand All @@ -223,7 +223,7 @@ impl Item {
impl RenderOnce for Item {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
if let Some(render) = &self.render {
render(self.clone(), self.selected, cx)
render(&self, self.selected, cx)
} else {
let theme = cx.global::<Theme>();
let mut bg_hover = theme.mantle;
Expand All @@ -237,6 +237,7 @@ impl RenderOnce for Item {
.border_1()
.rounded_xl()
.child(self.component)
.into_any_element()
}
}
}
Expand Down

0 comments on commit b99b6f9

Please sign in to comment.