use gamenight_api_client_rs::apis::default_api::get_gamenights; use inquire::Select; use crate::flows::view_gamenight::ViewGamenight; use super::{abort::Abort, *}; #[derive(Clone)] pub struct ListGamenights { } impl ListGamenights { pub fn new() -> Self { Self {} } } #[async_trait] impl<'a> Flow<'a> for ListGamenights { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { let response = get_gamenights(&state.configuration).await?; let mut view_flows = response.into_iter().map(|gamenight| -> Box + Send> { Box::new(ViewGamenight::new(gamenight)) }).collect:: + Send>>>(); view_flows.push(Box::new(Abort::new())); let choice = Select::new("What gamenight would you like to view?", view_flows) .prompt_skippable()?; handle_choice_option(&choice, self, state).await } } impl Display for ListGamenights { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "List all gamenights") } }