blob: fa5ac2f33e5c9b8c71100d38e2c7b88f9ee5b07a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import { Component, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Guid } from 'guid-typescript';
import { PostService } from 'src/app/services/post.service';
import { UserService } from 'src/app/services/user.service';
import { User } from 'src/models/identity/user.model';
import { Post } from 'src/models/post.model';
@Component({
selector: 'app-post',
templateUrl: './post.component.html',
styleUrls: ['./post.component.css'],
})
export class PostComponent implements OnInit {
public loaded = false;
public user: User;
public post: Post;
public votesNumber: number;
public timeCreated: string;
@Input() paramId: string;
constructor(private _postService: PostService, private _userService: UserService, private _router: Router)
{ }
ngOnInit(): void {
this.post = this._postService.getDefaultPost();
this.user = this._userService.getDefaultUser();
this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe({
next: (result: object) => {
Object.assign(this.post, result);
this.post.fileURLs = Object.values(result)[7];
this.votesNumber = 23;
this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB');
this.loadUser();
}
});
}
private loadUser(): void {
this._userService.getUserByUsernameRequest(this.post.creatorUsername).subscribe({
next: (result: object) => {
Object.assign(this.user, result);
this.loaded = true;
}
});
}
goToAuthorProfile(): void {
this._router.navigate(['/profile/' + this.user.userName]);
}
goToPostPage(): void {
this._router.navigate(['/post/' + this.post.postId]);
}
}
|