diff --git a/frontend/angular.json b/frontend/angular.json index feea49f..03dff4c 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -96,7 +96,10 @@ "ssl": true, "sslCert": ".certs/cert.pem", "sslKey": ".certs/key.pem", - "proxyConfig": "proxy.conf.json" + "proxyConfig": "proxy.conf.json", + "prebundle": { + "exclude": ["@postnord/web-components/loader"] + } }, "configurations": { "production": { diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico index b9174db..d5420d0 100644 Binary files a/frontend/public/favicon.ico and b/frontend/public/favicon.ico differ diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index f32dbe2..293a5e1 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -4,6 +4,6 @@ diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index bfbccb8..034ec14 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,21 +1,13 @@ -import { Component, CUSTOM_ELEMENTS_SCHEMA, inject, signal } from '@angular/core'; +import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; -import { ConfettiService } from './confetti/confetti.service'; @Component({ selector: 'app-root', imports: [RouterOutlet], - schemas: [CUSTOM_ELEMENTS_SCHEMA], templateUrl: './app.component.html', styleUrl: './app.component.css' }) export class App { - private readonly confettiService = inject(ConfettiService); - - protected readonly title = signal('PostNordLotteriet'); + // protected readonly title = 'PostNordLotteriet'; protected readonly currentYear = new Date().getFullYear(); - - protected celebrate(): void { - this.confettiService.celebrate(); - } } diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index dc39edb..79984cd 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -1,3 +1,10 @@ import { Routes } from '@angular/router'; -export const routes: Routes = []; +import { DrawComponent } from './draw/draw.component'; + +export const routes: Routes = [ + { + path: '', + component: DrawComponent + } +]; diff --git a/frontend/src/app/draw/draw.component.css b/frontend/src/app/draw/draw.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/draw/draw.component.html b/frontend/src/app/draw/draw.component.html new file mode 100644 index 0000000..2bba3e0 --- /dev/null +++ b/frontend/src/app/draw/draw.component.html @@ -0,0 +1,23 @@ +
+
+

Sveriges största lotteri

+

Kanske är det du som får post idag

+
+ + Kolla + + @if (result(); as result) { +
+ + +
+ } +
diff --git a/frontend/src/app/draw/draw.component.ts b/frontend/src/app/draw/draw.component.ts new file mode 100644 index 0000000..36f6867 --- /dev/null +++ b/frontend/src/app/draw/draw.component.ts @@ -0,0 +1,80 @@ +import { Component, CUSTOM_ELEMENTS_SCHEMA, inject, signal } from '@angular/core'; +import { HttpErrorResponse } from '@angular/common/http'; +import { dematerialize, finalize, forkJoin, map, materialize, take, timer } from 'rxjs'; + +import { ConfettiService } from '../confetti/confetti.service'; +import { ShipmentService } from '../shipment/shipment.service'; + +type DrawResult = + | { appearance: 'success'; message: string } + | { appearance: 'warning'; message: string } + | { appearance: 'error'; message: string }; + +@Component({ + selector: 'app-draw', + imports: [], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + templateUrl: './draw.component.html', + styleUrl: './draw.component.css' +}) +export class DrawComponent { + private readonly confettiService = inject(ConfettiService); + private readonly shipmentService = inject(ShipmentService); + + private readonly minimumLoadingTimeMs = 2000; + + protected readonly loading = signal(false); + protected readonly result = signal(null); + + protected check(): void { + if (this.loading()) { + return; + } + + this.loading.set(true); + this.result.set(null); + + forkJoin([this.shipmentService.trackAndTrace().pipe(materialize(), take(1)), timer(this.minimumLoadingTimeMs)]) + .pipe( + map(([notification]) => notification), + dematerialize(), + finalize(() => this.loading.set(false)) + ) + .subscribe({ + next: (response) => { + this.result.set({ + appearance: 'success', + message: response.message + }); + + this.confettiService.celebrate(); + }, + error: (error: HttpErrorResponse) => { + this.handleError(error); + } + }); + } + + protected dismissResult(): void { + this.result.set(null); + } + + private handleError(error: HttpErrorResponse): void { + switch (error.status) { + case 400: + case 429: + case 503: + this.result.set({ + appearance: 'warning', + message: error.error?.message ?? 'Försöket kunde inte genomföras.' + }); + break; + + default: + this.result.set({ + appearance: 'error', + message: 'Något gick fel. Försök igen senare.' + }); + } + } +} diff --git a/frontend/src/index.html b/frontend/src/index.html index 1632905..0d3e1ec 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -1,5 +1,5 @@ - + PostNordLotteriet @@ -7,7 +7,7 @@ - +