Rework comment UI

Add error popups, text field validation, move form, move comment header to footer, updated styling
This commit is contained in:
Michael Shamoon
2022-08-07 21:44:28 -07:00
parent d5018af2a3
commit 1b56ffd0c0
3 changed files with 65 additions and 57 deletions

View File

@@ -12,11 +12,12 @@ import { ToastService } from 'src/app/services/toast.service'
})
export class DocumentCommentsComponent implements OnInit {
commentForm: FormGroup = new FormGroup({
newcomment: new FormControl(''),
newComment: new FormControl(''),
})
networkActive = false
comments: PaperlessDocumentComment[] = []
newCommentError: boolean = false
@Input()
documentId: number
@@ -33,27 +34,30 @@ export class DocumentCommentsComponent implements OnInit {
.subscribe((comments) => (this.comments = comments))
}
commentId(index, comment: PaperlessDocumentComment) {
return comment.id
}
addComment() {
const comment: string = this.commentForm
.get('newComment')
.value.toString()
.trim()
if (comment.length == 0) {
this.newCommentError = true
return
}
this.newCommentError = false
this.networkActive = true
this.commentsService
.addComment(this.documentId, this.commentForm.get('newcomment').value)
.subscribe({
next: (result) => {
this.comments = result
this.commentForm.get('newcomment').reset()
this.networkActive = false
},
error: (e) => {
this.networkActive = false
this.toastService.showError(
$localize`Error saving comment: ${e.toString()}`
)
},
})
this.commentsService.addComment(this.documentId, comment).subscribe({
next: (result) => {
this.comments = result
this.commentForm.get('newComment').reset()
this.networkActive = false
},
error: (e) => {
this.networkActive = false
this.toastService.showError(
$localize`Error saving comment: ${e.toString()}`
)
},
})
}
deleteComment(commentId: number) {
@@ -70,4 +74,17 @@ export class DocumentCommentsComponent implements OnInit {
},
})
}
displayName(comment: PaperlessDocumentComment): string {
if (!comment.user) return ''
let nameComponents = []
if (comment.user.firstname) nameComponents.unshift(comment.user.firstname)
if (comment.user.lastname) nameComponents.unshift(comment.user.lastname)
if (comment.user.username) {
if (nameComponents.length > 0)
nameComponents.push(`(${comment.user.username})`)
else nameComponents.push(comment.user.username)
}
return nameComponents.join(' ')
}
}