mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix live updating of comments on doc change
This commit is contained in:
		| @@ -6,7 +6,8 @@ | |||||||
|                 Please enter a comment. |                 Please enter a comment. | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <div class="form-group mt-2 d-flex justify-content-end"> |         <div class="form-group mt-2 d-flex justify-content-end align-items-center"> | ||||||
|  |             <div *ngIf="networkActive" class="spinner-border spinner-border-sm fw-normal me-auto" role="status"></div> | ||||||
|             <button type="button" class="btn btn-primary btn-sm" [disabled]="networkActive" (click)="addComment()" i18n>Add comment</button> |             <button type="button" class="btn btn-primary btn-sm" [disabled]="networkActive" (click)="addComment()" i18n>Add comment</button> | ||||||
|         </div> |         </div> | ||||||
|     </form> |     </form> | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import { Component, Input, OnInit } from '@angular/core' | import { Component, Input } from '@angular/core' | ||||||
| import { DocumentCommentsService } from 'src/app/services/rest/document-comments.service' | import { DocumentCommentsService } from 'src/app/services/rest/document-comments.service' | ||||||
| import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment' | import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment' | ||||||
| import { FormControl, FormGroup } from '@angular/forms' | import { FormControl, FormGroup } from '@angular/forms' | ||||||
| @@ -10,7 +10,7 @@ import { ToastService } from 'src/app/services/toast.service' | |||||||
|   templateUrl: './document-comments.component.html', |   templateUrl: './document-comments.component.html', | ||||||
|   styleUrls: ['./document-comments.component.scss'], |   styleUrls: ['./document-comments.component.scss'], | ||||||
| }) | }) | ||||||
| export class DocumentCommentsComponent implements OnInit { | export class DocumentCommentsComponent { | ||||||
|   commentForm: FormGroup = new FormGroup({ |   commentForm: FormGroup = new FormGroup({ | ||||||
|     newComment: new FormControl(''), |     newComment: new FormControl(''), | ||||||
|   }) |   }) | ||||||
| @@ -19,19 +19,30 @@ export class DocumentCommentsComponent implements OnInit { | |||||||
|   comments: PaperlessDocumentComment[] = [] |   comments: PaperlessDocumentComment[] = [] | ||||||
|   newCommentError: boolean = false |   newCommentError: boolean = false | ||||||
|  |  | ||||||
|  |   private _documentId: number | ||||||
|  |  | ||||||
|   @Input() |   @Input() | ||||||
|   documentId: number |   set documentId(id: number) { | ||||||
|  |     if (id != this._documentId) { | ||||||
|  |       this._documentId = id | ||||||
|  |       this.update() | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   constructor( |   constructor( | ||||||
|     private commentsService: DocumentCommentsService, |     private commentsService: DocumentCommentsService, | ||||||
|     private toastService: ToastService |     private toastService: ToastService | ||||||
|   ) {} |   ) {} | ||||||
|  |  | ||||||
|   ngOnInit(): void { |   update(): void { | ||||||
|  |     this.networkActive = true | ||||||
|     this.commentsService |     this.commentsService | ||||||
|       .getComments(this.documentId) |       .getComments(this._documentId) | ||||||
|       .pipe(first()) |       .pipe(first()) | ||||||
|       .subscribe((comments) => (this.comments = comments)) |       .subscribe((comments) => { | ||||||
|  |         this.comments = comments | ||||||
|  |         this.networkActive = false | ||||||
|  |       }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   addComment() { |   addComment() { | ||||||
| @@ -45,7 +56,7 @@ export class DocumentCommentsComponent implements OnInit { | |||||||
|     } |     } | ||||||
|     this.newCommentError = false |     this.newCommentError = false | ||||||
|     this.networkActive = true |     this.networkActive = true | ||||||
|     this.commentsService.addComment(this.documentId, comment).subscribe({ |     this.commentsService.addComment(this._documentId, comment).subscribe({ | ||||||
|       next: (result) => { |       next: (result) => { | ||||||
|         this.comments = result |         this.comments = result | ||||||
|         this.commentForm.get('newComment').reset() |         this.commentForm.get('newComment').reset() | ||||||
| @@ -61,7 +72,7 @@ export class DocumentCommentsComponent implements OnInit { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   deleteComment(commentId: number) { |   deleteComment(commentId: number) { | ||||||
|     this.commentsService.deleteComment(this.documentId, commentId).subscribe({ |     this.commentsService.deleteComment(this._documentId, commentId).subscribe({ | ||||||
|       next: (result) => { |       next: (result) => { | ||||||
|         this.comments = result |         this.comments = result | ||||||
|         this.networkActive = false |         this.networkActive = false | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon