Skip to content

Commit

Permalink
Use Snackbar instead of generic banner
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-1337 committed Sep 30, 2024
1 parent b76be3a commit 6f87df8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
7 changes: 0 additions & 7 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,5 @@
</button>
</mat-card-actions>
</mat-card>
<mat-card>
<mat-card-content>
<div *ngIf="updateAvailable" class="update-banner">
<p>Eine neue Version ist verfügbar! <button (click)="reloadApp()">Jetzt aktualisieren</button></p>
</div>
</mat-card-content>
</mat-card>
</div>
</main>
22 changes: 18 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatInputModule } from '@angular/material/input';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; // Importiere MatSnackBar

import { MtxColorpickerModule } from '@ng-matero/extensions/colorpicker';

Expand All @@ -33,6 +34,7 @@ import { IconsClass } from './icons.class';
MatFormFieldModule,
MatSelectModule,
MatInputModule,
MatSnackBarModule,
MtxColorpickerModule,
NavbarComponent,
NgIf
Expand All @@ -42,8 +44,6 @@ import { IconsClass } from './icons.class';
})
export class AppComponent implements AfterViewInit, OnInit {

updateAvailable = false; // Flag für Banner

qrData = 'https://qr.changekraft.de'; // Default QR Code data
qrSize = 512; // Default size
// Define errorCorrectionLevel with the specific type
Expand All @@ -56,7 +56,9 @@ export class AppComponent implements AfterViewInit, OnInit {

constructor(
public icons: IconsClass,
private swUpdate: SwUpdate
private swUpdate: SwUpdate,
private snackBar: MatSnackBar

) { }

ngOnInit(): void {
Expand All @@ -69,11 +71,23 @@ export class AppComponent implements AfterViewInit, OnInit {
)
.subscribe(() => {
// Wenn ein Update gefunden wird, zeige das Banner an
this.updateAvailable = true;
this.showUpdateSnackBar();
});
}
}

// Zeige eine Snackbar, die auf ein Update hinweist
showUpdateSnackBar(): void {
const snackBarRef = this.snackBar.open('Neue Version verfügbar!', 'Neu laden', {
duration: 6000, // Zeigt die Snackbar für 6 Sekunden an
});

// Reagiere auf den Klick des Nutzers auf 'Neu laden'
snackBarRef.onAction().subscribe(() => {
this.reloadApp();
});
}

// Funktion, um die Anwendung neu zu laden
reloadApp(): void {
window.location.reload();
Expand Down

0 comments on commit 6f87df8

Please sign in to comment.