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