Skip to content

Commit

Permalink
fix: 🐛 manually unsubscribe when drop, related to Ribir #507
Browse files Browse the repository at this point in the history
  • Loading branch information
wjian23 committed Jan 29, 2024
1 parent b0c6883 commit c4e6ec9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gui/src/widgets/home/chat/msg_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ pub fn w_msg_list(

scroll_to_bottom();

watch!((
// TODO: use `guard` to unsubscribe when widget is disposed.
// Related to Ribir #507, should be auto unsubscribe_when_dropped when unvalid
let mut guard = Some(watch!((
$channel.msgs().len(),
$channel.last_msg().map_or(0, |msg| msg.cont_size())
))
.distinct_until_changed()
.subscribe(move |_| {
scroll_to_bottom();
});
})
.unsubscribe_when_dropped());

@ConstrainedBox {
clamp: BoxClamp::EXPAND_BOTH,
on_disposed: move |_| {
guard.take();
},
@$scrollable_container {
@$content_constrained_box {
@Column {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/widgets/home/sidebar/channel_thumbnail_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn w_channel_thumbnail_list(
@InteractiveList {
active: pipe! {
let channels = $channel_mgr.channel_ids();
let last_idx = (channels.len() - 1).min(0);
let last_idx = channels.len().max(1) - 1;
$channel_mgr.cur_channel_id().and_then(|id| {
channels.iter().position(|ch| ch == id).map(|idx| last_idx - idx)
}).unwrap_or(last_idx)
Expand Down

0 comments on commit c4e6ec9

Please sign in to comment.