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