Issue #168: youtube-like marking of comments (#297)

* youtube-like marking of comments

uses GET parameters to mark comments similar to youtube

* place link to comment in 'comment-date'

* Use a routes to highight a comment
This commit is contained in:
jonathanraes 2018-02-18 09:57:26 +01:00 committed by Chocobozzz
parent 16f1657097
commit d5b53822ae
5 changed files with 40 additions and 3 deletions

View File

@ -2,9 +2,10 @@
<img [src]="getAvatarUrl(comment.account)" alt="Avatar" /> <img [src]="getAvatarUrl(comment.account)" alt="Avatar" />
<div class="comment"> <div class="comment">
<span class="marked-comment" *ngIf="comment.marked">Marked comment</span>
<div class="comment-account-date"> <div class="comment-account-date">
<a target="_blank" [href]="comment.account.url" class="comment-account">{{ comment.by }}</a> <a target="_blank" [href]="comment.account.url" class="comment-account">{{ comment.by }}</a>
<div class="comment-date">{{ comment.createdAt | myFromNow }}</div> <a [routerLink]="['/videos/watch', video.uuid, 'comment', comment.id]" class="comment-date">{{ comment.createdAt | myFromNow }}</a>
</div> </div>
<div class="comment-html" [innerHTML]="sanitizedCommentHTML"></div> <div class="comment-html" [innerHTML]="sanitizedCommentHTML"></div>

View File

@ -32,6 +32,13 @@
} }
} }
.marked-comment {
background-color: #F5F5F5;
padding-left: 3px;
padding-right: 3px;
font-size: 12px;
}
.comment-html { .comment-html {
a { a {
@include disable-default-a-behaviour; @include disable-default-a-behaviour;

View File

@ -13,8 +13,8 @@ export class VideoComment implements VideoCommentServerModel {
updatedAt: Date | string updatedAt: Date | string
account: AccountInterface account: AccountInterface
totalReplies: number totalReplies: number
by: string by: string
marked = false
constructor (hash: VideoCommentServerModel) { constructor (hash: VideoCommentServerModel) {
this.id = hash.id this.id = hash.id

View File

@ -9,6 +9,7 @@ import { SortField } from '../../../shared/video/sort-field.type'
import { VideoDetails } from '../../../shared/video/video-details.model' import { VideoDetails } from '../../../shared/video/video-details.model'
import { VideoComment } from './video-comment.model' import { VideoComment } from './video-comment.model'
import { VideoCommentService } from './video-comment.service' import { VideoCommentService } from './video-comment.service'
import { ActivatedRoute } from '@angular/router'
@Component({ @Component({
selector: 'my-video-comments', selector: 'my-video-comments',
@ -29,12 +30,14 @@ export class VideoCommentsComponent implements OnChanges {
inReplyToCommentId: number inReplyToCommentId: number
threadComments: { [ id: number ]: VideoCommentThreadTree } = {} threadComments: { [ id: number ]: VideoCommentThreadTree } = {}
threadLoading: { [ id: number ]: boolean } = {} threadLoading: { [ id: number ]: boolean } = {}
markedCommentID: number
constructor ( constructor (
private authService: AuthService, private authService: AuthService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private confirmService: ConfirmService, private confirmService: ConfirmService,
private videoCommentService: VideoCommentService private videoCommentService: VideoCommentService,
private activatedRoute: ActivatedRoute
) {} ) {}
ngOnChanges (changes: SimpleChanges) { ngOnChanges (changes: SimpleChanges) {
@ -63,6 +66,18 @@ export class VideoCommentsComponent implements OnChanges {
res => { res => {
this.comments = this.comments.concat(res.comments) this.comments = this.comments.concat(res.comments)
this.componentPagination.totalItems = res.totalComments this.componentPagination.totalItems = res.totalComments
if (this.markedCommentID) {
// If there is a marked comment, retrieve it separately as it may not be on this page, filter to prevent duplicate
this.comments = this.comments.filter(value => value.id !== this.markedCommentID)
this.videoCommentService.getVideoThreadComments(this.video.id, this.markedCommentID).subscribe(
res => {
let comment = new VideoComment(res.comment)
comment.marked = true
this.comments.unshift(comment) // Insert marked comment at the beginning
}
)
}
}, },
err => this.notificationsService.error('Error', err.message) err => this.notificationsService.error('Error', err.message)
@ -163,6 +178,15 @@ export class VideoCommentsComponent implements OnChanges {
this.componentPagination.currentPage = 1 this.componentPagination.currentPage = 1
this.componentPagination.totalItems = null this.componentPagination.totalItems = null
// Find marked comment in params
this.activatedRoute.params.subscribe(
params => {
if (params['commentId']) {
this.markedCommentID = +params['commentId']
}
}
)
this.loadMoreComments() this.loadMoreComments()
} }
} }

View File

@ -10,6 +10,11 @@ const videoWatchRoutes: Routes = [
path: '', path: '',
component: VideoWatchComponent, component: VideoWatchComponent,
canActivate: [ MetaGuard ] canActivate: [ MetaGuard ]
},
{
path: 'comment/:commentId',
component: VideoWatchComponent,
canActivate: [ MetaGuard ]
} }
] ]