|
@@ -6,14 +6,16 @@ import SockJS from 'sockjs-client';
|
6
|
6
|
|
7
|
7
|
|
8
|
8
|
import { NavController } from 'ionic-angular';
|
|
9
|
+import { PostServiceProvider } from '../../providers/post-service/post-service';
|
9
|
10
|
|
10
|
11
|
@Component({
|
11
|
12
|
selector: 'page-home',
|
12
|
|
- templateUrl: 'home.html'
|
|
13
|
+ templateUrl: 'home.html',
|
|
14
|
+ providers: [PostServiceProvider]
|
13
|
15
|
})
|
14
|
16
|
export class HomePage implements OnInit{
|
15
|
17
|
|
16
|
|
- constructor(public navCtrl: NavController) {
|
|
18
|
+ constructor(public navCtrl: NavController, private postProvider: PostServiceProvider) {
|
17
|
19
|
|
18
|
20
|
}
|
19
|
21
|
|
|
@@ -24,6 +26,7 @@ export class HomePage implements OnInit{
|
24
|
26
|
postInput = "";
|
25
|
27
|
|
26
|
28
|
ngOnInit() {
|
|
29
|
+ this.getAllPosts();
|
27
|
30
|
this.connect();
|
28
|
31
|
}
|
29
|
32
|
connect() {
|
|
@@ -34,13 +37,36 @@ export class HomePage implements OnInit{
|
34
|
37
|
this.stompClient.connect({}, function (frame) {
|
35
|
38
|
console.log('Connected: ' + frame);
|
36
|
39
|
_this.stompClient.subscribe('/topic/posts', (post) => {
|
37
|
|
- _this.posts.push(JSON.parse(post.body));
|
|
40
|
+ _this.posts.unshift(JSON.parse(post.body));
|
38
|
41
|
});
|
39
|
42
|
});
|
40
|
43
|
}
|
41
|
44
|
|
|
45
|
+ getAllPosts() {
|
|
46
|
+ console.log("getting posts...");
|
|
47
|
+ //let previousPosts: any[] = this.postProvider.getAllPosts();
|
|
48
|
+ this.postProvider.getAllPosts().subscribe (
|
|
49
|
+ (posts) => {
|
|
50
|
+ console.log("hello there?");
|
|
51
|
+ console.log(posts);
|
|
52
|
+ let postarray = posts as any[];
|
|
53
|
+ for (let i = 0; i < postarray.length; i++) {
|
|
54
|
+ this.posts.unshift(posts[i]);
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+ );
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ goToUsersFeed(post) {
|
|
62
|
+ let params = {id: post.userId};
|
|
63
|
+ //this.navCtrl.push('UsersFeed', params);
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+
|
42
|
67
|
sendPost() {
|
43
|
68
|
this.stompClient.send(this.userPostUrl, {}, JSON.stringify({'id': '','message': this.postInput, 'userId': this.userId}))
|
|
69
|
+ this.postInput = "";
|
44
|
70
|
}
|
45
|
71
|
|
46
|
72
|
// showPost(message, userName) {
|