diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-27 16:11:53 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-27 16:11:53 +0100 |
commit | 4635f59d7c3fea4b97029f10886c62fdf38b2084 (patch) | |
tree | d97357a00042bbfb33c4177ee24c01171d28dfce /client/src/app/videos/+video-watch/comment/video-comment.component.ts | |
parent | ea44f375f5d3da06ca0aebfe871b9f924a26ec29 (diff) | |
download | PeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.tar.gz PeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.tar.zst PeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.zip |
Add video comment components
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comment.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comment.component.ts | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts new file mode 100644 index 000000000..b8e2acd52 --- /dev/null +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts | |||
@@ -0,0 +1,67 @@ | |||
1 | import { Component, EventEmitter, Input, Output } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' | ||
4 | import { AuthService } from '../../../core/auth' | ||
5 | import { User } from '../../../shared/users' | ||
6 | import { Video } from '../../../shared/video/video.model' | ||
7 | import { VideoComment } from './video-comment.model' | ||
8 | import { VideoCommentService } from './video-comment.service' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-video-comment', | ||
12 | templateUrl: './video-comment.component.html', | ||
13 | styleUrls: ['./video-comment.component.scss'] | ||
14 | }) | ||
15 | export class VideoCommentComponent { | ||
16 | @Input() video: Video | ||
17 | @Input() comment: VideoComment | ||
18 | @Input() commentTree: VideoCommentThreadTree | ||
19 | @Input() inReplyToCommentId: number | ||
20 | |||
21 | @Output() wantedToReply = new EventEmitter<VideoComment>() | ||
22 | @Output() resetReply = new EventEmitter() | ||
23 | |||
24 | constructor (private authService: AuthService, | ||
25 | private notificationsService: NotificationsService, | ||
26 | private videoCommentService: VideoCommentService) { | ||
27 | } | ||
28 | |||
29 | onCommentReplyCreated (comment: VideoComment) { | ||
30 | this.videoCommentService.addCommentReply(this.video.id, this.comment.id, comment) | ||
31 | .subscribe( | ||
32 | createdComment => { | ||
33 | if (!this.commentTree) { | ||
34 | this.commentTree = { | ||
35 | comment: this.comment, | ||
36 | children: [] | ||
37 | } | ||
38 | } | ||
39 | |||
40 | this.commentTree.children.push({ | ||
41 | comment: createdComment, | ||
42 | children: [] | ||
43 | }) | ||
44 | this.resetReply.emit() | ||
45 | }, | ||
46 | |||
47 | err => this.notificationsService.error('Error', err.message) | ||
48 | ) | ||
49 | } | ||
50 | |||
51 | onWantToReply () { | ||
52 | this.wantedToReply.emit(this.comment) | ||
53 | } | ||
54 | |||
55 | isUserLoggedIn () { | ||
56 | return this.authService.isLoggedIn() | ||
57 | } | ||
58 | |||
59 | // Event from child comment | ||
60 | onWantedToReply (comment: VideoComment) { | ||
61 | this.wantedToReply.emit(comment) | ||
62 | } | ||
63 | |||
64 | onResetReply () { | ||
65 | this.resetReply.emit() | ||
66 | } | ||
67 | } | ||