Skip to content

Commit

Permalink
fix(voter-list): add paginate function (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenijesavic authored Jul 15, 2023
1 parent a4fbd5e commit cfea660
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/components/proposals/voter-list.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { mapActions } from 'vuex'
import gql from 'graphql-tag'
import paginate from '~/utils/paginate'
const PROPOSAL_VOTES_QUERY = `
getDocument(docId: $docId) {
Expand Down Expand Up @@ -89,17 +90,7 @@ export default {
pageCount () { return Math.ceil(this.voteCount / 5) },
votesPaginated () {
if (!this.votes || this.isLoading) return []
const startIndex = this.page * this.size
const lastIndex = startIndex + this.size
const voteCount = this.votes.length
if (voteCount >= lastIndex) {
return [...this.votes].splice(startIndex, this.size)
}
return [...this.votes].splice(startIndex / this.size, this.size)
return (!this.votes || this.isLoading) ? [] : paginate(this.votes, this.page, this.size)
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/utils/paginate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function paginate(a, pageIndex, pageSize) {
const endIndex = Math.min((pageIndex + 1) * pageSize, a.length)
return a.slice(Math.max(endIndex - pageSize, 0), endIndex)
}

0 comments on commit cfea660

Please sign in to comment.