Add posting variable controlling the feed-post-input

master
Max 5 years ago
parent 708f2d723f
commit 8f8a9cf64e

@ -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;
});

@ -109,6 +109,7 @@ export class FeedService extends BaseService {
}
public postsAvailable = new BehaviorSubject<boolean>(true);
public posting = new BehaviorSubject<boolean>(false);
public posts: BehaviorSubject<Post[]> = 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);

Loading…
Cancel
Save