Skip to content

Commit

Permalink
fix: provide a seek pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed Sep 14, 2022
1 parent 95f9b64 commit 36c2d62
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
7 changes: 7 additions & 0 deletions app/components/seek-pagination.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#if @pagination.nextPage}}
<nav local-class='seek-pagination' aria-label="Pagination navigation">
<LinkTo @query={{hash seek=@pagination.nextPage}} local-class="next" rel="next" title="Goes to next page" data-test-pagination-next>
Next Page
</LinkTo>
</nav>
{{/if}}
28 changes: 28 additions & 0 deletions app/components/seek-pagination.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.seek-pagination {
text-align: center;
font-size: 90%;
margin-bottom: 20px;

ol {
list-style: none;
padding: 0;
}
ol, li { display: inline; }

a {
color: var(--main-color-light);
text-decoration: none;
padding: 5px 6px;
}
a:hover { background-color: var(--main-bg-dark); }
a:global(.active) { background-color: var(--main-bg-dark); }

img, svg { vertical-align: middle; }

.next:global(.active),
.prev:global(.active),
.next:hover,
.prev:hover {
background: none;
}
}
8 changes: 2 additions & 6 deletions app/controllers/me/pending-invites.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

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

export default class PendingInvitesController extends Controller {
queryParams = ['seek'];
@tracked seek = 'WzEsIDFd';

@reads('model.meta.total') totalItems;
@reads('model.meta.next_page') nextPage;
@pagination() pagination;
}
2 changes: 1 addition & 1 deletion app/routes/me/pending-invites.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class PendingInvitesRoute extends AuthenticatedRoute {
@service store;

queryParams = {
page: { refreshModel: true },
seek: { refreshModel: true },
};

model(params) {
Expand Down
2 changes: 1 addition & 1 deletion app/templates/me/pending-invites.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
{{/each}}
</div>

<Pagination @pagination={{this.pagination}} />
<SeekPagination @pagination={{this.pagination}} />
12 changes: 12 additions & 0 deletions app/utils/seek-pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import macro from 'macro-decorators';

export function pagination() {
return macro(function () {
let { nextPage, totalItems } = this;

return {
nextPage,
totalItems,
};
});
}
15 changes: 0 additions & 15 deletions app/utils/seek.js

This file was deleted.

16 changes: 7 additions & 9 deletions src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn prepare_list(
Page::Unspecified => query.load(&*conn)?,
Page::Seek(s) => {
let seek_key: (i32, i32) = s.decode()?;
println!("{} {}", seek_key.0, seek_key.1);
query
.filter(
crate_owner_invitations::crate_id.gt(seek_key.0).or(
Expand All @@ -154,15 +155,12 @@ fn prepare_list(
raw_invitations.pop();

if let Some(last) = raw_invitations.last() {
let mut params = IndexMap::new();
params.insert(
"seek".into(),
crate::controllers::helpers::pagination::encode_seek((
last.crate_id,
last.invited_user_id,
))?,
);
Some(req.query_with_params(params))
let seek_key = crate::controllers::helpers::pagination::encode_seek((
last.crate_id,
last.invited_user_id,
))?;

Some(seek_key)
} else {
None
}
Expand Down

0 comments on commit 36c2d62

Please sign in to comment.