Add paginated panel loading
This commit is contained in:
@@ -3,6 +3,22 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
use gotcha_gitea::models;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const PAGE_SIZE: i32 = 30;
|
||||
|
||||
pub struct Page<T> {
|
||||
pub items: Vec<T>,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
impl<T> Page<T> {
|
||||
pub fn from_items(items: Vec<T>) -> Self {
|
||||
Self {
|
||||
has_more: items.len() == PAGE_SIZE as usize,
|
||||
items,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum AppearanceMode {
|
||||
@@ -132,11 +148,13 @@ pub struct State {
|
||||
pub struct HomeData {
|
||||
pub activities: Vec<models::Activity>,
|
||||
pub heatmap: Vec<models::UserHeatmapData>,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
pub struct IssueDetails {
|
||||
pub issue: models::Issue,
|
||||
pub comments: Vec<models::Comment>,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
pub struct IssueEditorData {
|
||||
@@ -157,12 +175,14 @@ pub struct MilestoneDetails {
|
||||
pub milestone: models::Milestone,
|
||||
pub issues: Vec<models::Issue>,
|
||||
pub pulls: Vec<models::Issue>,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
pub struct PullDetails {
|
||||
pub pull: models::PullRequest,
|
||||
pub comments: Vec<models::Comment>,
|
||||
pub files: Vec<models::ChangedFile>,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
pub fn open_status() -> String {
|
||||
@@ -244,4 +264,10 @@ mod tests {
|
||||
assert_eq!(parse_api_date("2023-02-29T00:00:00Z"), None);
|
||||
assert_eq!(parse_api_date("not-a-date"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_api_pages_expose_more_results() {
|
||||
assert!(Page::from_items(vec![(); PAGE_SIZE as usize]).has_more);
|
||||
assert!(!Page::from_items(vec![(); PAGE_SIZE as usize - 1]).has_more);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user