Skip to content

Commit b6e54ed

Browse files
committed
modify default perPage && load more reactions
1 parent 90cf871 commit b6e54ed

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Type: `object`
103103
- desc: An optional description for your page, used in issue's body. Default `''`.
104104
- labels: An optional array of labels your want to add when creating the issue. Default `[]`.
105105
- theme: An optional Gitment theme object. Default `gitment.defaultTheme`.
106-
- perPage: An optional number to which comments will be paginated. Default `30`.
106+
- perPage: An optional number to which comments will be paginated. Default `20`.
107107
- maxCommentHeight: An optional number to limit comments' max height, over which comments will be folded. Default `250`.
108108

109109
### gitment.render([element])

src/gitment.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Gitment {
5656
labels: [],
5757
theme: defaultTheme,
5858
oauth: {},
59-
perPage: 30,
59+
perPage: 20,
6060
maxCommentHeight: 250,
6161
}, options)
6262

@@ -172,6 +172,14 @@ class Gitment {
172172
post(body) {
173173
return this.getIssue()
174174
.then(issue => http.post(issue.comments_url, { body }, ''))
175+
.then(data => {
176+
this.state.meta.comments++
177+
const pageCount = Math.ceil(this.state.meta.comments / this.perPage)
178+
if (this.state.currentPage === pageCount) {
179+
this.state.comments.push(data)
180+
}
181+
return data
182+
})
175183
}
176184

177185
loadMeta() {
@@ -218,8 +226,8 @@ class Gitment {
218226

219227
return this.getIssue()
220228
.then((issue) => {
221-
if (!issue.reactions.heart) return []
222-
return http.get(issue.reactions.url, { content: 'heart' }, '')
229+
if (!issue.reactions.total_count) return []
230+
return http.get(issue.reactions.url, {}, '')
223231
})
224232
.then((reactions) => {
225233
this.state.reactions = reactions
@@ -237,10 +245,10 @@ class Gitment {
237245
const comentReactions = {}
238246

239247
return Promise.all(comments.map((comment) => {
240-
if (!comment.reactions.heart) return []
248+
if (!comment.reactions.total_count) return []
241249

242250
const { owner, repo } = this
243-
return http.get(`/repos/${owner}/${repo}/issues/comments/${comment.id}/reactions`, { content: 'heart' })
251+
return http.get(`/repos/${owner}/${repo}/issues/comments/${comment.id}/reactions`, {})
244252
}))
245253
.then(reactionsArray => {
246254
comments.forEach((comment, index) => {

0 commit comments

Comments
 (0)