applied clippy

This commit is contained in:
Nickiel12 2023-09-22 21:32:17 -07:00
parent 52e46f737e
commit 057cdb02c0
10 changed files with 82 additions and 52 deletions

View file

@ -97,3 +97,9 @@ impl<'a> States<'a> {
}
}
}
impl<'a> Default for States<'a> {
fn default() -> Self {
Self::new()
}
}

View file

@ -42,7 +42,7 @@ impl DB {
transactions.append(&mut temp_transactions);
}
return Ok(());
Ok(())
}
//
@ -64,7 +64,7 @@ impl DB {
transactions.append(&mut temp_transactions);
}
return Ok(());
Ok(())
}
pub async fn get_all_buckets(&mut self) -> Result<(), Error> {
@ -85,6 +85,6 @@ impl DB {
transactions.append(&mut temp_transactions);
}
return Ok(());
Ok(())
}
}

View file

@ -35,6 +35,12 @@ impl DataCache {
}
}
}
return None;
None
}
}
impl Default for DataCache {
fn default() -> Self {
Self::new()
}
}

View file

@ -1,3 +1,4 @@
use core::fmt;
use std::borrow::Cow;
use sqlx::{postgres::types::PgMoney, FromRow};
@ -76,19 +77,21 @@ pub struct PartialTransaction {
impl Transaction {
pub fn get_header() -> String {
return format!(" {:<7} | {:<9} | {:<10}", "Id", "Amount", "Date");
}
pub fn to_string(&self) -> String {
return format!(
" T{:0>6} | {:>9} | {:>10}",
self.trns_id,
self.trns_amount.to_decimal(2).to_string(),
self.trns_date.to_string()
);
format!(" {:<7} | {:<9} | {:<10}", "Id", "Amount", "Date")
}
pub fn as_str(&self) -> Cow<str> {
return self.to_string().into();
self.to_string().into()
}
}
impl fmt::Display for Transaction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, " T{:0>6} | {:>9} | {:>10}",
self.trns_id,
self.trns_amount.to_decimal(2).to_string(),
self.trns_date.to_string()
)
}
}

View file

@ -55,29 +55,26 @@ pub fn poll_events(app: &mut App) -> AppResult<()> {
// 'q' needs to be handled at the top level so it can't be
// accidentally handed to a dead end
if let KeyCode::Char('q') = key.code {
if let Some(_) = app.states.nav_state.message.clone() {
if app.states.nav_state.message.is_some() {
app.states.nav_state.message = None;
} else if let ActiveFrame::Navigation = app.states.active_frame {
app.running = false;
} else {
if let ActiveFrame::Navigation = app.states.active_frame {
app.running = false;
} else {
app.states.active_frame = ActiveFrame::Navigation;
}
app.states.active_frame = ActiveFrame::Navigation;
}
} else if let KeyCode::Esc = key.code {
if let Some(_) = app.states.nav_state.message.clone() {
if app.states.nav_state.message.is_some() {
app.states.nav_state.message = None;
} else if let ActiveFrame::Navigation = app.states.active_frame {
app.running = false;
} else {
if let ActiveFrame::Navigation = app.states.active_frame {
app.running = false;
} else {
app.states.active_frame = ActiveFrame::Navigation;
}
app.states.active_frame = ActiveFrame::Navigation;
}
}
if let KeyCode::Char('r') = key.code {
app.refresh();
}
match app.states.active_frame {
ActiveFrame::Navigation => {
NavigationState::handle_event(key, app);
@ -93,7 +90,7 @@ pub fn poll_events(app: &mut App) -> AppResult<()> {
}
}
}
return Ok(());
Ok(())
}
pub fn init_logger(output_file: String) {

View file

@ -1,8 +1,5 @@
use crate::{
app::{ActiveFrame, App},
uis::{render_history_tab, render_manual_transaction},
};
use log;
// use log;
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout},
@ -11,7 +8,10 @@ use ratatui::{
Frame,
};
use crate::uis::{render_navigation_frame, render_quick_transaction};
use crate::{
app::{ActiveFrame, App},
uis::{render_history_tab, render_manual_transaction, render_navigation_frame, render_quick_transaction},
};
pub fn render<B: Backend>(f: &mut Frame<B>, app: &mut App) {
let size = f.size();

View file

@ -55,6 +55,12 @@ impl HistoryState {
}
}
impl Default for HistoryState {
fn default() -> Self {
Self::new()
}
}
pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &mut App) {
let split_body = Layout::default()
.direction(Direction::Horizontal)
@ -78,14 +84,14 @@ pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &m
lines.push(Line::from(vec![
Span::styled("Amount: ", ident_style),
Span::styled(
format!("{}", selected_item.trns_amount.to_decimal(2).to_string()),
selected_item.trns_amount.to_decimal(2).to_string(),
value_style,
),
]));
lines.push(Line::from(vec![
Span::styled("Transaction Date: ", ident_style),
Span::styled(
format!("{}", selected_item.trns_date.to_string()),
selected_item.trns_date.to_string(),
value_style,
),
]));

View file

@ -14,7 +14,7 @@ use crate::{
};
use chrono::prelude::Local;
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
use crossterm::event::{KeyCode, KeyEvent};
pub struct ManualTransactionState {
pub focus: Option<ManualDataFocus>,
@ -95,7 +95,7 @@ impl ManualTransactionState {
}
ManualDataFocus::Date => {
if let Some(ref mut x) = app.states.manual_transactions.date {
if x.len() == 0 {
if x.is_empty() {
x.push_str(&format!("+{}", Local::now().format("%m-%d-%Y")));
}
}
@ -158,7 +158,7 @@ impl ManualTransactionState {
},
KeyCode::Char(value) => match app.states.manual_transactions.focus.unwrap() {
ManualDataFocus::Amount => {
if value.is_digit(10) || value == '.' {
if value.is_ascii_digit() || value == '.' {
if let Some(ref mut s) = app.states.manual_transactions.amount {
s.push(value);
} else {
@ -174,7 +174,7 @@ impl ManualTransactionState {
}
}
ManualDataFocus::Date => {
if value.is_digit(10) {
if value.is_ascii_digit() {
if let Some(ref mut s) = app.states.manual_transactions.date {
if s.len() < 10 {
s.push(value);
@ -193,26 +193,26 @@ impl ManualTransactionState {
}
if let Some(ManualDataFocus::Date) = app.states.manual_transactions.focus {
if let Some(ref mut x) = app.states.manual_transactions.date {
if x.starts_with("+") {
if x.starts_with('+') {
x.clear();
}
}
}
} else {
match event.code {
KeyCode::Enter => {
app.states.manual_transactions.focus = Some(ManualDataFocus::Account);
}
_ => {}
};
} else if event.code == KeyCode::Enter{
app.states.manual_transactions.focus = Some(ManualDataFocus::Account);
}
}
}
impl Default for ManualTransactionState {
fn default() -> Self {
Self::new()
}
}
pub fn render_manual_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
// Render the custom tab bar
let mut constraints: Vec<Constraint> = vec![];
let constraints: Vec<Constraint> = vec![
Constraint::Length(1),
Constraint::Length(1), // account

View file

@ -63,6 +63,12 @@ impl<'a> NavigationState<'a> {
}
}
impl<'a> Default for NavigationState<'a> {
fn default() -> Self {
Self::new()
}
}
pub fn render_navigation_frame<B: Backend>(
f: &mut Frame<B>,
status_rect: Rect,
@ -114,7 +120,7 @@ pub fn render_navigation_frame<B: Backend>(
// Navbar section
let navbar = {
if let None = app.states.nav_state.message {
if app.states.nav_state.message.is_none() {
match app.states.active_frame {
ActiveFrame::Navigation => "Navigating: q/Esc to exit".to_string(),
_ => "Editing Body: q/Esc to go back to navigating".to_string(),

View file

@ -27,7 +27,7 @@ impl<'a> QuickTransactionState<'a> {
}
pub fn handle_event(event: KeyEvent, app: &mut App) {
let transact_state = &app.states.transactions;
// let transact_state = &app.states.transactions;
if event.kind == KeyEventKind::Press {
match event.code {
@ -38,6 +38,12 @@ impl<'a> QuickTransactionState<'a> {
}
}
impl<'a> Default for QuickTransactionState<'a> {
fn default() -> Self {
Self::new()
}
}
pub fn render_quick_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
let chunks = Layout::default()
.direction(Direction::Vertical)