-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod position; | ||
pub mod states; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
pub enum InputMode { | ||
Normal, | ||
Editing, | ||
} | ||
|
||
pub struct Query { | ||
pub query: String, | ||
pub error_message: Option<String>, | ||
} | ||
|
||
pub struct AppSearchState { | ||
pub current_search_query: String, | ||
pub cursor_position: usize, | ||
pub input_mode: InputMode, | ||
pub is_invalid_search: bool, | ||
pub is_blank_search: bool, | ||
pub query: Option<Query>, | ||
} | ||
|
||
impl Default for AppSearchState { | ||
fn default() -> Self { | ||
AppSearchState { | ||
current_search_query: "".to_owned(), | ||
cursor_position: 0, | ||
input_mode: InputMode::Normal, | ||
is_invalid_search: false, | ||
is_blank_search: false, | ||
query: None, | ||
} | ||
} | ||
} | ||
|
||
impl AppSearchState { | ||
/// Resets the [`AppSearchState`] to its default state, albeit still enabled. | ||
pub fn reset(&mut self) { | ||
*self = AppSearchState { | ||
..AppSearchState::default() | ||
} | ||
} | ||
|
||
/// Returns whether the [`AppSearchState`] has an invalid or blank search. | ||
pub fn is_invalid_or_blank_search(&self) -> bool { | ||
self.is_blank_search || self.is_invalid_search | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#[derive(Clone)] | ||
pub enum RouteId { | ||
Welcome, | ||
Searching(String), | ||
} | ||
|
||
#[derive(Clone, Copy, PartialEq, Debug)] | ||
pub enum ActiveBlock { | ||
SearchBar, | ||
Main, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Route { | ||
id: RouteId, | ||
active_block: ActiveBlock, | ||
} | ||
|
||
impl Route { | ||
pub fn new(id: RouteId, active_block: ActiveBlock) -> Self { | ||
Self { id, active_block } | ||
} | ||
|
||
pub fn get_active_block(&self) -> ActiveBlock { | ||
self.active_block | ||
} | ||
|
||
pub fn get_id(&self) -> RouteId { | ||
self.id.to_owned() | ||
} | ||
} | ||
|
||
impl Default for Route { | ||
fn default() -> Self { | ||
Self { | ||
id: RouteId::Welcome, | ||
active_block: ActiveBlock::SearchBar, | ||
} | ||
} | ||
} |