-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic refuge detail skeleton
- Loading branch information
1 parent
4938e39
commit 97e3f23
Showing
19 changed files
with
421 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/app/pages/refuges/refuge-detail/refuge-detail.page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<ion-header [translucent]="true"> | ||
<ion-toolbar> | ||
<ion-title>refuge-detail</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content [fullscreen]="true"> | ||
<ion-header collapse="condense"> | ||
<ion-toolbar> | ||
<ion-title size="large">refuge-detail</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
</ion-content> |
Empty file.
17 changes: 17 additions & 0 deletions
17
app/src/app/pages/refuges/refuge-detail/refuge-detail.page.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RefugeDetailPage } from './refuge-detail.page'; | ||
|
||
describe('RefugeDetailPage', () => { | ||
let component: RefugeDetailPage; | ||
let fixture: ComponentFixture<RefugeDetailPage>; | ||
|
||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(RefugeDetailPage); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
146 changes: 146 additions & 0 deletions
146
app/src/app/pages/refuges/refuge-detail/refuge-detail.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { RefugeService } from '../../../services/refuge/refuge.service'; | ||
import { AlertController, LoadingController } from '@ionic/angular'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { | ||
GetRefugeFromIdErrors, | ||
GetRefugeResponse, | ||
} from '../../../../schemas/refuge/get-refuge-schema'; | ||
import { match } from 'ts-pattern'; | ||
import { Refuge } from '../../../../schemas/refuge/refuge'; | ||
|
||
@Component({ | ||
selector: 'app-refuge-detail', | ||
templateUrl: './refuge-detail.page.html', | ||
styleUrls: ['./refuge-detail.page.scss'], | ||
}) | ||
export class RefugeDetailPage implements OnInit { | ||
refuge?: Refuge; | ||
|
||
constructor( | ||
private router: Router, | ||
private route: ActivatedRoute, | ||
private refugeService: RefugeService, | ||
private alertController: AlertController, | ||
private loadingController: LoadingController, | ||
private translateService: TranslateService, | ||
) { | ||
const refugeId = this.getRefugeIdFromUrl(); | ||
this.fetchRefuge(refugeId).then(); | ||
} | ||
|
||
ngOnInit() {} | ||
|
||
private async fetchRefuge(refugeId: string | null): Promise<void> { | ||
if (refugeId != null) this.fetchRefugeFromId(refugeId); | ||
else this.router.navigate(['login']).then(); | ||
} | ||
|
||
private getRefugeIdFromUrl(): string | null { | ||
return this.route.snapshot.paramMap.get('id'); | ||
} | ||
|
||
private fetchRefugeFromId(refugeId: string) { | ||
this.refugeService.getRefugeFrom(refugeId).subscribe({ | ||
next: (response: GetRefugeResponse) => | ||
this.handleGetRefugeResponse(response), | ||
error: () => this.handleClientError().then(), | ||
}); | ||
} | ||
|
||
private handleGetRefugeResponse(response: GetRefugeResponse) { | ||
match(response) | ||
.with({ status: 'correct' }, (response) => (this.refuge = response.data)) | ||
.with({ status: 'error' }, (response) => { | ||
this.handleGetError(response.error); | ||
}) | ||
.exhaustive(); | ||
} | ||
|
||
private handleGetError(error: GetRefugeFromIdErrors) { | ||
match(error) | ||
.with(GetRefugeFromIdErrors.NOT_FOUND, () => this.handleNotFoundRefuge()) | ||
.with(GetRefugeFromIdErrors.CLIENT_SEND_DATA_ERROR, () => | ||
this.handleBadUserData(), | ||
) | ||
.with(GetRefugeFromIdErrors.UNKNOWN_ERROR, () => | ||
this.handleUnknownError(), | ||
) | ||
.with( | ||
GetRefugeFromIdErrors.SERVER_INCORRECT_DATA_FORMAT_ERROR, | ||
GetRefugeFromIdErrors.PROGRAMMER_SEND_DATA_ERROR, | ||
() => this.handleBadProgrammerData(), | ||
) | ||
.exhaustive(); | ||
} | ||
|
||
private async handleClientError() { | ||
const alert = await this.alertController.create({ | ||
header: this.translateService.instant('HOME.ERRORS.CLIENT_ERROR.HEADER'), | ||
subHeader: this.translateService.instant( | ||
'HOME.ERRORS.CLIENT_ERROR.SUBHEADER', | ||
), | ||
message: this.translateService.instant( | ||
'HOME.ERRORS.CLIENT_ERROR.MESSAGE', | ||
), | ||
buttons: [ | ||
{ | ||
text: this.translateService.instant('HOME.ERRORS.CLIENT_ERROR.EXIT'), | ||
handler: () => { | ||
this.alertController.dismiss().then(); | ||
this.fetchRefuge(this.getRefugeIdFromUrl()); | ||
}, | ||
}, | ||
], | ||
}); | ||
return await alert.present(); | ||
} | ||
|
||
private handleNotFoundRefuge() { | ||
this.finishLoadAnimAndExecute(() => | ||
this.router | ||
.navigate(['not-found'], { | ||
skipLocationChange: true, | ||
}) | ||
.then(), | ||
).then(); | ||
} | ||
|
||
private handleBadProgrammerData() { | ||
this.finishLoadAnimAndExecute(() => | ||
this.router | ||
.navigate(['programming-error'], { | ||
skipLocationChange: true, | ||
}) | ||
.then(), | ||
).then(); | ||
} | ||
|
||
private handleBadUserData() { | ||
this.finishLoadAnimAndExecute(() => | ||
this.router | ||
.navigate(['not-found-page'], { | ||
skipLocationChange: true, | ||
}) | ||
.then(), | ||
).then(); | ||
} | ||
|
||
private handleUnknownError() { | ||
this.finishLoadAnimAndExecute(() => | ||
this.router | ||
.navigate(['internal-error-page'], { | ||
skipLocationChange: true, | ||
}) | ||
.then(), | ||
).then(); | ||
} | ||
|
||
private async finishLoadAnimAndExecute( | ||
func: (() => void) | (() => Promise<void>), | ||
) { | ||
await this.loadingController.dismiss().then(); | ||
await func(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/app/services/language/device-language.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { DeviceLanguageService } from './device-language.service'; | ||
|
||
describe('DeviceLanguageService', () => { | ||
let service: DeviceLanguageService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(DeviceLanguageService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.