Skip to content

Commit 78d249b

Browse files
committed
feat: seek pagination support
1 parent 6a44750 commit 78d249b

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

app/controllers/me/pending-invites.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import { tracked } from '@glimmer/tracking';
33

44
import { reads } from 'macro-decorators';
55

6-
import { pagination } from '../../utils/pagination';
6+
import { pagination } from '../../utils/seek';
77

88
export default class PendingInvitesController extends Controller {
9-
queryParams = ['page', 'per_page'];
10-
@tracked page = '1';
11-
@tracked per_page = 10;
9+
queryParams = ['seek'];
10+
@tracked seek = 'WzEsIDFd';
1211

1312
@reads('model.meta.total') totalItems;
1413
@pagination() pagination;

app/utils/seek.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import macro from 'macro-decorators';
2+
3+
const VIEWABLE_PAGES = 9;
4+
5+
export function pagination() {
6+
return macro(function () {
7+
let { page, per_page: perPage, totalItems } = this;
8+
9+
return {
10+
page,
11+
perPage,
12+
totalItems,
13+
}
14+
});
15+
}

src/controllers/crate_owner_invitation.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ pub fn list(req: &mut dyn RequestExt) -> EndpointResult {
2020
let user_id = auth.user_id();
2121

2222
let PrivateListResponse {
23-
invitations, users, ..
23+
invitations,
24+
users,
25+
meta,
2426
} = prepare_list(req, auth, ListFilter::InviteeId(user_id))?;
2527

2628
// The schema for the private endpoints is converted to the schema used by v1 endpoints.
@@ -47,6 +49,7 @@ pub fn list(req: &mut dyn RequestExt) -> EndpointResult {
4749
Ok(req.json(&json!({
4850
"crate_owner_invitations": crate_owner_invitations,
4951
"users": users,
52+
"meta": meta,
5053
})))
5154
}
5255

@@ -123,6 +126,10 @@ fn prepare_list(
123126
))
124127
// We fetch one element over the page limit to then detect whether there is a next page.
125128
.limit(pagination.per_page as i64 + 1);
129+
let total = crate_owner_invitations::table
130+
.count()
131+
.get_result(&*conn)
132+
.unwrap();
126133

127134
// Load and paginate the results.
128135
let mut raw_invitations: Vec<CrateOwnerInvitation> = match pagination.page {
@@ -225,7 +232,7 @@ fn prepare_list(
225232
Ok(PrivateListResponse {
226233
invitations,
227234
users: users.into_iter().map(|(_, user)| user.into()).collect(),
228-
meta: ResponseMeta { next_page },
235+
meta: ResponseMeta { next_page, total },
229236
})
230237
}
231238

@@ -239,6 +246,7 @@ struct PrivateListResponse {
239246
#[derive(Serialize)]
240247
struct ResponseMeta {
241248
next_page: Option<String>,
249+
total: i64,
242250
}
243251

244252
#[derive(Deserialize)]

0 commit comments

Comments
 (0)