ソースを参照

infinte scroll for user page

David Thornley 6 年 前
コミット
12a1236d0a
共有5 個のファイルを変更した79 個の追加38 個の削除を含む
  1. 5
    3
      zlg/src/pages/home/home.html
  2. 1
    18
      zlg/src/pages/home/home.ts
  3. 20
    7
      zlg/src/pages/userfeed/userfeed.html
  4. 51
    8
      zlg/src/pages/userfeed/userfeed.ts
  5. 2
    2
      zlg/src/providers/user/userProvider.ts

+ 5
- 3
zlg/src/pages/home/home.html ファイルの表示

2
   <ion-navbar>
2
   <ion-navbar>
3
         <br>
3
         <br>
4
         <button ion-button menuToggle><ion-icon name="menu"></ion-icon></button>
4
         <button ion-button menuToggle><ion-icon name="menu"></ion-icon></button>
5
-    <ion-title align="middle">The Vault</ion-title>
5
+    <ion-title align=right>The Vault</ion-title>
6
   </ion-navbar>
6
   </ion-navbar>
7
 </ion-header>
7
 </ion-header>
8
 
8
 
20
     <button (click)="sendPost()" id="myVault-button18" style="font-weight:600;font-size:20px;" class="codystar button button-royal button-block button-small">Post</button>
20
     <button (click)="sendPost()" id="myVault-button18" style="font-weight:600;font-size:20px;" class="codystar button button-royal button-block button-small">Post</button>
21
   </div>
21
   </div>
22
   
22
   
23
-  <div id="myVault-markdown4" class="show-list-numbers-and-dots overflow-box" style="overflow-y: scroll; height: 55vh;">
23
+  <div id="myVault-markdown4" class="show-list-numbers-and-dots overflow-box" style="overflow-y: scroll; height: 50vh;">
24
       <div style="color:#FFFFFF;list-style-type: none;" *ngFor="let p of posts">
24
       <div style="color:#FFFFFF;list-style-type: none;" *ngFor="let p of posts">
25
-        <button (click)="goToUsersFeed(p)" class="button button-block" style="background-color:lightgray;text-align: left; word-wrap: break-word; white-space: normal"><strong>{{ p.userName }}: </strong>{{ p.message }}</button>
25
+        <button (click)="goToUsersFeed(p)" class="button button-block" style="background-color:lightgray;text-align: left; word-wrap: break-word; white-space: normal"><strong>{{ p.userName }}: </strong>{{ p.message }}
26
+        <p> Posted: {{ p.createdAt |date:'dd/MM/yyyy H:mm' }}</p>
27
+      </button>
26
       </div>
28
       </div>
27
   </div>
29
   </div>
28
 
30
 

+ 1
- 18
zlg/src/pages/home/home.ts ファイルの表示

37
     this.connect();  
37
     this.connect();  
38
   }
38
   }
39
 
39
 
40
-//   connect() {
41
-//     const socket = new SockJS('https://fast-headland-39537.herokuapp.com/vault-socket');
42
-//     this.stompClient = Stomp.over(socket);
43
-
44
-//     this.stompClient.connect({}, (frame) => {
45
-//       console.log('Connected: ' + frame);
46
-//       this.stompClient.subscribe('/topic/posts', (post) => {
47
-//         this.posts.unshift(JSON.parse(post.body)));
48
-//       _this.stompClient.subscribe('/topic/posts', (post) => {
49
-//         _this.posts.unshift(JSON.parse(post.body));
50
-//      });
51
-//     }
52
-//   }
53
-//   );
54
-  
55
-// }
56
-
57
 connect() {
40
 connect() {
58
   const socket = new SockJS('https://fast-headland-39537.herokuapp.com/vault-socket');
41
   const socket = new SockJS('https://fast-headland-39537.herokuapp.com/vault-socket');
59
   this.stompClient = Stomp.over(socket);
42
   this.stompClient = Stomp.over(socket);
106
 
89
 
107
   goToUsersFeed(post) {
90
   goToUsersFeed(post) {
108
     console.log(post.id);
91
     console.log(post.id);
109
-    let params = {id: post.userId};
92
+    let params = {id: post.userId, name: post.userName};
110
     this.navCtrl.push('UserfeedPage', params);
93
     this.navCtrl.push('UserfeedPage', params);
111
   }
94
   }
112
 
95
 

+ 20
- 7
zlg/src/pages/userfeed/userfeed.html ファイルの表示

7
 <ion-header>
7
 <ion-header>
8
 
8
 
9
   <ion-navbar>
9
   <ion-navbar>
10
-    <ion-title align = "middle"><strong>{{user.name}}'s</strong> Vault</ion-title>
10
+    <ion-title align=right><strong>{{userName}}'s</strong> Vault</ion-title>
11
   </ion-navbar>
11
   </ion-navbar>
12
 </ion-header>
12
 </ion-header>
13
 
13
 
14
 
14
 
15
 <ion-content padding="true" style="background: url(../assets/img/0iNAJ9CJQ1qT57JTEweX_palePurpVault.png) no-repeat center;background-size:cover;" class="has-header">
15
 <ion-content padding="true" style="background: url(../assets/img/0iNAJ9CJQ1qT57JTEweX_palePurpVault.png) no-repeat center;background-size:cover;" class="has-header">
16
   <ion-card-content text-center>
16
   <ion-card-content text-center>
17
-      <ion-img src = "/assets/img/tom.jpg" width="250" height = "250"></ion-img>
17
+      <ion-img src = "/assets/img/tom.jpg" width="125" height = "125"></ion-img>
18
   </ion-card-content>
18
   </ion-card-content>
19
 
19
 
20
-
20
+<!-- 
21
   <ion-list>
21
   <ion-list>
22
-    <!-- <ion item *ngFor= "let post of feed"> -->
23
-    <ion-item>
22
+    <div style= "overflow-y:scroll">
23
+    <ion-item *ngFor= "let post of postArr">
24
       <h2>{{post.message}}</h2>
24
       <h2>{{post.message}}</h2>
25
       <p>
25
       <p>
26
-          {{post.timestamp}}
26
+          {{post.createdAt}}
27
       </p>
27
       </p>
28
     </ion-item>
28
     </ion-item>
29
-  </ion-list>
29
+  </div>
30
+  </ion-list> -->
31
+  <div id="myVault-markdown4" class="show-list-numbers-and-dots overflow-box" style="overflow-y: scroll; height: 60vh;">
32
+      <div style="color:#FFFFFF;list-style-type: none;" *ngFor="let post of postArr">
33
+        <ion-item class="button button-block" style="background-color:lightgray;text-align: left; word-wrap: break-word; white-space: normal; cursor:none; ">{{ post.message }}
34
+        <p> Posted: {{post.createdAt |date:'MM/dd/yyyy H:mm'}}</p>
35
+        </ion-item>
36
+      </div>
37
+  </div>
38
+
39
+<ion-infinite-scroll (ionInfinite)="doInfinite($event)" *ngIf="page < totalPage">
40
+  <ion-infinite-scroll-content loadingSpinner="bubbles" loadingText="Loading more data..." style="color:lightgray"></ion-infinite-scroll-content>
41
+</ion-infinite-scroll>
42
+
30
 </ion-content>
43
 </ion-content>

+ 51
- 8
zlg/src/pages/userfeed/userfeed.ts ファイルの表示

15
   templateUrl: 'userfeed.html',
15
   templateUrl: 'userfeed.html',
16
 })
16
 })
17
 export class UserfeedPage {
17
 export class UserfeedPage {
18
-  //user: any;
19
-  user= {name:'Froilanda'};
18
+  userName: string;
20
   post= {timestamp: '3:19PM Sun August 5th 2018',message:'hello world'};
19
   post= {timestamp: '3:19PM Sun August 5th 2018',message:'hello world'};
21
   userid: any;
20
   userid: any;
22
   postArr: Array<any>;
21
   postArr: Array<any>;
22
+  data: any;
23
+  errorMessage: string;
24
+  page = 0;
25
+  perPage = 0;
26
+  totalData = 0;
27
+  totalPage = 0;
23
 
28
 
24
   constructor(public navCtrl: NavController, public navParams: NavParams,
29
   constructor(public navCtrl: NavController, public navParams: NavParams,
25
               public UserProvider: UserProvider) {
30
               public UserProvider: UserProvider) {
26
     //this.user.name = this.navParams.get('name');
31
     //this.user.name = this.navParams.get('name');
27
     this.userid = this.navParams.get('id');
32
     this.userid = this.navParams.get('id');
33
+    this.userName = this.navParams.get('name');
34
+    this.getAllPostsByUserId();
28
   }
35
   }
29
 
36
 
30
   ionViewDidLoad() {
37
   ionViewDidLoad() {
31
     console.log('ionViewDidLoad UserfeedPage');
38
     console.log('ionViewDidLoad UserfeedPage');
39
+    this.getAllPostsByUserId();
32
   }
40
   }
33
 
41
 
34
-  getAllPostsByUserId(){
35
-    return this.UserProvider.getAllPostsByUserId(this.userid).subscribe(response => {
36
-      console.log("response: " + response);
37
-      this.postArr = response;
38
-      console.log("postarr: " + this.postArr);
39
-    });
42
+  // getAllPostsByUserId(){
43
+  //   return this.UserProvider.getAllPostsByUserId(this.userid).subscribe(response => {
44
+  //     console.log("response: " + response);
45
+  //     this.postArr = response;
46
+  //     console.log("postarr: " + this.postArr);
47
+  //   });
48
+  // }
49
+
50
+  getAllPostsByUserId() {
51
+    this.UserProvider.getAllPostsByUserId(this.page, this.userid)
52
+       .subscribe(
53
+         res => {
54
+           console.log(res)
55
+           this.data = res;
56
+           this.postArr = this.data.content;
57
+           this.perPage = this.data.size;
58
+           this.totalData = this.data.totalElements;
59
+           this.totalPage = this.data.totalPages;
60
+         },
61
+         error =>  this.errorMessage = <any>error);
62
+  }
63
+
64
+  doInfinite(infiniteScroll) {
65
+    this.page = this.page+1;
66
+    setTimeout(() => {
67
+      this.UserProvider.getAllPostsByUserId(this.page, this.userid)
68
+         .subscribe(
69
+           res => {
70
+             this.data = res;
71
+             this.perPage = this.data.size;
72
+             this.totalData = this.data.totalElements;
73
+             this.totalPage = this.data.totalPages;
74
+             for(let i=0; i<this.data.content.length; i++) {
75
+               this.postArr.push(this.data.content[i]);
76
+             }
77
+           },
78
+           error =>  this.errorMessage = <any>error);
79
+  
80
+      console.log('Async operation has ended');
81
+      infiniteScroll.complete();
82
+    }, 1000);
40
   }
83
   }
41
 
84
 
42
 
85
 

+ 2
- 2
zlg/src/providers/user/userProvider.ts ファイルの表示

12
   constructor(public http: HttpClient) {
12
   constructor(public http: HttpClient) {
13
   }
13
   }
14
 
14
 
15
-  getAllPostsByUserId(id: string):Observable<any> {
16
-    return this.http.get(this.USER_API + id);
15
+  getAllPostsByUserId(page: number, id: string):Observable<any> {
16
+    return this.http.get(this.USER_API + id + "/?page="+ page);
17
   }
17
   }
18
 }
18
 }