Files
maternal-app/maternal-web/store/slices/offlineSlice.ts
andupetcu b62342fe2d Add missing pages with AppShell layout integration
- Created /track, /insights, /children, /family, /settings, /logout pages
- Wrapped all authenticated pages with AppShell and ProtectedRoute
- Updated AI assistant page to use AppShell layout
- All pages now have proper header/navigation and footer/tabbar
- Added responsive mobile and desktop layouts
- Integrated with existing navigation system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-30 22:05:56 +03:00

75 lines
2.0 KiB
TypeScript

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
export interface PendingAction {
id: string;
type: string;
payload: any;
timestamp: string;
retryCount: number;
}
interface OfflineState {
isOnline: boolean;
pendingActions: PendingAction[];
lastSyncTime: string | null;
syncInProgress: boolean;
}
const initialState: OfflineState = {
isOnline: typeof navigator !== 'undefined' ? navigator.onLine : true,
pendingActions: [],
lastSyncTime: null,
syncInProgress: false,
};
const offlineSlice = createSlice({
name: 'offline',
initialState,
reducers: {
setOnlineStatus: (state, action: PayloadAction<boolean>) => {
state.isOnline = action.payload;
if (action.payload && state.pendingActions.length > 0) {
state.syncInProgress = true;
}
},
addPendingAction: (state, action: PayloadAction<Omit<PendingAction, 'id' | 'timestamp' | 'retryCount'>>) => {
state.pendingActions.push({
...action.payload,
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
timestamp: new Date().toISOString(),
retryCount: 0,
});
},
removePendingAction: (state, action: PayloadAction<string>) => {
state.pendingActions = state.pendingActions.filter(a => a.id !== action.payload);
},
incrementRetryCount: (state, action: PayloadAction<string>) => {
const action_ = state.pendingActions.find(a => a.id === action.payload);
if (action_) {
action_.retryCount += 1;
}
},
clearPendingActions: (state) => {
state.pendingActions = [];
},
setSyncInProgress: (state, action: PayloadAction<boolean>) => {
state.syncInProgress = action.payload;
},
updateLastSyncTime: (state) => {
state.lastSyncTime = new Date().toISOString();
},
},
});
export const {
setOnlineStatus,
addPendingAction,
removePendingAction,
incrementRetryCount,
clearPendingActions,
setSyncInProgress,
updateLastSyncTime,
} = offlineSlice.actions;
export default offlineSlice.reducer;