From 8f8a9cf64e5f1329827d9e02eddc5072d1b55e32 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Jan 2020 18:23:04 +0100 Subject: [PATCH] Add posting variable controlling the feed-post-input --- src/app/components/feed/feed.component.ts | 7 +++---- src/app/services/feed/feed.service.ts | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index 2dad603..6461e4d 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -63,6 +63,9 @@ export class FeedComponent implements OnInit { this.feedService.postsAvailable.subscribe(available => { this.loadingMostLiked = this.loadingNew = available; }); + this.feedService.posting.subscribe(posting => { + this.posting = posting; + }); } /** @@ -74,7 +77,6 @@ export class FeedComponent implements OnInit { if (postElement && activityId && this.checked) { this.posting = true; this.feedService.createPostActivity(postElement.value, activityId, this.file).subscribe(() => { - this.posting = false; postElement.value = ''; this.textInputValue = ''; this.checked = false; @@ -85,14 +87,12 @@ export class FeedComponent implements OnInit { this.showNew(); } }, (error: IErrorResponse) => { - this.posting = false; this.errorOccurred = true; this.errorMessage = error.error.errors[0].message; }); } else if (postElement) { this.posting = true; this.feedService.createPost(postElement.value, this.file).subscribe((result) => { - this.posting = false; postElement.value = ''; this.textInputValue = ''; this.checked = false; @@ -104,7 +104,6 @@ export class FeedComponent implements OnInit { } }, (error: IErrorResponse) => { console.log(error); - this.posting = false; this.errorOccurred = true; this.errorMessage = error.error.errors[0].message; }); diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index 7b13fd5..0535ed7 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -109,6 +109,7 @@ export class FeedService extends BaseService { } public postsAvailable = new BehaviorSubject(true); + public posting = new BehaviorSubject(false); public posts: BehaviorSubject = new BehaviorSubject([]); private activePostList: Sort = Sort.NEW; private offset = 0; @@ -186,6 +187,7 @@ export class FeedService extends BaseService { * @param file - a file that is being uploaded with the post */ private createPostRequest(body: { variables: any; query: string }, file?: File) { + this.posting.next(true); if (file) { return this.postGraphql(body, null, 0) .pipe(tap(response => { @@ -197,8 +199,10 @@ export class FeedService extends BaseService { post.mediaType = result.fileName.endsWith('.png') ? 'IMAGE' : 'VIDEO'; updatedPosts.unshift(post); this.posts.next(updatedPosts); + this.posting.next(false); }, error => { console.error(error); + this.posting.next(false); this.deletePost(post.id); }); } @@ -206,6 +210,7 @@ export class FeedService extends BaseService { } else if (!file) { return this.postGraphql(body, null, 0) .pipe(tap(response => { + this.posting.next(false); const updatedPosts = this.posts.getValue(); if (this.activePostList === Sort.NEW) { const post = this.constructPost(response);