From abc26d7be02a1ae877e3c367180359e2aaeee75e Mon Sep 17 00:00:00 2001 From: Akulij Date: Fri, 2 May 2025 14:30:50 +0300 Subject: [PATCH] make ProjectPage callback to actually display some projects information --- src/main.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 16669c4..f5895a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -302,8 +302,45 @@ async fn callback_handler(bot: Bot, mut db: DB, q: CallbackQuery) -> BotResult<( .await? } Callback::ProjectPage { id } => { - bot.send_message(q.from.id, format!("Some project No: {id}")) - .await?; + let nextproject = db + .get_literal_value(&format!("project_{}_msg", id + 1)) + .await? + .unwrap_or("emptyproject".into()); + let keyboard = match nextproject.to_lowercase().as_str() { + "end" | "empty" | "none" => { + stacked_buttons_markup!( + create_callback_button("go_home", Callback::GoHome, &mut db).await? + ) + } + _ => { + stacked_buttons_markup!( + create_callback_button( + "next_project", + Callback::ProjectPage { id: id + 1 }, + &mut db + ) + .await?, + create_callback_button("go_home", Callback::GoHome, &mut db).await? + ) + } + }; + + replace_message( + &bot, + &mut db, + q.chat_id().map(|i| i.0).unwrap_or(q.from.id.0 as i64), + q.message.map_or_else( + || { + Err(BotError::MsgTooOld( + "Failed to get message id, probably message too old".to_string(), + )) + }, + |m| Ok(m.id().0), + )?, + &format!("project_{}_msg", id), + Some(keyboard), + ) + .await? } Callback::GoHome => { let keyboard = make_start_buttons(&mut db).await?;