Remove unnecessary state field
This commit is contained in:
@@ -23,17 +23,16 @@ pub struct MainView {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MainViewState {
|
||||
popup: Option<AppPopup>,
|
||||
status: Status,
|
||||
dl_game_list: GameList<DLSiteManiax>,
|
||||
list_page_size: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Clone)]
|
||||
enum Status {
|
||||
Running,
|
||||
Exiting,
|
||||
Popup,
|
||||
Popup(AppPopup),
|
||||
}
|
||||
|
||||
impl MainView {
|
||||
@@ -56,7 +55,6 @@ impl MainView {
|
||||
let dl_game_list = GameList::new(games)?;
|
||||
let view = Self {
|
||||
state: MainViewState {
|
||||
popup: None,
|
||||
status: Status::Running,
|
||||
list_page_size: 0,
|
||||
dl_game_list,
|
||||
@@ -69,7 +67,7 @@ impl MainView {
|
||||
|
||||
impl MainViewState {
|
||||
fn quit(&mut self) -> color_eyre::Result<()> {
|
||||
if self.popup.is_none() {
|
||||
if matches!(self.status, Status::Running) {
|
||||
self.status = Status::Exiting;
|
||||
ApplicationConfig::get_config()?.save()?;
|
||||
}
|
||||
@@ -77,15 +75,14 @@ impl MainViewState {
|
||||
}
|
||||
|
||||
fn folder_popup(&mut self) {
|
||||
self.popup = Some(AppPopup::AddFolder(AddFolderPopup::new()));
|
||||
self.status = Status::Popup;
|
||||
self.status = Status::Popup(AppPopup::AddFolder(AddFolderPopup::new()));
|
||||
}
|
||||
|
||||
fn handle_popup(&mut self, event: &Event) -> color_eyre::Result<()> {
|
||||
let Some(current_popup) = self.popup.as_mut() else {
|
||||
let Status::Popup(popup) = &mut self.status else {
|
||||
return Ok(());
|
||||
};
|
||||
match current_popup {
|
||||
match popup {
|
||||
AppPopup::AddFolder(folder_popup) => {
|
||||
folder_popup.textarea.handle_input(event)?;
|
||||
if let Event::Key(key) = event &&
|
||||
@@ -133,13 +130,12 @@ impl View for MainView {
|
||||
state.handle_popup(event)?;
|
||||
|
||||
if let Event::Key(key_event) = event {
|
||||
if matches!(state.status, Status::Popup) &&
|
||||
if let Status::Popup(_) = &state.status &&
|
||||
matches!(key_event.code, KeyCode::Esc)
|
||||
{
|
||||
state.status = Status::Running;
|
||||
state.popup = None;
|
||||
}
|
||||
if !matches!(state.status, Status::Popup) &&
|
||||
if matches!(state.status, Status::Running) &&
|
||||
matches!(key_event.kind, KeyEventKind::Press)
|
||||
{
|
||||
match key_event.code {
|
||||
@@ -178,7 +174,7 @@ impl StatefulWidget for MainView {
|
||||
Self::render_game_info(chunks[1], buf, state);
|
||||
Self::render_footer(state, chunks[2], buf);
|
||||
|
||||
let Some(popup) = state.popup.as_mut() else {
|
||||
let Status::Popup(popup) = &mut state.status else {
|
||||
return;
|
||||
};
|
||||
match popup {
|
||||
@@ -191,7 +187,7 @@ impl StatefulWidget for MainView {
|
||||
|
||||
impl HasScreenCursor for MainView {
|
||||
fn screen_cursor(&self) -> Option<(u16, u16)> {
|
||||
let Some(popup) = &self.state.popup else {
|
||||
let Status::Popup(popup) = &self.state.status else {
|
||||
return None;
|
||||
};
|
||||
match popup {
|
||||
@@ -252,7 +248,7 @@ impl MainView {
|
||||
"(q) quit / (a) add folders",
|
||||
Style::default().fg(Color::Green),
|
||||
)];
|
||||
if matches!(state.status, Status::Popup) {
|
||||
if let Status::Popup(_) = state.status {
|
||||
navigation_text[0] = Span::styled("(Esc) close", Style::default().fg(Color::Green));
|
||||
}
|
||||
let line = Line::from(navigation_text);
|
||||
|
||||
Reference in New Issue
Block a user