diff --git a/src/app/entities/api-response.ts b/src/app/entities/api-response.ts index 1ce0166..e7648c1 100644 --- a/src/app/entities/api-response.ts +++ b/src/app/entities/api-response.ts @@ -1,7 +1,7 @@ export interface ApiResponse { - success: boolean; - data?: T; - error?: ApiError; + readonly success: boolean; + readonly data?: T; + readonly error?: ApiError; } export interface ApiError { diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index eeef071..102fa84 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -14,10 +14,12 @@ export class HeaderComponent implements OnInit { async login(): Promise { this.oauthService.configure(authConfig); - await this.oauthService.loadDiscoveryDocument(); - sessionStorage.setItem('flow', 'code'); - - this.oauthService.initLoginFlow(); + await this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => { + console.log( + 'LOGGED=' + (this.oauthService.hasValidIdToken() + && this.oauthService.hasValidAccessToken()) + ); + }); } logout(): void { diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 0b8f749..5f8e038 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -3,7 +3,6 @@ import { OAuthService } from 'angular-oauth2-oidc'; import { ActivatedRoute } from '@angular/router'; import { ApiService } from '../services/api.service'; import { Travel } from '../entities/travel'; -import { ApiResponse } from '../entities/api-response'; @Component({ templateUrl: './home.component.html', @@ -25,27 +24,6 @@ export class HomeComponent implements OnInit { this.route.params.subscribe((p) => { this.login = p['login']; }); - - this.apiService - .call('/travel/list') - .subscribe((res: ApiResponse) => { - if (res.success) { - this.userTravels = res.data; - console.log(res.data); - } else { - console.error(res.error.code + ' ' + res.error.msg); - } - }); - - // This would directly (w/o user interaction) redirect the user to the - // login page if they are not already logged in. - /* - this.oauthService.loadDiscoveryDocumentAndTryLogin().then(_ => { - if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) { - this.oauthService.initImplicitFlow('some-state'); - } - }); - */ } loadUserProfile(): void { diff --git a/src/app/travel-list/travel-list.component.css b/src/app/travel-list/travel-list.component.css index 511addb..253622a 100644 --- a/src/app/travel-list/travel-list.component.css +++ b/src/app/travel-list/travel-list.component.css @@ -32,7 +32,7 @@ position: fixed; } -.lessons-table { +.travel-table { min-height: 360px; margin-top: 10px; } diff --git a/src/app/travel-list/travel-list.component.html b/src/app/travel-list/travel-list.component.html index 8bbad7d..82c343a 100644 --- a/src/app/travel-list/travel-list.component.html +++ b/src/app/travel-list/travel-list.component.html @@ -1,6 +1,6 @@
- +
@@ -8,7 +8,7 @@
{ - numTravels = 0; private travelsSubject = new BehaviorSubject([]); private loadingSubject = new BehaviorSubject(false); @@ -15,8 +14,7 @@ export class TravelsDataSource implements DataSource { constructor(private apiService: ApiService) {} - loadLessons( - courseId: number, + loadTravels( filter: string, sortDirection: string, pageIndex: number, @@ -32,17 +30,8 @@ export class TravelsDataSource implements DataSource { ) .subscribe((res) => { const data = (res as ApiResponse).data; - this.numTravels = data.length; this.travelsSubject.next(data); }); - - // this.apiService - // .findLessons(courseId, filter, sortDirection, pageIndex, pageSize) - // .pipe( - // catchError(() => of([])), - // finalize(() => this.loadingSubject.next(false)) - // ) - // .subscribe((lessons) => this.lessonsSubject.next(lessons)); } connect(collectionViewer: CollectionViewer): Observable {