]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/comment/video-comments.component.ts
Delete highlighted comment too if needed
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comments.component.ts
index 72f66ff09687eac108d04db4efca60cf1685d345..3707a40948d528294efda9d27b948b328f78d5f7 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'
+import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef } from '@angular/core'
 import { ActivatedRoute } from '@angular/router'
 import { ConfirmService } from '@app/core'
 import { NotificationsService } from 'angular2-notifications'
@@ -19,6 +19,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
   styleUrls: ['./video-comments.component.scss']
 })
 export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
+  @ViewChild('commentHighlightBlock') commentHighlightBlock: ElementRef
   @Input() video: VideoDetails
   @Input() user: User
 
@@ -76,7 +77,16 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
           this.threadComments[commentId] = res
           this.threadLoading[commentId] = false
 
-          if (highlightThread) this.highlightedThread = new VideoComment(res.comment)
+          if (highlightThread) {
+            this.highlightedThread = new VideoComment(res.comment)
+
+            // Scroll to the highlighted thread
+            setTimeout(() => {
+              // -60 because of the fixed header
+              const scrollY = this.commentHighlightBlock.nativeElement.offsetTop - 60
+              window.scroll(0, scrollY)
+            }, 500)
+          }
         },
 
         err => this.notificationsService.error(this.i18n('Error'), err.message)
@@ -138,6 +148,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
           // Delete the thread
           this.comments = this.comments.filter(c => c.id !== commentToDelete.id)
           this.componentPagination.totalItems--
+
+          if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined
         },
 
         err => this.notificationsService.error(this.i18n('Error'), err.message)