1
1
import { inject } from 'aurelia-framework' ;
2
2
import { AuthService } from 'aurelia-authentication' ;
3
3
import { NotificationService } from 'aurelia-notify' ;
4
+ import { DataListController } from 'resources/features/data-list/controller' ;
4
5
import { NewsService } from '../../services/news/news-service' ;
5
6
import { NewsCommentsService } from '../../services/news/news-comments-service' ;
6
7
7
8
const ENTER_KEY = 13 ;
8
9
9
10
@inject ( NewsService , NewsCommentsService , AuthService , NotificationService )
10
11
export class View {
11
- loading = false ;
12
-
13
12
constructor ( newsService , newsCommentsService , authService , notificationService ) {
14
13
this . newsService = newsService ;
15
14
this . newsCommentsService = newsCommentsService ;
16
15
this . authService = authService ;
17
16
this . notificationService = notificationService ;
17
+
18
+ this . dataListController = new DataListController ( options => this . loadMore ( options ) ) ;
18
19
}
19
20
20
21
activate ( params , routeConfig ) {
@@ -28,16 +29,6 @@ export class View {
28
29
this . user = null ;
29
30
} ) ;
30
31
31
- let commentsPromise = this . newsCommentsService . getAll ( params . id )
32
- . then ( comments => {
33
- this . comments = comments . data ;
34
- this . currentPage = comments . current_page ;
35
- this . lastPage = comments . last_page ;
36
- } )
37
- . catch ( ( ) => {
38
- this . comments = [ ] ;
39
- } ) ;
40
-
41
32
let newsPromise = this . newsService . get ( params . id )
42
33
. then ( news => {
43
34
this . news = news ;
@@ -47,7 +38,7 @@ export class View {
47
38
this . news = null ;
48
39
} ) ;
49
40
50
- return Promise . all ( [ userPromise , commentsPromise , newsPromise ] ) ;
41
+ return Promise . all ( [ userPromise , newsPromise ] ) ;
51
42
}
52
43
53
44
onKeyUp ( event ) {
@@ -78,19 +69,8 @@ export class View {
78
69
} ) ;
79
70
}
80
71
81
- loadMore ( ) {
82
- this . loading = true ;
83
- this . newsCommentsService . getAll ( this . newsId , this . currentPage + 1 )
84
- . then ( comments => {
85
- this . comments = this . comments . concat ( comments . data ) ;
86
- this . currentPage = comments . current_page ;
87
- this . lastPage = comments . last_page ;
88
- this . loading = false ;
89
- } )
90
- . catch ( ( ) => {
91
- this . comments = [ ] ;
92
- this . loading = false ;
93
- } ) ;
72
+ loadMore ( page ) {
73
+ return this . newsCommentsService . getAll ( this . newsId , page ) ;
94
74
}
95
75
96
76
get isAuthenticated ( ) {
0 commit comments