From 34d75b6544c86aceaf71f2c0af5a9fdf3f132893 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Jan 2020 18:25:42 +0100 Subject: [PATCH] Improve code in feed component --- src/app/components/feed/feed.component.ts | 27 +++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index 6461e4d..44eee90 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -78,14 +78,7 @@ export class FeedComponent implements OnInit { this.posting = true; this.feedService.createPostActivity(postElement.value, activityId, this.file).subscribe(() => { postElement.value = ''; - this.textInputValue = ''; - this.checked = false; - this.file = null; - this.localFileUrl = null; - this.fileType = null; - if (this.view !== 'new') { - this.showNew(); - } + this.resetPostInput(); }, (error: IErrorResponse) => { this.errorOccurred = true; this.errorMessage = error.error.errors[0].message; @@ -94,14 +87,7 @@ export class FeedComponent implements OnInit { this.posting = true; this.feedService.createPost(postElement.value, this.file).subscribe((result) => { postElement.value = ''; - this.textInputValue = ''; - this.checked = false; - this.file = null; - this.localFileUrl = null; - this.fileType = null; - if (this.view !== 'new') { - this.showNew(); - } + this.resetPostInput(); }, (error: IErrorResponse) => { console.log(error); this.errorOccurred = true; @@ -117,6 +103,15 @@ export class FeedComponent implements OnInit { this.fileInput.nativeElement.value = ''; } + resetPostInput() { + this.textInputValue = ''; + this.checked = false; + this.discardFile(); + if (this.view !== 'new') { + this.showNew(); + } + } + onFileInputChange(event) { this.errorOccurred = false; this.errorMessage = '';