Add posting variable controlling the feed-post-input

master
Max 4 years ago
parent 708f2d723f
commit 8f8a9cf64e

@ -63,6 +63,9 @@ export class FeedComponent implements OnInit {
this.feedService.postsAvailable.subscribe(available => { this.feedService.postsAvailable.subscribe(available => {
this.loadingMostLiked = this.loadingNew = 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) { if (postElement && activityId && this.checked) {
this.posting = true; this.posting = true;
this.feedService.createPostActivity(postElement.value, activityId, this.file).subscribe(() => { this.feedService.createPostActivity(postElement.value, activityId, this.file).subscribe(() => {
this.posting = false;
postElement.value = ''; postElement.value = '';
this.textInputValue = ''; this.textInputValue = '';
this.checked = false; this.checked = false;
@ -85,14 +87,12 @@ export class FeedComponent implements OnInit {
this.showNew(); this.showNew();
} }
}, (error: IErrorResponse) => { }, (error: IErrorResponse) => {
this.posting = false;
this.errorOccurred = true; this.errorOccurred = true;
this.errorMessage = error.error.errors[0].message; this.errorMessage = error.error.errors[0].message;
}); });
} else if (postElement) { } else if (postElement) {
this.posting = true; this.posting = true;
this.feedService.createPost(postElement.value, this.file).subscribe((result) => { this.feedService.createPost(postElement.value, this.file).subscribe((result) => {
this.posting = false;
postElement.value = ''; postElement.value = '';
this.textInputValue = ''; this.textInputValue = '';
this.checked = false; this.checked = false;
@ -104,7 +104,6 @@ export class FeedComponent implements OnInit {
} }
}, (error: IErrorResponse) => { }, (error: IErrorResponse) => {
console.log(error); console.log(error);
this.posting = false;
this.errorOccurred = true; this.errorOccurred = true;
this.errorMessage = error.error.errors[0].message; this.errorMessage = error.error.errors[0].message;
}); });

@ -109,6 +109,7 @@ export class FeedService extends BaseService {
} }
public postsAvailable = new BehaviorSubject<boolean>(true); public postsAvailable = new BehaviorSubject<boolean>(true);
public posting = new BehaviorSubject<boolean>(false);
public posts: BehaviorSubject<Post[]> = new BehaviorSubject([]); public posts: BehaviorSubject<Post[]> = new BehaviorSubject([]);
private activePostList: Sort = Sort.NEW; private activePostList: Sort = Sort.NEW;
private offset = 0; private offset = 0;
@ -186,6 +187,7 @@ export class FeedService extends BaseService {
* @param file - a file that is being uploaded with the post * @param file - a file that is being uploaded with the post
*/ */
private createPostRequest(body: { variables: any; query: string }, file?: File) { private createPostRequest(body: { variables: any; query: string }, file?: File) {
this.posting.next(true);
if (file) { if (file) {
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
@ -197,8 +199,10 @@ export class FeedService extends BaseService {
post.mediaType = result.fileName.endsWith('.png') ? 'IMAGE' : 'VIDEO'; post.mediaType = result.fileName.endsWith('.png') ? 'IMAGE' : 'VIDEO';
updatedPosts.unshift(post); updatedPosts.unshift(post);
this.posts.next(updatedPosts); this.posts.next(updatedPosts);
this.posting.next(false);
}, error => { }, error => {
console.error(error); console.error(error);
this.posting.next(false);
this.deletePost(post.id); this.deletePost(post.id);
}); });
} }
@ -206,6 +210,7 @@ export class FeedService extends BaseService {
} else if (!file) { } else if (!file) {
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
this.posting.next(false);
const updatedPosts = this.posts.getValue(); const updatedPosts = this.posts.getValue();
if (this.activePostList === Sort.NEW) { if (this.activePostList === Sort.NEW) {
const post = this.constructPost(response); const post = this.constructPost(response);

Loading…
Cancel
Save