Initial End to End functionality

This commit is contained in:
Mulu Mehari
2026-08-02 22:44:08 +03:00
parent c9d885356c
commit c62ec59655
53 changed files with 6791 additions and 1208 deletions

View File

@@ -2,8 +2,15 @@ import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
export type LayoutMode = 'top' | 'sidebar';
/**
* Row height in tables. Officers who work a queue all day want more rows per
* screen; occasional users want the breathing room.
*/
export type Density = 'comfortable' | 'compact';
interface PreferencesState {
layoutMode: LayoutMode;
density: Density;
}
const PREFERENCES_KEY = 'ema-backoffice-preferences';
@@ -11,17 +18,25 @@ const PREFERENCES_KEY = 'ema-backoffice-preferences';
const loadPreferences = (): PreferencesState => {
try {
const stored = localStorage.getItem(PREFERENCES_KEY);
if (stored) return JSON.parse(stored);
} catch {}
if (stored) {
// Merge over the defaults so a preferences blob written before a new
// key existed does not come back with that key undefined.
return { layoutMode: 'sidebar', density: 'comfortable', ...JSON.parse(stored) };
}
} catch {
// Corrupt or unavailable storage (private mode) — fall through to the default.
}
// The sidebar is the grouped, scannable layout; the top strip puts all
// ~20 destinations in one horizontally-scrolling row.
return { layoutMode: 'sidebar' };
return { layoutMode: 'sidebar', density: 'comfortable' };
};
const savePreferences = (state: PreferencesState) => {
try {
localStorage.setItem(PREFERENCES_KEY, JSON.stringify(state));
} catch {}
} catch {
// Storage full or unavailable — the preference just will not persist.
}
};
const initialState: PreferencesState = loadPreferences();
@@ -34,8 +49,12 @@ const preferencesSlice = createSlice({
state.layoutMode = action.payload;
savePreferences(state);
},
setDensity(state, action: PayloadAction<Density>) {
state.density = action.payload;
savePreferences(state);
},
},
});
export const { setLayoutMode } = preferencesSlice.actions;
export const { setLayoutMode, setDensity } = preferencesSlice.actions;
export const preferencesReducer = preferencesSlice.reducer;