Provide search functionality through the TUI #134

Merged
wojtek merged 35 commits from 24---provide-search-functionality-through-the-tui into main 2024-02-18 22:12:42 +01:00
3 changed files with 15 additions and 20 deletions
Showing only changes of commit 24daaff2a1 - Show all commits

View File

@ -21,13 +21,21 @@ pub type App<MH> = AppState<
>;
impl<MH: IMusicHoard> App<MH> {
pub fn new(music_hoard: MH) -> Self {
match AppMachine::new(music_hoard) {
Ok(browse) => browse.into(),
Err(critical) => critical.into(),
pub fn new(mut music_hoard: MH) -> Self {
let init_result = Self::init(&mut music_hoard);
let inner = AppInner::new(music_hoard);
match init_result {
Ok(()) => AppMachine::browse(inner).into(),
Err(err) => AppMachine::critical(inner, err.to_string()).into(),
}
}
fn init(music_hoard: &mut MH) -> Result<(), musichoard::Error> {
music_hoard.load_from_database()?;
music_hoard.rescan_library()?;
Ok(())
}
fn inner_ref(&self) -> &AppInner<MH> {
match self {
AppState::Browse(browse) => browse.inner_ref(),

View File

@ -2,7 +2,7 @@ use crate::tui::{
app::{
app::App,
selection::{Delta, ListSelection},
state::{critical::AppCritical, AppInner, AppMachine},
state::{AppInner, AppMachine},
AppPublic, AppState, IAppInteractBrowse,
},
lib::IMusicHoard,
@ -17,21 +17,6 @@ impl<MH: IMusicHoard> AppMachine<MH, AppBrowse> {
state: AppBrowse,
}
}
pub fn new(mut music_hoard: MH) -> Result<Self, AppMachine<MH, AppCritical>> {
let init_result = Self::init(&mut music_hoard);
let inner = AppInner::new(music_hoard);
match init_result {
Ok(()) => Ok(AppMachine::browse(inner)),
Err(err) => Err(AppMachine::critical(inner, err.to_string())),
}
}
fn init(music_hoard: &mut MH) -> Result<(), musichoard::Error> {
music_hoard.load_from_database()?;
music_hoard.rescan_library()?;
Ok(())
}
}
impl<MH: IMusicHoard> From<AppMachine<MH, AppBrowse>> for App<MH> {

View File

@ -59,6 +59,8 @@ impl<'a, MH: IMusicHoard> From<&'a mut AppInner<MH>> for AppPublicInner<'a> {
}
}
// FIXME: split tests - into parts that test functionality in isolation and move those where
// appropriate, and parts that verify transitions between states.
#[cfg(test)]
mod tests {
use musichoard::collection::Collection;