Skip to content

Commit e965faa

Browse files
committed
feat: filter contests in dpns screens
1 parent afb2706 commit e965faa

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/ui/dpns/dpns_contested_names_screen.rs

+57-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub struct DPNSScreen {
120120
/// Sorting
121121
sort_column: SortColumn,
122122
sort_order: SortOrder,
123+
active_filter_term: String,
124+
past_filter_term: String,
123125

124126
/// Which sub-screen is active: Active contests, Past, Owned, or Scheduled
125127
pub dpns_subscreen: DPNSSubscreen,
@@ -188,6 +190,8 @@ impl DPNSScreen {
188190
message: None,
189191
sort_column: SortColumn::ContestedName,
190192
sort_order: SortOrder::Ascending,
193+
active_filter_term: String::new(),
194+
past_filter_term: String::new(),
191195
scheduled_vote_cast_in_progress: false,
192196
pending_backend_task: None,
193197
dpns_subscreen,
@@ -339,9 +343,31 @@ impl DPNSScreen {
339343

340344
/// Show the Active Contests table
341345
fn render_table_active_contests(&mut self, ui: &mut Ui) {
346+
ui.horizontal(|ui| {
347+
ui.label("Filter names:");
348+
ui.text_edit_singleline(&mut self.active_filter_term);
349+
});
350+
342351
let contested_names = {
343352
let guard = self.contested_names.lock().unwrap();
344353
let mut cn = guard.clone();
354+
if !self.active_filter_term.is_empty() {
355+
let mut filter_lc = self.active_filter_term.to_lowercase();
356+
// Convert o and O to 0 and l to 1 in filter_lc
357+
filter_lc = filter_lc
358+
.chars()
359+
.map(|c| match c {
360+
'o' | 'O' => '0',
361+
'l' => '1',
362+
_ => c,
363+
})
364+
.collect();
365+
cn.retain(|c| {
366+
c.normalized_contested_name
367+
.to_lowercase()
368+
.contains(&filter_lc)
369+
});
370+
}
345371
self.sort_contested_names(&mut cn);
346372
cn
347373
};
@@ -667,10 +693,34 @@ impl DPNSScreen {
667693

668694
/// Show a Past Contests table
669695
fn render_table_past_contests(&mut self, ui: &mut Ui) {
696+
ui.horizontal(|ui| {
697+
ui.label("Filter names:");
698+
ui.text_edit_singleline(&mut self.past_filter_term);
699+
});
700+
670701
let contested_names = {
671702
let guard = self.contested_names.lock().unwrap();
672703
let mut cn = guard.clone();
673704
cn.retain(|c| c.awarded_to.is_some() || c.state == ContestState::Locked);
705+
// 1) Filter by `active_filter_term`
706+
if !self.past_filter_term.is_empty() {
707+
let mut filter_lc = self.past_filter_term.to_lowercase();
708+
// Convert o and O to 0 and l to 1 in filter_lc
709+
filter_lc = filter_lc
710+
.chars()
711+
.map(|c| match c {
712+
'o' | 'O' => '0',
713+
'l' => '1',
714+
_ => c,
715+
})
716+
.collect();
717+
718+
cn.retain(|c| {
719+
c.normalized_contested_name
720+
.to_lowercase()
721+
.contains(&filter_lc)
722+
});
723+
}
674724
self.sort_contested_names(&mut cn);
675725
cn
676726
};
@@ -784,7 +834,13 @@ impl DPNSScreen {
784834
ui.label("Active");
785835
}
786836
ContestState::WonBy(identifier) => {
787-
ui.label(identifier.to_string(Encoding::Base58));
837+
ui.add(
838+
egui::Label::new(
839+
identifier.to_string(Encoding::Base58),
840+
)
841+
.sense(egui::Sense::hover())
842+
.truncate(),
843+
);
788844
}
789845
ContestState::Locked => {
790846
ui.label("Locked");

0 commit comments

Comments
 (0)