feat: new search experience #58

Merged
reya merged 7 commits from new-search into master 2026-10-06 03:00:23 +00:00
Showing only changes of commit 453a462fc0 - Show all commits
+31 -20
View File
@@ -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,7 +603,9 @@ impl Sidebar {
} }
let chat = ChatRegistry::global(cx); let chat = ChatRegistry::global(cx);
let hits = matches.into_iter().filter_map(|matched| { let mut hits = matches
.into_iter()
.filter_map(|matched| {
let room = chat.read(cx).room(&matched.room, cx)?.upgrade()?; let room = chat.read(cx).room(&matched.room, cx)?.upgrade()?;
Some(MessageHit { Some(MessageHit {
@@ -611,9 +614,14 @@ impl Sidebar {
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("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 })); 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)
.label(label)
.text_xs() .text_xs()
.font_semibold() .font_semibold()
.text_color(cx.theme().text_placeholder) .text_color(cx.theme().text_placeholder)
.child(*label) .into_any_element()
.into_any_element(), }
SidebarRow::Empty(text) => h_flex() SidebarRow::Empty(text) => h_flex()
.h_10() .h_10()
.w_full() .w_full()