Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 786a1fb

Browse files
committed
feat(news): add pagination to comments
1 parent a2486b5 commit 786a1fb

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

scss/include/_animation.scss

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ section.au-enter-active {
33
animation: fadeIn 1s;
44
}
55

6+
.aurelia-animators > .au-enter {
7+
opacity: 0 !important;
8+
}
9+
10+
.aurelia-animators > .au-enter-active {
11+
animation: fadeIn 2s;
12+
}
13+
614
/* animation definitions */
715
@keyframes fadeIn {
816
0% {
@@ -13,4 +21,4 @@ section.au-enter-active {
1321
opacity: 1;
1422
transform: none
1523
}
16-
}
24+
}

src/services/news/news-comments-service.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class NewsCommentsService {
77
this.apiClient = apiClient;
88
}
99

10-
getRecent(newsId) {
11-
return this.apiClient.find('news/' + newsId + '/comments')
10+
getAll(newsId, page = 1) {
11+
return this.apiClient.find('news/' + newsId + '/comments', {page: page})
1212
.catch(error => Promise.reject(error));
1313
}
1414

src/view-models/news/view.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ export class View {
2424
this.user = null;
2525
});
2626

27-
let commentsPromise = this.newsCommentsService.getRecent(params.id)
27+
let commentsPromise = this.newsCommentsService.getAll(params.id)
2828
.then(comments => {
29-
this.comments = comments;
29+
this.comments = comments.data.reverse();
30+
this.currentPage = comments.current_page;
31+
this.lastPage = comments.last_page;
3032
})
3133
.catch(() => {
3234
this.comments = [];
@@ -66,6 +68,18 @@ export class View {
6668
});
6769
}
6870

71+
loadMore() {
72+
this.newsCommentsService.getAll(this.newsId, this.currentPage + 1)
73+
.then(comments => {
74+
this.comments = comments.data.reverse().concat(this.comments);
75+
this.currentPage = comments.current_page;
76+
this.lastPage = comments.last_page;
77+
})
78+
.catch(() => {
79+
this.comments = [];
80+
});
81+
}
82+
6983
get isAuthenticated() {
7084
return this.authService.isAuthenticated();
7185
}

src/views/auth/sign-in.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ <h4 class="card-title">Sign In</h4>
77
<form submit.delegate="signIn()" novalidate>
88
<div class="form-group row">
99
<label for="username" class="col-sm-2 form-control-label">Username</label>
10-
1110
<div class="col-sm-10">
1211
<input type="text" class="form-control" id="username" placeholder="Username" value.bind="username">
1312
</div>
1413
</div>
14+
1515
<div class="form-group row">
1616
<label for="password" class="col-sm-2 form-control-label">Password</label>
17-
1817
<div class="col-sm-10">
1918
<input type="password" class="form-control" id="password" placeholder="Password" value.bind="password">
2019
</div>

src/views/news/view.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ <h4><a href="#/news/view/${news.id}">${news.title}</a></h4>
2121
</div>
2222
<div class="card-text">${news.text}</div>
2323
</div>
24-
<div class="card-footer" if.bind="isAuthenticated || comments.length > 0">
25-
<div class="news-card-comment" repeat.for="item of comments">
24+
<div class="card-footer aurelia-animators" if.bind="isAuthenticated || comments.length > 0">
25+
<div class="news-card-comment">
26+
<a click.delegate="loadMore()">Load more...</a>
27+
</div>
28+
<div class="news-card-comment au-animate" repeat.for="item of comments">
2629
<a href="#/profiles/view/${item.user.id}" class="pull-left">
30+
<!-- Todo -->
2731
<img alt="${item.user.username}" src="http://lr.local/img/avatar/${item.user.avatar}">
2832
</a>
2933
<div class="media-body">
@@ -34,6 +38,7 @@ <h4><a href="#/news/view/${news.id}">${news.title}</a></h4>
3438
</div>
3539
<div class="news-card-comment" if.bind="isAuthenticated">
3640
<a href="#/profiles/view/${user.id}" class="pull-left">
41+
<!-- Todo: image path -->
3742
<img alt="${user.username}" src="http://lr.local/img/avatar/${user.avatar}">
3843
</a>
3944
<div class="media-body">

0 commit comments

Comments
 (0)