feat(pwa): add offline handling and fallback support (#2444)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-23 20:51:22 -07:00
committed by GitHub
co-authored by acx10
parent 8278f47c6a
commit 27c764f0f1
5 changed files with 76 additions and 4 deletions
+18
View File
@@ -28,6 +28,7 @@ import {scan, withLatestFrom} from 'rxjs/operators';
export class AppComponent implements OnInit, OnDestroy {
loading = true;
offline = !navigator.onLine;
private subscriptions: Subscription[] = [];
private subscriptionsInitialized = false;
@@ -43,6 +44,9 @@ export class AppComponent implements OnInit, OnDestroy {
private libraryLoadingService = inject(LibraryLoadingService);
ngOnInit(): void {
window.addEventListener('online', this.onOnline);
window.addEventListener('offline', this.onOffline);
this.authInit.initialized$.subscribe(ready => {
this.loading = !ready;
if (ready && !this.subscriptionsInitialized) {
@@ -52,6 +56,18 @@ export class AppComponent implements OnInit, OnDestroy {
});
}
private onOnline = () => {
this.offline = false;
};
private onOffline = () => {
this.offline = true;
};
reload(): void {
window.location.reload();
}
private setupWebSocketSubscriptions(): void {
this.subscriptions.push(
this.rxStompService.watch('/user/queue/book-add').pipe(
@@ -125,6 +141,8 @@ export class AppComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
window.removeEventListener('online', this.onOnline);
window.removeEventListener('offline', this.onOffline);
this.subscriptions.forEach(sub => sub.unsubscribe());
this.libraryLoadingService.hide();
}