- Next.js 14+ with App Router and TypeScript - Tailwind CSS and ShadCN UI styling - Zustand state management - Dexie.js for IndexedDB (local-first data) - Auth.js v5 for authentication - BMAD framework integration Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
import { SyncManager } from '@/services/sync-manager';
|
|
import { InstallPromptService } from '@/services/install-prompt-service';
|
|
import { useOfflineStore } from '@/lib/store/offline-store';
|
|
|
|
export function PWAInitializer() {
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return;
|
|
|
|
// Story 3.3: Initialize offline network listeners
|
|
SyncManager.startNetworkListener();
|
|
|
|
// Update online status when network changes
|
|
const updateOnlineStatus = () => {
|
|
const isOnline = SyncManager.isOnline();
|
|
useOfflineStore.getState().setOnlineStatus(isOnline);
|
|
};
|
|
|
|
window.addEventListener('online', updateOnlineStatus);
|
|
window.addEventListener('offline', updateOnlineStatus);
|
|
|
|
// Initial status check
|
|
updateOnlineStatus();
|
|
|
|
// Story 3.4: Initialize install prompt service
|
|
InstallPromptService.initialize();
|
|
|
|
console.log('[PWAInitializer] Services initialized');
|
|
|
|
return () => {
|
|
window.removeEventListener('online', updateOnlineStatus);
|
|
window.removeEventListener('offline', updateOnlineStatus);
|
|
};
|
|
}, []);
|
|
|
|
return null;
|
|
}
|