From 6588bc6535a1f522491085f86da8f29dfabd28df Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 15 Jan 2020 18:18:31 +0100 Subject: [PATCH 1/4] Fix profilePicture reloading --- src/app/components/profile/profile.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 412b106..cd29dd3 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -73,8 +73,8 @@ export class ProfileComponent implements OnInit { formData.append('profilePicture', event.target.files[0]); this.http.post('https://greenvironment.net/upload', formData).subscribe( - async (response: Response) => { - this.userProfile.profilePicture = 'https://greenvironment.net/' + (await response.json()).filename; + (response: any) => { + this.userProfile.profilePicture = 'https://greenvironment.net/' + response.filename; }, (error) => console.log(error) ); From a80bcf9d3e20aaa5c588dc91fd2b3ab39c876795 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 15 Jan 2020 18:24:54 +0100 Subject: [PATCH 2/4] Add environment --- src/app/components/profile/profile.component.ts | 5 +++-- src/app/services/profile/profile.service.ts | 2 +- src/environments/environment.prod.ts | 3 ++- src/environments/environment.ts | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index cd29dd3..ff163ee 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -6,6 +6,7 @@ import { RequestService } from 'src/app/services/request/request.service'; import { DatasharingService } from '../../services/datasharing.service'; import { ProfileService } from 'src/app/services/profile/profile.service'; import { HttpClient } from '@angular/common/http'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-profile', @@ -72,9 +73,9 @@ export class ProfileComponent implements OnInit { const formData: any = new FormData(); formData.append('profilePicture', event.target.files[0]); - this.http.post('https://greenvironment.net/upload', formData).subscribe( + this.http.post(environment.greenvironmentUrl, formData).subscribe( (response: any) => { - this.userProfile.profilePicture = 'https://greenvironment.net/' + response.filename; + this.userProfile.profilePicture = environment.greenvironmentUrl + response.filename; }, (error) => console.log(error) ); diff --git a/src/app/services/profile/profile.service.ts b/src/app/services/profile/profile.service.ts index 3de1124..67069a7 100644 --- a/src/app/services/profile/profile.service.ts +++ b/src/app/services/profile/profile.service.ts @@ -82,7 +82,7 @@ export class ProfileService { profile.friendCount = response.data.getUser.friendCount; profile.groupCount = response.data.getUser.groupCount; if (response.data.getUser.profilePicture) { - profile.profilePicture = 'https://greenvironment.net/' + response.data.getUser.profilePicture; + profile.profilePicture = environment.greenvironmentUrl + response.data.getUser.profilePicture; } else { profile.profilePicture = 'assets/images/account_circle-24px.svg'; } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 1bcd4f6..73d5691 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,4 +1,5 @@ export const environment = { production: true, - graphQLUrl: '/graphql' + graphQLUrl: '/graphql', + greenvironmentUrl: '', }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 8ddcf48..062be1b 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,8 @@ export const environment = { production: false, - graphQLUrl: 'https://greenvironment.net/graphql' + graphQLUrl: 'https://greenvironment.net/graphql', + greenvironmentUrl: 'https://greenvironment.net/', }; /* From a881f74a4fc2df5f08a1f3dccaf7117e1f370e66 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 15 Jan 2020 18:29:52 +0100 Subject: [PATCH 3/4] Fix invalid upload url --- src/app/components/profile/profile.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index ff163ee..31822ad 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -73,7 +73,7 @@ export class ProfileComponent implements OnInit { const formData: any = new FormData(); formData.append('profilePicture', event.target.files[0]); - this.http.post(environment.greenvironmentUrl, formData).subscribe( + this.http.post(environment.greenvironmentUrl + '/upload', formData).subscribe( (response: any) => { this.userProfile.profilePicture = environment.greenvironmentUrl + response.filename; }, From 9ccb38976243e29ced37226dc5f7ae4d30949298 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 15 Jan 2020 19:05:25 +0100 Subject: [PATCH 4/4] Add error snackbar for picture upload --- src/app/app.module.ts | 4 +++- src/app/components/profile/profile.component.html | 4 ++-- src/app/components/profile/profile.component.ts | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f2300c3..2c5b1b3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -66,6 +66,7 @@ import {MatTooltipModule} from '@angular/material/tooltip'; import {MatExpansionModule} from '@angular/material/expansion'; import {MatDatepickerModule} from '@angular/material/datepicker'; import {MatNativeDateModule} from '@angular/material/'; +import {MatSnackBarModule} from '@angular/material/snack-bar'; // import logo from 'src/assets/gv-new-logo.svg'; import logo from '!!raw-loader!./gv-new-logo-white.svg'; @@ -150,7 +151,8 @@ const appRoutes: Routes = [ MatDialogModule, MatTooltipModule, MatExpansionModule, - MatDatepickerModule + MatDatepickerModule, + MatSnackBarModule, ], entryComponents: [ DialogCreateGroupComponent, DialogCreateEventComponent ], providers: [], diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index b40f0f6..81d38a8 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -6,7 +6,7 @@
camera_alt - +
@@ -48,7 +48,7 @@
camera_alt - +
diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 31822ad..b1a9aba 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -7,6 +7,8 @@ import { DatasharingService } from '../../services/datasharing.service'; import { ProfileService } from 'src/app/services/profile/profile.service'; import { HttpClient } from '@angular/common/http'; import { environment } from 'src/environments/environment'; +import {MatSnackBar} from '@angular/material/snack-bar'; +import { reduce } from 'rxjs/operators'; @Component({ selector: 'app-profile', @@ -27,6 +29,7 @@ export class ProfileComponent implements OnInit { constructor( private http: HttpClient, + private _snackBar: MatSnackBar, private router: Router, private requestService: RequestService, private data: DatasharingService, @@ -75,9 +78,12 @@ export class ProfileComponent implements OnInit { this.http.post(environment.greenvironmentUrl + '/upload', formData).subscribe( (response: any) => { - this.userProfile.profilePicture = environment.greenvironmentUrl + response.filename; + this.userProfile.profilePicture = environment.greenvironmentUrl + response.fileName; }, - (error) => console.log(error) - ); + (error) => { + this._snackBar.open('failed to upload picture', 'okay', { + duration: 3000 + }); + }); } }