Remove SyncService and introduce context-based offline mode and state management
- Delete `SyncService` and its associated bidirectional synchronization logic. - Add multiple context providers (`OfflineProvider`, `AlertProvider`, `LangContext`, `UserContext`, `SessionContext`, `WorldContext`, `SettingBookContext`) for contextual state management. - Implement `SecureStorage` for OS-level secure data encryption and replace dependency on `SyncService` synchronization. - Update localization files (`en.json`, `fr.json`) with offline mode and error-related strings.
This commit is contained in:
35
context/OfflineContext.ts
Normal file
35
context/OfflineContext.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createContext, Dispatch, SetStateAction } from 'react';
|
||||
|
||||
export interface OfflineMode {
|
||||
isManuallyOffline: boolean;
|
||||
isNetworkOnline: boolean;
|
||||
isOffline: boolean;
|
||||
isDatabaseInitialized: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface OfflineContextType {
|
||||
offlineMode: OfflineMode;
|
||||
setOfflineMode: Dispatch<SetStateAction<OfflineMode>>;
|
||||
toggleOfflineMode: () => void;
|
||||
initializeDatabase: (userId: string, encryptionKey?: string) => Promise<boolean>;
|
||||
isCurrentlyOffline: () => boolean;
|
||||
}
|
||||
|
||||
export const defaultOfflineMode: OfflineMode = {
|
||||
isManuallyOffline: false,
|
||||
isNetworkOnline: typeof navigator !== 'undefined' ? navigator.onLine : true,
|
||||
isOffline: false,
|
||||
isDatabaseInitialized: false,
|
||||
error: null
|
||||
};
|
||||
|
||||
const OfflineContext = createContext<OfflineContextType>({
|
||||
offlineMode: defaultOfflineMode,
|
||||
setOfflineMode: () => {},
|
||||
toggleOfflineMode: () => {},
|
||||
initializeDatabase: async () => false,
|
||||
isCurrentlyOffline: () => false
|
||||
});
|
||||
|
||||
export default OfflineContext;
|
||||
Reference in New Issue
Block a user