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.feedService.postsAvailable.subscribe(available => {
this.loadingMostLiked = this.loadingNew = 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) { 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.resetPostInput();
this.checked = false;
this.file = null;
this.localFileUrl = null;
this.fileType = null;
if (this.view !== 'new') {
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) => {
console.log('response in component');
this.posting = false;
postElement.value = ''; postElement.value = '';
this.textInputValue = ''; this.resetPostInput();
this.checked = false;
this.file = null;
this.localFileUrl = null;
this.fileType = null;
if (this.view !== 'new') {
this.showNew();
}
}, (error: IErrorResponse) => { }, (error: IErrorResponse) => {
console.log('an error occured in component');
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;
}); });
@ -120,6 +103,15 @@ export class FeedComponent implements OnInit {
this.fileInput.nativeElement.value = ''; this.fileInput.nativeElement.value = '';
} }
resetPostInput() {
this.textInputValue = '';
this.checked = false;
this.discardFile();
if (this.view !== 'new') {
this.showNew();
}
}
onFileInputChange(event) { onFileInputChange(event) {
this.errorOccurred = false; this.errorOccurred = false;
this.errorMessage = ''; this.errorMessage = '';

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

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

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

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

Loading…
Cancel
Save