Skip to content

Commit

Permalink
adjust UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Jul 18, 2023
1 parent b8e6c30 commit 3b118f4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Adjust the UI
- Create separate E2E test project which locally tests agains running angular + Spring API using Selnium. On CI it uses test containers of both images. Adding authontication headers with own server.
- Try using WebTestClient https://docs.spring.io/spring-framework/reference/testing/webtestclient.html#webtestclient-json
- Add pgAdmin to dev container https://www.pgadmin.org/download/pgadmin-4-container/s
- fix client tests
2 changes: 1 addition & 1 deletion client/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<app-weight></app-weight>
<app-weight *ngIf="$sync | async"></app-weight>
7 changes: 6 additions & 1 deletion client/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Component } from '@angular/core';
import { WithingsService } from './withings.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {}
export class AppComponent {
constructor(private withingsService: WithingsService) {}

$sync = this.withingsService.sync();
}
17 changes: 17 additions & 0 deletions client/src/app/weight.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { WeightResponse } from './types';

@Injectable({
providedIn: 'root',
})
export class WeightService {
constructor(private http: HttpClient) {}

getWeight(): Observable<number | undefined> {
return this.http
.get<WeightResponse>('/api/weight')
.pipe(map((weightResponse) => weightResponse.weight));
}
}
6 changes: 3 additions & 3 deletions client/src/app/weight/weight.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Component } from '@angular/core';
import { map } from 'rxjs';
import { WithingsService } from '../withings.service';
import { WeightService } from '../weight.service';

@Component({
selector: 'app-weight',
templateUrl: './weight.component.html',
styleUrls: ['./weight.component.css'],
})
export class WeightComponent {
constructor(private withingsService: WithingsService) {}
constructor(private weightService: WeightService) {}

$weight = this.withingsService
$weight = this.weightService
.getWeight()
.pipe(map((weight) => weight?.toString() ?? '?'));
}
15 changes: 7 additions & 8 deletions client/src/app/withings.service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable, OnInit } from '@angular/core';
import { catchError, map, Observable, of } from 'rxjs';
import { WeightResponse } from './types';
import { Injectable } from '@angular/core';
import { Observable, catchError, map, of } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class WithingsService {
constructor(private http: HttpClient) {}

getWeight(): Observable<number | undefined> {
return this.http.get<WeightResponse>('/api/withings/weight').pipe(
map((weightResponse) => weightResponse.weight),
sync(): Observable<boolean> {
return this.http.post<void>('/api/withings/sync', undefined).pipe(
map(() => true),
catchError((error) => {
if (error instanceof HttpErrorResponse && error.status === 401) {
debugger;
window.location.href = error.error._links.oauth2Login.href;
}
return of(undefined);

return of();
})
);
}
Expand Down
9 changes: 1 addition & 8 deletions client/src/proxy.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
"/api": {
"target": "http://localhost:8080",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true,
"xfwd": true,
"headers": {
"X-Forwarded-Prefix": "/api"
}
"changeOrigin": true
}
}

0 comments on commit 3b118f4

Please sign in to comment.