improve sidebar search results display
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use std::cmp::Reverse;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -602,18 +603,25 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let chat = ChatRegistry::global(cx);
|
let chat = ChatRegistry::global(cx);
|
||||||
let hits = matches.into_iter().filter_map(|matched| {
|
let mut hits = matches
|
||||||
let room = chat.read(cx).room(&matched.room, cx)?.upgrade()?;
|
.into_iter()
|
||||||
|
.filter_map(|matched| {
|
||||||
|
let room = chat.read(cx).room(&matched.room, cx)?.upgrade()?;
|
||||||
|
|
||||||
Some(MessageHit {
|
Some(MessageHit {
|
||||||
room,
|
room,
|
||||||
author: matched.author,
|
author: matched.author,
|
||||||
content: matched.content,
|
content: matched.content,
|
||||||
created_at: matched.created_at,
|
created_at: matched.created_at,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.results.extend(hits.map(SearchResult::Message));
|
// Newest matching message first
|
||||||
|
hits.sort_by_key(|hit| Reverse(hit.created_at));
|
||||||
|
|
||||||
|
self.results
|
||||||
|
.extend(hits.into_iter().map(SearchResult::Message));
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,27 +842,29 @@ impl Sidebar {
|
|||||||
|
|
||||||
let mut rows = Vec::new();
|
let mut rows = Vec::new();
|
||||||
|
|
||||||
if !rooms.is_empty() {
|
rows.push(SidebarRow::Heading("Groups"));
|
||||||
rows.push(SidebarRow::Heading("Chats"));
|
if groups.is_empty() {
|
||||||
rows.extend(rooms.into_iter().map(|room| SidebarRow::Room { room }));
|
rows.push(SidebarRow::Empty("No groups found"));
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if !groups.is_empty() {
|
|
||||||
rows.push(SidebarRow::Heading("Groups"));
|
|
||||||
rows.extend(groups.into_iter().map(|group| SidebarRow::Group { group }));
|
rows.extend(groups.into_iter().map(|group| SidebarRow::Group { group }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !messages.is_empty() {
|
rows.push(SidebarRow::Heading("Rooms"));
|
||||||
rows.push(SidebarRow::Heading("Messages"));
|
if rooms.is_empty() {
|
||||||
rows.extend(messages.into_iter().map(|hit| SidebarRow::Message { hit }));
|
rows.push(SidebarRow::Empty("No rooms found"));
|
||||||
|
} else {
|
||||||
|
rows.extend(rooms.into_iter().map(|room| SidebarRow::Room { room }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows.is_empty() {
|
rows.push(SidebarRow::Heading("Messages"));
|
||||||
|
if messages.is_empty() {
|
||||||
rows.push(SidebarRow::Empty(if self.finding {
|
rows.push(SidebarRow::Empty(if self.finding {
|
||||||
"Searching..."
|
"Searching..."
|
||||||
} else {
|
} else {
|
||||||
"No results"
|
"No messages found"
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
rows.extend(messages.into_iter().map(|hit| SidebarRow::Message { hit }));
|
||||||
}
|
}
|
||||||
|
|
||||||
rows
|
rows
|
||||||
@@ -1158,15 +1168,16 @@ impl Sidebar {
|
|||||||
}))
|
}))
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
SidebarRow::Heading(label) => div()
|
SidebarRow::Heading(label) => {
|
||||||
.px_1p5()
|
let label = *label;
|
||||||
.pt_2()
|
|
||||||
.pb_1()
|
Nav::new(label)
|
||||||
.text_xs()
|
.label(label)
|
||||||
.font_semibold()
|
.text_xs()
|
||||||
.text_color(cx.theme().text_placeholder)
|
.font_semibold()
|
||||||
.child(*label)
|
.text_color(cx.theme().text_placeholder)
|
||||||
.into_any_element(),
|
.into_any_element()
|
||||||
|
}
|
||||||
SidebarRow::Empty(text) => h_flex()
|
SidebarRow::Empty(text) => h_flex()
|
||||||
.h_10()
|
.h_10()
|
||||||
.w_full()
|
.w_full()
|
||||||
|
|||||||
Reference in New Issue
Block a user