Pedantic clippy

This commit is contained in:
Joseph Ferano 2023-06-13 23:00:28 +07:00
parent 7c2249ed08
commit 4e0195e132
3 changed files with 10 additions and 8 deletions

View File

@ -159,7 +159,7 @@ impl<'a> Column {
}
#[must_use]
pub fn get_task_state_from_curr_selected_task(&self) -> Option<TaskState<'a>> {
pub fn get_task_state_from_current(&self) -> Option<TaskState<'a>> {
self.get_selected_task().map(|t| TaskState {
title: TextArea::from(t.title.lines()),
description: TextArea::from(t.description.lines()),

View File

@ -151,6 +151,7 @@ pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
tx.commit().unwrap();
}
/// # Panics
///
/// Panics if something goes wrong with the SQL
pub fn set_selected_column(conn: &Connection, column_id: usize) {
@ -161,19 +162,21 @@ pub fn set_selected_column(conn: &Connection, column_id: usize) {
.unwrap();
}
/// # Panics
///
/// Panics if something goes wrong with the SQL
pub fn get_selected_column(conn: &Connection) -> usize {
let mut stmt = conn
.prepare("select value from app_state where key = ?1")
.unwrap();
stmt.query_row(&["selected_column"], |row| {
stmt.query_row(["selected_column"], |row| {
let value: String = row.get::<usize, String>(0).unwrap();
Ok(value.parse::<usize>().unwrap())
})
.unwrap()
}
/// # Panics
///
/// Panics if something goes wrong with the SQL
pub fn set_selected_task_for_column(conn: &Connection, task_idx: usize, column_id: i32) {
@ -183,6 +186,7 @@ pub fn set_selected_task_for_column(conn: &Connection, task_idx: usize, column_i
stmt.execute((column_id, task_idx)).unwrap();
}
/// # Panics
///
/// Panics if something goes wrong with the SQL
pub fn get_selected_task_for_column(conn: &Connection, column_id: i32) -> usize {

View File

@ -146,9 +146,7 @@ pub fn handle_main(state: &mut State<'_>, key: event::KeyEvent) {
}
}
KeyCode::Char('n') => state.task_edit_state = Some(TaskState::default()),
KeyCode::Char('e') => {
state.task_edit_state = column.get_task_state_from_curr_selected_task();
}
KeyCode::Char('e') => state.task_edit_state = column.get_task_state_from_current(),
KeyCode::Char('D') => {
if !column.tasks.is_empty() {
db::delete_task(&state.db_conn, column.get_selected_task().unwrap());
@ -173,9 +171,9 @@ pub fn handle_main(state: &mut State<'_>, key: event::KeyEvent) {
/// Shouldn't really panic because there are checks to ensure we can unwrap safely
pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
if let Event::Key(key) = event::read()? {
if let Some(_) = state.task_edit_state {
let mut column = state.project.get_selected_column_mut();
handle_task_edit(&state.db_conn, &mut column, key, &mut state.task_edit_state);
if state.task_edit_state.is_some() {
let column = state.project.get_selected_column_mut();
handle_task_edit(&state.db_conn, column, key, &mut state.task_edit_state);
} else {
handle_main(state, key);
}