fixed val logic, added status
This commit is contained in:
@@ -8,7 +8,7 @@ use ratatui::widgets::TableState;
|
||||
use crate::app::{
|
||||
entry::Entry,
|
||||
settings::Settings,
|
||||
status::{CurrentScreen, EditingField, EntryCreation},
|
||||
status::{AppStatus, CurrentScreen, EditingField, EntryValError},
|
||||
};
|
||||
|
||||
pub struct AppState {
|
||||
@@ -16,11 +16,12 @@ pub struct AppState {
|
||||
pub fromPort: String,
|
||||
pub toIP: String,
|
||||
pub toPort: String,
|
||||
pub screen: CurrentScreen,
|
||||
pub currentlyEditing: Option<EditingField>,
|
||||
pub screen: CurrentScreen,
|
||||
pub entries: Vec<Entry>,
|
||||
pub confDir: String,
|
||||
pub tableState: TableState,
|
||||
pub appStatus: AppStatus,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -36,10 +37,11 @@ impl AppState {
|
||||
entries: settings.entries,
|
||||
confDir,
|
||||
tableState: TableState::default().with_selected(0),
|
||||
appStatus: AppStatus::Welcome,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn store(&mut self) -> EntryCreation {
|
||||
pub fn store(&mut self) -> EntryValError {
|
||||
match Entry::new(
|
||||
self.fromIP.clone(),
|
||||
self.toIP.clone(),
|
||||
@@ -53,11 +55,10 @@ impl AppState {
|
||||
self.fromPort = String::new();
|
||||
self.toPort = String::new();
|
||||
self.currentlyEditing = None;
|
||||
self.tableState
|
||||
.select(Some(self.entries.len() - 1 as usize));
|
||||
EntryCreation::Success
|
||||
self.tableState.select(Some(self.entries.len() - 1_usize));
|
||||
EntryValError::NONE
|
||||
}
|
||||
_ => EntryCreation::PortValidationError,
|
||||
Err(e) => e,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user