Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master

master
Max_ES 5 years ago committed by Gitea
commit 1bafc60500

@ -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,39 +77,19 @@ 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;
this.file = null;
this.localFileUrl = null;
this.fileType = null;
if (this.view !== 'new') {
this.showNew();
}
this.resetPostInput();
}, (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) => {
console.log('response in component');
this.posting = false;
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('an error occured in component');
console.log(error);
this.posting = false;
this.errorOccurred = true;
this.errorMessage = error.error.errors[0].message;
});
@ -120,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 = '';

@ -22,9 +22,10 @@
</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<div class="postMedia">
<img *ngIf="post.mediaType === 'IMAGE'" [src]="post.mediaUrl" alt="post image"/>
<video *ngIf="post.mediaType === 'VIDEO'" controls>
<mat-spinner *ngIf="post.mediaLoading" style="margin:0 auto; margin-top: 2em;" diameter="50"></mat-spinner>
<div class="postMedia" [hidden]="post.mediaLoading">
<img *ngIf="post.mediaType === 'IMAGE'" [src]="post.mediaUrl" (load)="onLoad(this.post)" alt="post image"/>
<video *ngIf="post.mediaType === 'VIDEO'" (load)="onLoad(this.post)" controls>
<source [src]="post.mediaUrl" type="video/webm">
</video>
</div>

@ -49,6 +49,10 @@ export class PostlistComponent implements OnInit {
});
}
onLoad(post: Post) {
post.mediaLoading = false;
}
public showUserProfile(post: any) {
this.router.navigate(['profile/' + post.author.id]);
}

@ -13,6 +13,7 @@ export class Post {
deletable: boolean;
author: Author;
activity: Activity;
mediaLoading: boolean;
mediaUrl: string;
mediaType: 'VIDEO' | 'IMAGE';
@ -42,6 +43,7 @@ export class Post {
if (media) {
this.mediaUrl = environment.greenvironmentUrl + media.url;
this.mediaType = media.type;
this.mediaLoading = true;
}
}
}

@ -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,10 +210,11 @@ 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);
updatedPosts.unshift(post);
updatedPosts.unshift(post);
this.posts.next(updatedPosts);
}
}));

Loading…
Cancel
Save