state.rs (1765B)
1 use crate::timeline::TimelineTab; 2 use notedeck::debouncer::Debouncer; 3 use std::time::Duration; 4 5 use super::SearchType; 6 7 #[derive(Debug, Eq, PartialEq)] 8 pub enum SearchState { 9 Typing(TypingType), 10 PerformSearch(SearchType), 11 Searched, 12 Navigating, 13 New, 14 } 15 16 #[derive(Debug, Eq, PartialEq)] 17 pub enum TypingType { 18 Mention(String), 19 AutoSearch, 20 } 21 22 #[derive(Debug, Eq, PartialEq, Clone)] 23 pub enum FocusState { 24 /// Get ready to focus 25 Navigating, 26 27 /// We should request focus when we stop navigating 28 ShouldRequestFocus, 29 30 /// We already focused, we don't need to do that again 31 RequestedFocus, 32 } 33 34 /// Search query state that exists between frames 35 #[derive(Debug)] 36 pub struct SearchQueryState { 37 /// This holds our search query while we're updating it 38 pub string: String, 39 40 /// When the debouncer timer elapses, we execute the search and mark 41 /// our state as searchd. This will make sure we don't try to search 42 /// again next frames 43 pub state: SearchState, 44 45 /// A bit of context to know if we're navigating to the view. We 46 /// can use this to know when to request focus on the textedit 47 pub focus_state: FocusState, 48 49 /// When was the input updated? We use this to debounce searches 50 pub debouncer: Debouncer, 51 52 /// The search results 53 pub notes: TimelineTab, 54 } 55 56 impl Default for SearchQueryState { 57 fn default() -> Self { 58 SearchQueryState::new() 59 } 60 } 61 62 impl SearchQueryState { 63 pub fn new() -> Self { 64 Self { 65 string: "".to_string(), 66 state: SearchState::New, 67 notes: TimelineTab::default(), 68 focus_state: FocusState::Navigating, 69 debouncer: Debouncer::new(Duration::from_millis(200)), 70 } 71 } 72 }