todo stuff
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
// todo split pager out into a single struct
|
||||
use chrono_tz::Tz;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::*;
|
||||
use serenity::{builder::CreateComponents, model::interactions::message_component::ButtonStyle};
|
||||
use serenity::{
|
||||
builder::CreateComponents,
|
||||
model::{
|
||||
id::{ChannelId, GuildId, UserId},
|
||||
interactions::message_component::ButtonStyle,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{component_models::ComponentDataModel, models::reminder::look_flags::LookFlags};
|
||||
|
||||
@ -209,3 +216,123 @@ impl DelPager {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct TodoPager {
|
||||
pub page: usize,
|
||||
action: PageAction,
|
||||
pub user_id: Option<UserId>,
|
||||
pub channel_id: Option<ChannelId>,
|
||||
pub guild_id: Option<GuildId>,
|
||||
}
|
||||
|
||||
impl Pager for TodoPager {
|
||||
fn next_page(&self, max_pages: usize) -> usize {
|
||||
match self.action {
|
||||
PageAction::First => 0,
|
||||
PageAction::Previous => 0.max(self.page - 1),
|
||||
PageAction::Refresh => self.page,
|
||||
PageAction::Next => (max_pages - 1).min(self.page + 1),
|
||||
PageAction::Last => max_pages - 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn create_button_row(&self, max_pages: usize, comp: &mut CreateComponents) {
|
||||
let next_page = self.next_page(max_pages);
|
||||
|
||||
let (page_first, page_prev, page_refresh, page_next, page_last) =
|
||||
TodoPager::buttons(next_page, self.user_id, self.channel_id, self.guild_id);
|
||||
|
||||
comp.create_action_row(|row| {
|
||||
row.create_button(|b| {
|
||||
b.label("⏮️")
|
||||
.style(ButtonStyle::Primary)
|
||||
.custom_id(page_first.to_custom_id())
|
||||
.disabled(next_page == 0)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.label("◀️")
|
||||
.style(ButtonStyle::Secondary)
|
||||
.custom_id(page_prev.to_custom_id())
|
||||
.disabled(next_page == 0)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.label("🔁").style(ButtonStyle::Secondary).custom_id(page_refresh.to_custom_id())
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.label("▶️")
|
||||
.style(ButtonStyle::Secondary)
|
||||
.custom_id(page_next.to_custom_id())
|
||||
.disabled(next_page + 1 == max_pages)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.label("⏭️")
|
||||
.style(ButtonStyle::Primary)
|
||||
.custom_id(page_last.to_custom_id())
|
||||
.disabled(next_page + 1 == max_pages)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl TodoPager {
|
||||
pub fn new(
|
||||
page: usize,
|
||||
user_id: Option<UserId>,
|
||||
channel_id: Option<ChannelId>,
|
||||
guild_id: Option<GuildId>,
|
||||
) -> Self {
|
||||
Self { page, action: PageAction::Refresh, user_id, channel_id, guild_id }
|
||||
}
|
||||
|
||||
pub fn buttons(
|
||||
page: usize,
|
||||
user_id: Option<UserId>,
|
||||
channel_id: Option<ChannelId>,
|
||||
guild_id: Option<GuildId>,
|
||||
) -> (
|
||||
ComponentDataModel,
|
||||
ComponentDataModel,
|
||||
ComponentDataModel,
|
||||
ComponentDataModel,
|
||||
ComponentDataModel,
|
||||
) {
|
||||
(
|
||||
ComponentDataModel::TodoPager(TodoPager {
|
||||
page,
|
||||
action: PageAction::First,
|
||||
user_id,
|
||||
channel_id,
|
||||
guild_id,
|
||||
}),
|
||||
ComponentDataModel::TodoPager(TodoPager {
|
||||
page,
|
||||
action: PageAction::Previous,
|
||||
user_id,
|
||||
channel_id,
|
||||
guild_id,
|
||||
}),
|
||||
ComponentDataModel::TodoPager(TodoPager {
|
||||
page,
|
||||
action: PageAction::Refresh,
|
||||
user_id,
|
||||
channel_id,
|
||||
guild_id,
|
||||
}),
|
||||
ComponentDataModel::TodoPager(TodoPager {
|
||||
page,
|
||||
action: PageAction::Next,
|
||||
user_id,
|
||||
channel_id,
|
||||
guild_id,
|
||||
}),
|
||||
ComponentDataModel::TodoPager(TodoPager {
|
||||
page,
|
||||
action: PageAction::Last,
|
||||
user_id,
|
||||
channel_id,
|
||||
guild_id,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user