Skip to content

Introduce MVVM #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ratatui::{prelude::Backend, Terminal};

use std::ops::ControlFlow;

use crate::{app::config::Config, infrastructure::terminal::restore};
use crate::{infrastructure::terminal::restore, model::config::Config};

#[derive(Debug, Parser)]
#[command(version, about)]
Expand Down
18 changes: 9 additions & 9 deletions src/handler/bookmarked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use ratatui::{
use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
model::{screens::View, Model},
ui::popup::{help::HelpPopUpBuilder, PopUp},
};

pub fn handle_bookmarked_patchsets<B>(
app: &mut App,
model: &mut Model,
key: KeyEvent,
mut terminal: Terminal<B>,
) -> color_eyre::Result<ControlFlow<(), Terminal<B>>>
Expand All @@ -23,25 +23,25 @@ where
match key.code {
KeyCode::Char('?') => {
let popup = generate_help_popup();
app.popup = Some(popup);
model.popup = Some(popup);
}
KeyCode::Esc | KeyCode::Char('q') => {
app.bookmarked_patchsets.patchset_index = 0;
app.set_current_screen(CurrentScreen::MailingListSelection);
model.bookmarked_patchsets.patchset_index = 0;
model.set_current_screen(View::MailingListSelection);
}
KeyCode::Char('j') | KeyCode::Down => {
app.bookmarked_patchsets.select_below_patchset();
model.bookmarked_patchsets.select_below_patchset();
}
KeyCode::Char('k') | KeyCode::Up => {
app.bookmarked_patchsets.select_above_patchset();
model.bookmarked_patchsets.select_above_patchset();
}
KeyCode::Enter => {
terminal = loading_screen! {
terminal,
"Loading patchset" => {
let result = app.init_details_actions();
let result = model.init_details_actions();
if result.is_ok() {
app.set_current_screen(CurrentScreen::PatchsetDetails);
model.set_current_screen(View::PatchsetDetails);
}
result
}
Expand Down
20 changes: 10 additions & 10 deletions src/handler/details_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use ratatui::{
use std::time::Duration;

use crate::{
app::{screens::CurrentScreen, App},
infrastructure::terminal::{setup_user_io, teardown_user_io},
model::{screens::View, Model},
ui::popup::{help::HelpPopUpBuilder, review_trailers::ReviewTrailersPopUp, PopUp},
};

use super::wait_key_press;

pub fn handle_patchset_details<B: Backend>(
app: &mut App,
model: &mut Model,
key: KeyEvent,
terminal: &mut Terminal<B>,
) -> color_eyre::Result<()> {
let patchset_details_and_actions = app.details_actions.as_mut().unwrap();
let patchset_details_and_actions = model.details_actions.as_mut().unwrap();

if key.modifiers.contains(KeyModifiers::SHIFT) {
match key.code {
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn handle_patchset_details<B: Backend>(
KeyCode::Char('t') => {
let popup =
ReviewTrailersPopUp::generate_trailers_popup(patchset_details_and_actions);
app.popup = Some(popup);
model.popup = Some(popup);
}
_ => {}
}
Expand All @@ -61,12 +61,12 @@ pub fn handle_patchset_details<B: Backend>(
match key.code {
KeyCode::Char('?') => {
let popup = generate_help_popup();
app.popup = Some(popup);
model.popup = Some(popup);
}
KeyCode::Esc | KeyCode::Char('q') => {
let ps_da_clone = patchset_details_and_actions.last_screen.clone();
app.set_current_screen(ps_da_clone);
app.reset_details_actions();
model.set_current_screen(ps_da_clone);
model.reset_details_actions();
}
KeyCode::Char('a') => {
patchset_details_and_actions.toggle_apply_action();
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn handle_patchset_details<B: Backend>(
KeyCode::Enter => {
if patchset_details_and_actions.actions_require_user_io() {
setup_user_io(terminal)?;
app.consolidate_patchset_actions()?;
model.consolidate_patchset_actions()?;
println!("\nPress ENTER continue...");
loop {
if let Event::Key(key) = event::read()? {
Expand All @@ -120,9 +120,9 @@ pub fn handle_patchset_details<B: Backend>(
}
teardown_user_io(terminal)?;
} else {
app.consolidate_patchset_actions()?;
model.consolidate_patchset_actions()?;
}
app.set_current_screen(CurrentScreen::PatchsetDetails);
model.set_current_screen(View::PatchsetDetails);
}
_ => {}
}
Expand Down
16 changes: 8 additions & 8 deletions src/handler/edit_config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ratatui::crossterm::event::{KeyCode, KeyEvent};

use crate::{
app::{screens::CurrentScreen, App},
model::{screens::View, Model},
ui::popup::{help::HelpPopUpBuilder, PopUp},
};

pub fn handle_edit_config(app: &mut App, key: KeyEvent) -> color_eyre::Result<()> {
if let Some(edit_config_state) = app.edit_config.as_mut() {
pub fn handle_edit_config(model: &mut Model, key: KeyEvent) -> color_eyre::Result<()> {
if let Some(edit_config_state) = model.edit_config.as_mut() {
match edit_config_state.is_editing() {
true => match key.code {
KeyCode::Esc => {
Expand All @@ -29,13 +29,13 @@ pub fn handle_edit_config(app: &mut App, key: KeyEvent) -> color_eyre::Result<()
false => match key.code {
KeyCode::Char('?') => {
let popup = generate_help_popup();
app.popup = Some(popup);
model.popup = Some(popup);
}
KeyCode::Esc | KeyCode::Char('q') => {
app.consolidate_edit_config();
app.config.save_patch_hub_config()?;
app.reset_edit_config();
app.set_current_screen(CurrentScreen::MailingListSelection);
model.consolidate_edit_config();
model.config.save_patch_hub_config()?;
model.reset_edit_config();
model.set_current_screen(View::MailingListSelection);
}
KeyCode::Enter => {
edit_config_state.toggle_editing();
Expand Down
16 changes: 8 additions & 8 deletions src/handler/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ use ratatui::{
use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
model::{screens::View, Model},
ui::popup::{help::HelpPopUpBuilder, PopUp},
};

pub fn handle_latest_patchsets<B>(
app: &mut App,
model: &mut Model,
key: KeyEvent,
mut terminal: Terminal<B>,
) -> color_eyre::Result<ControlFlow<(), Terminal<B>>>
where
B: Backend + Send + 'static,
{
let latest_patchsets = app.latest_patchsets.as_mut().unwrap();
let latest_patchsets = model.latest_patchsets.as_mut().unwrap();

match key.code {
KeyCode::Char('?') => {
let popup = generate_help_popup();
app.popup = Some(popup);
model.popup = Some(popup);
}
KeyCode::Esc | KeyCode::Char('q') => {
app.reset_latest_patchsets();
app.set_current_screen(CurrentScreen::MailingListSelection);
model.reset_latest_patchsets();
model.set_current_screen(View::MailingListSelection);
}
KeyCode::Char('j') | KeyCode::Down => {
latest_patchsets.select_below_patchset();
Expand All @@ -54,9 +54,9 @@ where
terminal = loading_screen! {
terminal,
"Loading patchset" => {
let result = app.init_details_actions();
let result = model.init_details_actions();
if result.is_ok() {
app.set_current_screen(CurrentScreen::PatchsetDetails);
model.set_current_screen(View::PatchsetDetails);
}
result
}
Expand Down
38 changes: 19 additions & 19 deletions src/handler/mail_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use ratatui::{
use std::ops::ControlFlow;

use crate::{
app::{screens::CurrentScreen, App},
loading_screen,
model::{screens::View, Model},
ui::popup::{help::HelpPopUpBuilder, PopUp},
};

pub fn handle_mailing_list_selection<B>(
app: &mut App,
model: &mut Model,
key: KeyEvent,
mut terminal: Terminal<B>,
) -> color_eyre::Result<ControlFlow<(), Terminal<B>>>
Expand All @@ -23,12 +23,12 @@ where
match key.code {
KeyCode::Char('?') => {
let popup = generate_help_popup();
app.popup = Some(popup);
model.popup = Some(popup);
}
KeyCode::Enter => {
if app.mailing_list_selection.has_valid_target_list() {
app.init_latest_patchsets();
let list_name = app
if model.mailing_list_selection.has_valid_target_list() {
model.init_latest_patchsets();
let list_name = model
.latest_patchsets
.as_ref()
.unwrap()
Expand All @@ -39,11 +39,11 @@ where
terminal,
format!("Fetching patchsets from {}", list_name) => {
let result =
app.latest_patchsets.as_mut().unwrap()
model.latest_patchsets.as_mut().unwrap()
.fetch_current_page();
if result.is_ok() {
app.mailing_list_selection.clear_target_list();
app.set_current_screen(CurrentScreen::LatestPatchsets);
model.mailing_list_selection.clear_target_list();
model.set_current_screen(View::LatestPatchsets);
}
result
}
Expand All @@ -54,35 +54,35 @@ where
terminal = loading_screen! {
terminal,
"Refreshing lists" => {
app.mailing_list_selection
model.mailing_list_selection
.refresh_available_mailing_lists()
}
};
}
KeyCode::F(2) => {
app.init_edit_config();
app.set_current_screen(CurrentScreen::EditConfig);
model.init_edit_config();
model.set_current_screen(View::EditConfig);
}
KeyCode::F(1) => {
if !app.bookmarked_patchsets.bookmarked_patchsets.is_empty() {
app.mailing_list_selection.clear_target_list();
app.set_current_screen(CurrentScreen::BookmarkedPatchsets);
if !model.bookmarked_patchsets.bookmarked_patchsets.is_empty() {
model.mailing_list_selection.clear_target_list();
model.set_current_screen(View::BookmarkedPatchsets);
}
}
KeyCode::Backspace => {
app.mailing_list_selection.remove_last_target_list_char();
model.mailing_list_selection.remove_last_target_list_char();
}
KeyCode::Esc => {
return Ok(ControlFlow::Break(()));
}
KeyCode::Char(ch) => {
app.mailing_list_selection.push_char_to_target_list(ch);
model.mailing_list_selection.push_char_to_target_list(ch);
}
KeyCode::Down => {
app.mailing_list_selection.highlight_below_list();
model.mailing_list_selection.highlight_below_list();
}
KeyCode::Up => {
app.mailing_list_selection.highlight_above_list();
model.mailing_list_selection.highlight_above_list();
}
_ => {}
}
Expand Down
Loading