mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 09:34:19 +01:00
route: add Search route and hook up SearchView
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -18,6 +18,7 @@ use crate::{
|
||||
edit_deck::{EditDeckResponse, EditDeckView},
|
||||
note::{PostAction, PostType},
|
||||
profile::EditProfileView,
|
||||
search::SearchView,
|
||||
support::SupportView,
|
||||
RelayView, View,
|
||||
},
|
||||
@@ -387,6 +388,26 @@ fn render_nav_body(
|
||||
SupportView::new(&mut app.support).show(ui);
|
||||
None
|
||||
}
|
||||
|
||||
Route::Search => {
|
||||
let id = ui.id().with(("search", depth, col));
|
||||
let search_buffer = app.view_state.searches.entry(id).or_default();
|
||||
let txn = Transaction::new(ctx.ndb).expect("txn");
|
||||
|
||||
SearchView::new(
|
||||
ctx.ndb,
|
||||
&txn,
|
||||
ctx.note_cache,
|
||||
ctx.img_cache,
|
||||
&ctx.accounts.mutefun(),
|
||||
app.note_options,
|
||||
search_buffer,
|
||||
)
|
||||
.show(ui);
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
Route::NewDeck => {
|
||||
let id = ui.id().with("new-deck");
|
||||
let new_deck_state = app.view_state.id_to_deck_state.entry(id).or_default();
|
||||
|
||||
@@ -25,6 +25,8 @@ pub enum Route {
|
||||
EditProfile(Pubkey),
|
||||
Support,
|
||||
NewDeck,
|
||||
/// Search screen
|
||||
Search,
|
||||
EditDeck(usize),
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ impl Route {
|
||||
Route::Timeline(timeline_kind) => timeline_kind.serialize_tokens(writer),
|
||||
Route::Accounts(routes) => routes.serialize_tokens(writer),
|
||||
Route::AddColumn(routes) => routes.serialize_tokens(writer),
|
||||
Route::Search => writer.write_token("search"),
|
||||
Route::Reply(note_id) => {
|
||||
writer.write_token("reply");
|
||||
writer.write_token(¬e_id.hex());
|
||||
@@ -181,6 +184,12 @@ impl Route {
|
||||
Ok(Route::NewDeck)
|
||||
})
|
||||
},
|
||||
|p| {
|
||||
p.parse_all(|p| {
|
||||
p.parse_token("search")?;
|
||||
Ok(Route::Search)
|
||||
})
|
||||
},
|
||||
],
|
||||
)
|
||||
}
|
||||
@@ -223,6 +232,7 @@ impl Route {
|
||||
Route::NewDeck => ColumnTitle::simple("Add Deck"),
|
||||
Route::EditDeck(_) => ColumnTitle::simple("Edit Deck"),
|
||||
Route::EditProfile(_) => ColumnTitle::simple("Edit Profile"),
|
||||
Route::Search => ColumnTitle::simple("Search"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,6 +354,7 @@ impl fmt::Display for Route {
|
||||
Route::NewDeck => write!(f, "Add Deck"),
|
||||
Route::EditDeck(_) => write!(f, "Edit Deck"),
|
||||
Route::EditProfile(_) => write!(f, "Edit Profile"),
|
||||
Route::Search => write!(f, "Search"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,10 @@ impl TimelineKind {
|
||||
// the parser below as well
|
||||
pub fn serialize_tokens(&self, writer: &mut TokenWriter) {
|
||||
match self {
|
||||
TimelineKind::Search(query) => query.serialize_tokens(writer),
|
||||
TimelineKind::Search(query) => {
|
||||
writer.write_token("search");
|
||||
query.serialize_tokens(writer)
|
||||
}
|
||||
TimelineKind::List(list_kind) => list_kind.serialize_tokens(writer),
|
||||
TimelineKind::Algo(algo_timeline) => algo_timeline.serialize_tokens(writer),
|
||||
TimelineKind::Notifications(pk) => {
|
||||
@@ -394,6 +397,11 @@ impl TimelineKind {
|
||||
p.parse_token("hashtag")?;
|
||||
Ok(TimelineKind::Hashtag(p.pull_token()?.to_string()))
|
||||
},
|
||||
|p| {
|
||||
p.parse_token("search")?;
|
||||
let search_query = SearchQuery::parse_from_tokens(p)?;
|
||||
Ok(TimelineKind::Search(search_query))
|
||||
},
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -461,6 +461,9 @@ impl<'a> NavTitle<'a> {
|
||||
Route::EditProfile(pubkey) => {
|
||||
self.show_profile(ui, pubkey, pfp_size);
|
||||
}
|
||||
Route::Search => {
|
||||
ui.add(ui::side_panel::search_button());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,6 +325,11 @@ impl<'a> DesktopSidePanel<'a> {
|
||||
SidePanelAction::Search => {
|
||||
// TODO
|
||||
info!("Clicked search button");
|
||||
if router.top() == &Route::Search {
|
||||
router.go_back();
|
||||
} else {
|
||||
router.route_to(Route::Search);
|
||||
}
|
||||
}
|
||||
SidePanelAction::ExpandSidePanel => {
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user