pwa notifications

This commit is contained in:
Bastian Wagner
2026-06-29 14:52:33 +02:00
parent 8fdee223c0
commit a033c50c25
18 changed files with 780 additions and 26 deletions

View File

@@ -11,6 +11,7 @@ import { getAuthErrorMessage } from '../auth/error-message';
import { AuthService } from '../auth/auth.service';
import { TaskDigestPreference } from '../auth/auth.models';
import { OnboardingService } from '../onboarding/onboarding.service';
import { TaskPushService } from '../tasks/task-push.service';
@Component({
selector: 'app-account',
@@ -28,6 +29,7 @@ import { OnboardingService } from '../onboarding/onboarding.service';
export class AccountComponent {
protected readonly auth = inject(AuthService);
protected readonly onboarding = inject(OnboardingService);
protected readonly taskPush = inject(TaskPushService);
private readonly router = inject(Router);
private readonly snackBar = inject(MatSnackBar);
protected savingTaskDigestPreference = false;
@@ -71,6 +73,9 @@ export class AccountComponent {
this.snackBar.open('Task-Mail-Einstellung gespeichert.', 'OK', {
duration: 3000,
});
if (preference === 'none') {
void this.taskPush.disableCurrentSubscription();
}
},
error: (error: unknown) => {
this.snackBar.open(getAuthErrorMessage(error), 'OK', {
@@ -80,6 +85,36 @@ export class AccountComponent {
});
}
async enablePushNotifications(): Promise<void> {
await this.taskPush.enable();
if (this.taskPush.errorMessage()) {
this.snackBar.open(this.taskPush.errorMessage()!, 'OK', {
duration: 5000,
});
return;
}
this.snackBar.open('PWA-Benachrichtigungen aktiviert.', 'OK', {
duration: 3000,
});
}
async disablePushNotifications(): Promise<void> {
await this.taskPush.disableCurrentSubscription();
if (this.taskPush.errorMessage()) {
this.snackBar.open(this.taskPush.errorMessage()!, 'OK', {
duration: 5000,
});
return;
}
this.snackBar.open('PWA-Benachrichtigungen deaktiviert.', 'OK', {
duration: 3000,
});
}
logout(): void {
this.auth.logout();
void this.router.navigateByUrl('/login');