From caca9e354d7def319085348f73508295e95227a7 Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 3 May 2025 16:38:47 +0300 Subject: [PATCH] change ProjectPage callback's keyboard generation --- src/main.rs | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index aa9c713..45f544f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -306,28 +306,39 @@ async fn callback_handler(bot: Bot, mut db: DB, q: CallbackQuery) -> BotResult<( .await? } Callback::ProjectPage { id } => { - let nextproject = db + let nextproject = match 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? + .unwrap_or("emptyproject".into()) + .as_str() + { + "end" | "empty" | "none" => None, + _ => Some( + create_callback_button( + "next_project", + Callback::ProjectPage { id: id + 1 }, + &mut db, ) - } - _ => { - 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? - ) - } + .await?, + ), }; + let prevproject = match id.wrapping_sub(1) { + 0 => None, + _ => Some( + create_callback_button( + "prev_project", + Callback::ProjectPage { + id: id.wrapping_sub(1), + }, + &mut db, + ) + .await?, + ), + }; + let keyboard = buttons_markup!( + [prevproject, nextproject].into_iter().flatten(), + [create_callback_button("go_home", Callback::GoHome, &mut db).await?] + ); replace_message( &bot,