rename SearchResultsView => MentionPickerView
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -11,19 +11,21 @@ use notedeck_ui::{
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
pub struct SearchResultsView<'a> {
|
||||
/// Displays user profiles for the user to pick from.
|
||||
/// Useful for manually typing a username and selecting the profile desired
|
||||
pub struct MentionPickerView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
txn: &'a Transaction,
|
||||
img_cache: &'a mut Images,
|
||||
results: &'a Vec<&'a [u8; 32]>,
|
||||
}
|
||||
|
||||
pub enum SearchResultsResponse {
|
||||
pub enum MentionPickerResponse {
|
||||
SelectResult(Option<usize>),
|
||||
DeleteMention,
|
||||
}
|
||||
|
||||
impl<'a> SearchResultsView<'a> {
|
||||
impl<'a> MentionPickerView<'a> {
|
||||
pub fn new(
|
||||
img_cache: &'a mut Images,
|
||||
ndb: &'a Ndb,
|
||||
@@ -38,8 +40,8 @@ impl<'a> SearchResultsView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut egui::Ui, width: f32) -> SearchResultsResponse {
|
||||
let mut search_results_selection = None;
|
||||
fn show(&mut self, ui: &mut egui::Ui, width: f32) -> MentionPickerResponse {
|
||||
let mut selection = None;
|
||||
ui.vertical(|ui| {
|
||||
for (i, res) in self.results.iter().enumerate() {
|
||||
let profile = match self.ndb.get_profile_by_pubkey(self.txn, res) {
|
||||
@@ -54,16 +56,16 @@ impl<'a> SearchResultsView<'a> {
|
||||
.add(user_result(&profile, self.img_cache, i, width))
|
||||
.clicked()
|
||||
{
|
||||
search_results_selection = Some(i)
|
||||
selection = Some(i)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
SearchResultsResponse::SelectResult(search_results_selection)
|
||||
MentionPickerResponse::SelectResult(selection)
|
||||
}
|
||||
|
||||
pub fn show_in_rect(&mut self, rect: egui::Rect, ui: &mut egui::Ui) -> SearchResultsResponse {
|
||||
let widget_id = ui.id().with("search_results");
|
||||
pub fn show_in_rect(&mut self, rect: egui::Rect, ui: &mut egui::Ui) -> MentionPickerResponse {
|
||||
let widget_id = ui.id().with("mention_results");
|
||||
let area_resp = egui::Area::new(widget_id)
|
||||
.order(egui::Order::Foreground)
|
||||
.fixed_pos(rect.left_top())
|
||||
@@ -104,7 +106,7 @@ impl<'a> SearchResultsView<'a> {
|
||||
ui.advance_cursor_after_rect(rect);
|
||||
|
||||
if close_button_resp {
|
||||
SearchResultsResponse::DeleteMention
|
||||
MentionPickerResponse::DeleteMention
|
||||
} else {
|
||||
scroll_resp.inner
|
||||
}
|
||||
@@ -5,13 +5,13 @@ pub mod column;
|
||||
pub mod configure_deck;
|
||||
pub mod edit_deck;
|
||||
pub mod images;
|
||||
pub mod mentions_picker;
|
||||
pub mod note;
|
||||
pub mod post;
|
||||
pub mod preview;
|
||||
pub mod profile;
|
||||
pub mod relay;
|
||||
pub mod search;
|
||||
pub mod search_results;
|
||||
pub mod settings;
|
||||
pub mod side_panel;
|
||||
pub mod support;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::draft::{Draft, Drafts, MentionHint};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use crate::media_upload::{nostrbuild_nip96_upload, MediaPath};
|
||||
use crate::post::{downcast_post_buffer, MentionType, NewPost};
|
||||
use crate::ui::search_results::SearchResultsView;
|
||||
use crate::ui::mentions_picker::MentionPickerView;
|
||||
use crate::ui::{self, Preview, PreviewConfig};
|
||||
use crate::Result;
|
||||
|
||||
@@ -273,7 +273,7 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
return;
|
||||
};
|
||||
|
||||
let resp = SearchResultsView::new(
|
||||
let resp = MentionPickerView::new(
|
||||
self.note_context.img_cache,
|
||||
self.note_context.ndb,
|
||||
txn,
|
||||
@@ -282,7 +282,7 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
.show_in_rect(hint_rect, ui);
|
||||
|
||||
match resp {
|
||||
ui::search_results::SearchResultsResponse::SelectResult(selection) => {
|
||||
ui::mentions_picker::MentionPickerResponse::SelectResult(selection) => {
|
||||
if let Some(hint_index) = selection {
|
||||
if let Some(pk) = res.get(hint_index) {
|
||||
let record = self.note_context.ndb.get_profile_by_pubkey(txn, pk);
|
||||
@@ -297,7 +297,7 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
}
|
||||
}
|
||||
|
||||
ui::search_results::SearchResultsResponse::DeleteMention => {
|
||||
ui::mentions_picker::MentionPickerResponse::DeleteMention => {
|
||||
self.draft.buffer.delete_mention(mention.index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ mod state;
|
||||
|
||||
pub use state::{FocusState, SearchQueryState, SearchState};
|
||||
|
||||
use super::search_results::{SearchResultsResponse, SearchResultsView};
|
||||
use super::mentions_picker::{MentionPickerResponse, MentionPickerView};
|
||||
|
||||
pub struct SearchView<'a, 'd> {
|
||||
query: &'a mut SearchQueryState,
|
||||
@@ -76,7 +76,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
|
||||
break 's;
|
||||
};
|
||||
|
||||
let search_res = SearchResultsView::new(
|
||||
let search_res = MentionPickerView::new(
|
||||
self.note_context.img_cache,
|
||||
self.note_context.ndb,
|
||||
self.txn,
|
||||
@@ -85,7 +85,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
|
||||
.show_in_rect(ui.available_rect_before_wrap(), ui);
|
||||
|
||||
search_action = match search_res {
|
||||
SearchResultsResponse::SelectResult(Some(index)) => {
|
||||
MentionPickerResponse::SelectResult(Some(index)) => {
|
||||
let Some(pk_bytes) = results.get(index) else {
|
||||
break 's;
|
||||
};
|
||||
@@ -103,8 +103,8 @@ impl<'a, 'd> SearchView<'a, 'd> {
|
||||
new_search_text: format!("@{username}"),
|
||||
})
|
||||
}
|
||||
SearchResultsResponse::DeleteMention => Some(SearchAction::CloseMention),
|
||||
SearchResultsResponse::SelectResult(None) => break 's,
|
||||
MentionPickerResponse::DeleteMention => Some(SearchAction::CloseMention),
|
||||
MentionPickerResponse::SelectResult(None) => break 's,
|
||||
};
|
||||
}
|
||||
SearchState::PerformSearch(search_type) => {
|
||||
|
||||
Reference in New Issue
Block a user