From d0c067d9ed5e164decf85b5ffd78e73642b9b829 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Jan 2020 20:54:29 +0100 Subject: [PATCH 1/3] Fix friend link bug --- src/app/components/social/friends/friends.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/social/friends/friends.component.html b/src/app/components/social/friends/friends.component.html index 913d661..9d011ec 100644 --- a/src/app/components/social/friends/friends.component.html +++ b/src/app/components/social/friends/friends.component.html @@ -17,7 +17,7 @@ -
+
{{friend.name}} From d8a2438761ec854165503833c3aa9f0209ae9666 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Jan 2020 21:08:16 +0100 Subject: [PATCH 2/3] Fix issue where media didn't load on profile page --- src/app/services/feed/feed.service.ts | 6 ++-- src/app/services/profile/profile.service.ts | 39 +++------------------ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index 0535ed7..1333f15 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -289,7 +289,7 @@ export class FeedService extends BaseService { {headers: this.headers}) .pipe(this.retryRated()) .subscribe(response => { - this.posts.next(this.constructAllPosts(response)); + this.posts.next(this.constructAllPosts(response.data.getPosts)); this.activePostList = sort; }); } @@ -303,7 +303,7 @@ export class FeedService extends BaseService { this.http.post(environment.graphQLUrl, body, {headers: this.headers}) .pipe(this.retryRated()) .subscribe(response => { - const posts = this.constructAllPosts(response); + const posts = this.constructAllPosts(response.data.getPosts); const previousPosts = this.posts.getValue(); for (const post of previousPosts.reverse()) { if (!posts.find(p => p.id === post.id)) { @@ -360,7 +360,7 @@ export class FeedService extends BaseService { public constructAllPosts(response: any): Post[] { const posts = new Array(); - for (const post of response.data.getPosts) { + for (const post of response) { let profilePicture: string; if (post.author.profilePicture) { profilePicture = environment.greenvironmentUrl + post.author.profilePicture; diff --git a/src/app/services/profile/profile.service.ts b/src/app/services/profile/profile.service.ts index 809cb71..a808a16 100644 --- a/src/app/services/profile/profile.service.ts +++ b/src/app/services/profile/profile.service.ts @@ -7,6 +7,7 @@ import {User} from 'src/app/models/user'; import {Subject} from 'rxjs'; import {Activity} from 'src/app/models/activity'; import {BaseService} from '../base.service'; +import {FeedService} from 'src/app/services/feed/feed.service'; const graphqlGetProfileQuery = `query($userId: ID) { getUser(userId:$userId){ @@ -30,6 +31,7 @@ const graphqlGetProfileQuery = `query($userId: ID) { downvotes, userVote, deletable, + media {url, type}, activity{ id name @@ -39,7 +41,7 @@ const graphqlGetProfileQuery = `query($userId: ID) { author{ name, handle, - profilePicture + profilePicture, id}, createdAt } @@ -51,7 +53,7 @@ const graphqlGetProfileQuery = `query($userId: ID) { }) export class ProfileService extends BaseService { - constructor(http: HttpClient) { + constructor(http: HttpClient, private feedService: FeedService) { super(http); } @@ -96,38 +98,7 @@ export class ProfileService extends BaseService { const temp = new Date(Number(response.data.getUser.joinedAt)); const date = temp.toLocaleString('en-GB'); profile.joinedAt = date; - for (const post of response.data.getUser.posts) { - const id: number = post.id; - const content: string = post.content; - const htmlContent: string = post.htmlContent; - const upvotes: number = post.upvotes; - const downvotes: number = post.downvotes; - const userVote: string = post.userVote; - const deletable: boolean = post.deletable; - let profilePicture: string; - if (post.author.profilePicture) { - profilePicture = environment.greenvironmentUrl + post.author.profilePicture; - } else { - profilePicture = 'assets/images/default-profilepic.svg'; - } - const author = new Author(post.author.id, post.author.name, post.author.handle, profilePicture); - const ptemp = new Date(Number(post.createdAt)); - const pdate = ptemp.toLocaleString('en-GB'); - let activity: Activity; - if (post.activity) { - activity = new Activity( - post.activity.id, - post.activity.name, - post.activity.description, - post.activity.points); - } else { - activity = null; - } - - // tslint:disable-next-line: max-line-length - posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, pdate, author, activity)); - } - profile.posts = posts; + profile.posts = this.feedService.constructAllPosts(response.data.getUser.posts); return profile; } return null; From dbbfc470eb587cf124969a06cac65dcb2fd7153d Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Jan 2020 21:38:42 +0100 Subject: [PATCH 3/3] Change function in feedService --- src/app/services/feed/feed.service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index 1333f15..9f0a8fd 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -192,21 +192,22 @@ export class FeedService extends BaseService { return this.postGraphql(body, null, 0) .pipe(tap(response => { const updatedPosts = this.posts.getValue(); - if (this.activePostList === Sort.NEW) { - const post = this.constructPost(response); - this.uploadPostImage(post.id, file).subscribe((result) => { + const post = this.constructPost(response); + this.uploadPostImage(post.id, file).subscribe((result) => { + if (this.activePostList === Sort.NEW) { post.mediaUrl = result.fileName; 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); }); } - })); + )); } else if (!file) { return this.postGraphql(body, null, 0) .pipe(tap(response => {