diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index ef80553..73094f0 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -36,22 +36,12 @@ export class FeedComponent implements OnInit { this.data.currentUserInfo.subscribe(user => { this.user = user; this.loggedIn = user.loggedIn; - if (this.loggedIn) { - this.userId = user.userID; - this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { - this.loading = false; - this.feedNew = this.feedService.renderAllPosts(response.json()); - this.parentSelectedPostList = this.feedNew; - this.feedMostLiked = this.feedNew; - }); - } else { this.feedService.getAllPostsRaw().subscribe(response => { this.loading = false; this.feedNew = this.feedService.renderAllPosts(response.json()); this.parentSelectedPostList = this.feedNew; this.feedMostLiked = this.feedNew; }); - } }); } @@ -66,7 +56,7 @@ export class FeedComponent implements OnInit { } showNew() { - this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { + this.feedService.getAllPostsRaw().subscribe(response => { this.feedNew = this.feedService.renderAllPosts(response.json()); this.parentSelectedPostList = this.feedNew; }); this.viewNew = true; @@ -74,7 +64,7 @@ export class FeedComponent implements OnInit { } showMostLiked() { - this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { + this.feedService.getAllPostsRaw().subscribe(response => { this.feedMostLiked = this.feedService.renderAllPosts(response.json()); this.parentSelectedPostList = this.feedMostLiked; }); this.viewNew = false; @@ -83,7 +73,7 @@ export class FeedComponent implements OnInit { refresh($event) { - this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { + this.feedService.getAllPostsRaw().subscribe(response => { this.parentSelectedPostList = this.feedService.renderAllPosts(response.json()); }); } diff --git a/src/app/components/feed/postlist/postlist.component.ts b/src/app/components/feed/postlist/postlist.component.ts index bcb3afe..8209e8b 100644 --- a/src/app/components/feed/postlist/postlist.component.ts +++ b/src/app/components/feed/postlist/postlist.component.ts @@ -23,13 +23,17 @@ export class PostlistComponent implements OnInit { this.feedService.upvote(pPost.id).subscribe(response => { // this.voteEvent.emit(true); pPost.userVote = response.json().data.vote; + pPost.upvotes = response.json().data.vote.post.upvotes; + pPost.downvotes = response.json().data.vote.post.downvotes; }); } voteDown(pPost: Post) { this.feedService.downvote(pPost.id).subscribe(response => { // this.voteEvent.emit(true); - pPost.userVote = response.json().data.vote; + pPost.userVote = response.json().data.vote.post.userVote; + pPost.upvotes = response.json().data.vote.post.upvotes; + pPost.downvotes = response.json().data.vote.post.downvotes; }); } diff --git a/src/app/components/group/group.component.html b/src/app/components/group/group.component.html index 764d2a4..52f9d46 100644 --- a/src/app/components/group/group.component.html +++ b/src/app/components/group/group.component.html @@ -24,7 +24,7 @@
- created by {{groupProfile.creator.username}} @{{groupProfile.creator.handle}} + created by {{groupProfile.creator.username}} @{{groupProfile.creator.handle}}
@@ -62,6 +62,7 @@ +
@@ -76,9 +77,21 @@ {{event.name}} {{event.date}} - +
+ + +
@@ -97,7 +110,7 @@
{{user.username}} {{user.handle}} -
+
@@ -105,6 +118,7 @@
+

Group not found :(

diff --git a/src/app/components/group/group.component.sass b/src/app/components/group/group.component.sass index 649f40c..e75d22b 100644 --- a/src/app/components/group/group.component.sass +++ b/src/app/components/group/group.component.sass @@ -13,17 +13,19 @@ max-width: 1200px margin: 0 auto +#accordion + max-width: 690px + margin: 0 auto + $mat-card-header-size: 100px !default #profile-card-container margin: 0 auto width: 100% max-width: 690px - .icon-box - text-align: right - width: 100% + .button-box - width: 100% text-align: right + margin-left: auto .request-button margin: auto 0 #toolbar @@ -37,6 +39,7 @@ $mat-card-header-size: 100px !default margin-right: 3em #username margin: 0 0.5em + overflow: auto #handle font-size: 14px .profile-picture @@ -57,7 +60,6 @@ $mat-card-header-size: 100px !default outline: none user-select: none /deep/ .mat-card-header-text - width: 1000% margin: 0 margin-left: 16px .mat-card-subtitle @@ -76,7 +78,7 @@ $mat-card-header-size: 100px !default cursor: pointer .pointer cursor: pointer - + /deep/ .mat-expansion-panel background: #e6e6e6 /deep/.dark-theme .mat-expansion-panel diff --git a/src/app/components/group/group.component.ts b/src/app/components/group/group.component.ts index 6d42205..2b2e5b3 100644 --- a/src/app/components/group/group.component.ts +++ b/src/app/components/group/group.component.ts @@ -6,6 +6,7 @@ import { RequestService } from 'src/app/services/request/request.service'; import { DatasharingService } from '../../services/datasharing.service'; import { GroupService } from 'src/app/services/group/group.service'; import { Group } from 'src/app/models/group'; +import { Event } from 'src/app/models/event'; import {MatDialog, MatDialogRef} from '@angular/material/dialog'; // DIALOG COMPONENT to create events @@ -110,6 +111,20 @@ export class GroupComponent implements OnInit { this.requestService.joinGroup(group); } + public joinEvent(event: Event) { + this.groupService.joinEvent(event.id).subscribe(response => { + const pEvent = response.json().data.joinEvent; + event.joined = pEvent.joined; + }); + } + + public leaveEvent(event: Event) { + this.groupService.leaveEvent(event.id).subscribe(response => { + const pEvent = response.json().data.leaveEvent; + event.joined = pEvent.joined; + }); + } + public showUserProfile(user: User) { this.router.navigate(['profile/' + user.userID]); } diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 03fc377..8662044 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -56,11 +56,7 @@ export class ProfileComponent implements OnInit { this.data.currentUserInfo.subscribe(user => { this.self = user; }); - if (this.self.loggedIn) { - this.profileService.getUserDataBySelfId(this.id, this.self.userID.toString()); - } else { - this.profileService.getUserData(this.id); - } + this.profileService.getUserData(this.id); this.profileService.proflile.subscribe(response => { if (response) { this.userProfile = response; diff --git a/src/app/models/event.ts b/src/app/models/event.ts index 95d9151..d2e2804 100644 --- a/src/app/models/event.ts +++ b/src/app/models/event.ts @@ -1,11 +1,13 @@ export class Event { - id: number; + id: string; name: string; date: string; + joined: boolean; - constructor(pId: number, pName: string, pdate: string) { + constructor(pId: string, pName: string, pdate: string, pjoined: boolean) { this.id = pId; this.name = pName; this.date = pdate; + this.joined = pjoined; } } diff --git a/src/app/models/group.ts b/src/app/models/group.ts index 0395207..9c0ff55 100644 --- a/src/app/models/group.ts +++ b/src/app/models/group.ts @@ -9,5 +9,6 @@ export class Group { members: User[] = new Array(); admins: User[] = new Array(); events: Event[] = new Array(); + joined: boolean; allowedToJoinGroup = false; } diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index f261df2..e609837 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -29,33 +29,33 @@ export class FeedService { } public upvote(pPostID: number): any { - const url = environment.graphQLUrl; - const headers = new Headers(); headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { - vote(postId: $postId, type: UPVOTE) + vote(postId: $postId, type: UPVOTE) { + post{userVote upvotes downvotes} + } }`, variables: { postId: pPostID }}; - return this.http.post(url, body); + return this.http.post(environment.graphQLUrl, body); } public downvote(pPostID: number): any { - const url = environment.graphQLUrl; - const headers = new Headers(); headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { - vote(postId: $postId, type: DOWNVOTE) + vote(postId: $postId, type: DOWNVOTE) { + post{userVote upvotes downvotes} + } }`, variables: { postId: pPostID }}; - return this.http.post(url, body); + return this.http.post(environment.graphQLUrl, body); } public deletePost(pPostID: number): any { @@ -83,74 +83,32 @@ export class FeedService { }); return this.posts; } - public getAllPostsById(userId: number): Array { - const url = environment.graphQLUrl; - - const headers = new Headers(); - headers.set('Content-Type', 'application/json'); - - this.http.post(url, this.getBodyForGetAllPostsByUserId(userId)) - .subscribe(response => { - this.posts = this.renderAllPosts(response.json()); - }); - return this.posts; - } public getAllPostsRaw(): any { - const url = environment.graphQLUrl; - const headers = new Headers(); headers.set('Content-Type', 'application/json'); - - return this.http.post(url, this.getBodyForGetAllPosts()); + return this.http.post(environment.graphQLUrl, this.getBodyForGetAllPosts()); } - public getAllPostsRawByUserId(userId: number): any { - const url = environment.graphQLUrl; - - const headers = new Headers(); - headers.set('Content-Type', 'application/json'); - - return this.http.post(url, this.getBodyForGetAllPostsByUserId(userId)); - } - - getBodyForGetAllPostsByUserId(pUserId: number) { - const body = {query: `query ($userId: ID!) { + getBodyForGetAllPosts() { + const body = {query: `{ getPosts (first: 1000, offset: 0) { id, content, htmlContent, upvotes, downvotes, - userVote(userId: $userId), - deletable(userId: $userId) + userVote, + deletable author{ name, handle, id}, createdAt} }`, variables: { - userId: pUserId }}; return body; } - getBodyForGetAllPosts() { - const body = {query: `query { - getPosts (first: 1000, offset: 0) { - id, - content, - htmlContent, - upvotes, - downvotes, - author{ - name, - handle, - id}, - createdAt} - }` - }; - return body; - } public renderAllPosts(pResponse: any): Array { const posts = new Array(); diff --git a/src/app/services/group/group.service.ts b/src/app/services/group/group.service.ts index 0f064ba..83e0fb4 100644 --- a/src/app/services/group/group.service.ts +++ b/src/app/services/group/group.service.ts @@ -32,10 +32,11 @@ export class GroupService { getGroup(groupId:$groupId){ id name + joined creator{id name handle} admins{id name handle} members{id name handle} - events{id name dueDate} + events{id name dueDate joined} } }`, variables: { groupId: id @@ -52,6 +53,8 @@ export class GroupService { group.creator.userID = response.data.getGroup.creator.id; group.creator.handle = response.data.getGroup.creator.handle; group.creator.username = response.data.getGroup.creator.name; + group.joined = response.data.getGroup.joined; + for (const member of response.data.getGroup.members) { const user = new User(); user.userID = member.id; @@ -69,7 +72,7 @@ export class GroupService { for (const event of response.data.getGroup.events) { const temp = new Date(Number(event.dueDate)); const date = temp.toLocaleString('en-GB'); - group.events.push(new Event(event.id, event.name, date)); + group.events.push(new Event(event.id, event.name, date, event.joined)); } return group; } @@ -84,6 +87,7 @@ export class GroupService { id name dueDate + joined } }`, variables: { name: name, @@ -95,7 +99,36 @@ export class GroupService { const event = response.json().data.createEvent; const temp = new Date(Number(event.dueDate)); const pdate = temp.toLocaleString('en-GB'); - this.group.next(this.renderGroup(this.group.getValue().events.push(new Event(event.id, event.name, pdate)))); + this.group.next( + this.renderGroup(this.group.getValue().events.push(new Event(event.id, event.name, pdate, event.joined))) + ); }); } + + public joinEvent(eventId: string) { + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + const body = {query: `mutation($eventId: ID!) { + joinEvent(eventId: $eventId) { + joined + } + }`, variables: { + eventId: eventId + }}; + return this.http.post(environment.graphQLUrl, body); + } + + public leaveEvent(eventId: string) { + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + const body = {query: `mutation($eventId: ID!) { + leaveEvent(eventId: $eventId) { + joined + } + }`, variables: { + eventId: eventId + }}; + return this.http.post(environment.graphQLUrl, body); + } + } diff --git a/src/app/services/profile/profile.service.ts b/src/app/services/profile/profile.service.ts index f130b6f..d92944d 100644 --- a/src/app/services/profile/profile.service.ts +++ b/src/app/services/profile/profile.service.ts @@ -26,18 +26,6 @@ export class ProfileService { }); } - public getUserDataBySelfId(userId: string, selfId: string) { - const headers = new Headers(); - headers.set('Content-Type', 'application/json'); - // return this.renderProfile(this.http.post(environment.graphQLUrl, this.buildGetProfileJson(userId))); - this.http.post(environment.graphQLUrl, this.buildGetProfileJsonBySelfId(userId, selfId)).subscribe(result => { - // push onto subject - this.proflile.next(this.renderProfile(result.json())); - return this.proflile; - }); - } - - public buildGetProfileJson(id: string): any { const body = {query: `query($userId: ID) { getUser(userId:$userId){ @@ -59,42 +47,8 @@ export class ProfileService { htmlContent, upvotes, downvotes, - author{ - name, - handle, - id}, - createdAt - } - } - }`, variables: { - userId: id - }}; - return body; - } - - public buildGetProfileJsonBySelfId(id: string, selfId: string): any { - const body = {query: `query($userId: ID, $selfId: ID!) { - getUser(userId:$userId){ - id - handle - name - profilePicture - points - level - friendCount - groupCount - joinedAt - friends{ - id - } - posts{ - id, - content, - htmlContent, - upvotes, - downvotes, - userVote(userId: $selfId), - deletable(userId: $selfId) + userVote, + deletable, author{ name, handle, @@ -104,7 +58,6 @@ export class ProfileService { } }`, variables: { userId: id, - selfId: selfId }}; return body; }