2026-01-07 16:03:02 +01:00
|
|
|
import { create } from 'zustand';
|
|
|
|
|
import { persist } from 'zustand/middleware';
|
|
|
|
|
|
2026-01-11 15:20:48 +01:00
|
|
|
export type AlertThresholdUnit = 'hours' | 'minutes';
|
|
|
|
|
|
2026-01-07 16:03:02 +01:00
|
|
|
interface ModQueueState {
|
2026-01-11 15:20:48 +01:00
|
|
|
alertThresholdValue: number;
|
|
|
|
|
alertThresholdUnit: AlertThresholdUnit;
|
2026-01-07 16:03:02 +01:00
|
|
|
selectedBoardFilter: string | null;
|
2026-01-11 15:20:48 +01:00
|
|
|
setAlertThreshold: (value: number, unit: AlertThresholdUnit) => void;
|
2026-01-07 16:03:02 +01:00
|
|
|
setSelectedBoardFilter: (boardAddress: string | null) => void;
|
2026-01-11 15:20:48 +01:00
|
|
|
// Helper to get threshold in seconds for calculations
|
|
|
|
|
getAlertThresholdSeconds: () => number;
|
2026-01-07 16:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-11 16:30:35 +01:00
|
|
|
// Type for old persisted state format (before migration)
|
|
|
|
|
interface OldPersistedState {
|
|
|
|
|
alertThresholdHours?: number;
|
|
|
|
|
alertThresholdValue?: number;
|
|
|
|
|
alertThresholdUnit?: AlertThresholdUnit;
|
|
|
|
|
selectedBoardFilter?: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 16:03:02 +01:00
|
|
|
const useModQueueStore = create<ModQueueState>()(
|
|
|
|
|
persist(
|
2026-01-11 16:30:35 +01:00
|
|
|
(set, get) => ({
|
|
|
|
|
alertThresholdValue: 6,
|
|
|
|
|
alertThresholdUnit: 'hours' as AlertThresholdUnit,
|
|
|
|
|
selectedBoardFilter: null,
|
|
|
|
|
setAlertThreshold: (value, unit) => set({ alertThresholdValue: value, alertThresholdUnit: unit }),
|
|
|
|
|
setSelectedBoardFilter: (boardAddress) => set({ selectedBoardFilter: boardAddress }),
|
|
|
|
|
getAlertThresholdSeconds: () => {
|
|
|
|
|
const { alertThresholdValue, alertThresholdUnit } = get();
|
|
|
|
|
return alertThresholdUnit === 'hours' ? alertThresholdValue * 3600 : alertThresholdValue * 60;
|
|
|
|
|
},
|
|
|
|
|
}),
|
2026-01-07 16:03:02 +01:00
|
|
|
{
|
|
|
|
|
name: 'mod-queue-storage',
|
2026-01-11 16:30:35 +01:00
|
|
|
version: 1,
|
|
|
|
|
// Migrate old alertThresholdHours format to new alertThresholdValue/alertThresholdUnit format
|
|
|
|
|
migrate: (persistedState, version) => {
|
|
|
|
|
const state = persistedState as OldPersistedState;
|
|
|
|
|
if (version === 0 && state.alertThresholdHours !== undefined) {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
alertThresholdValue: state.alertThresholdHours,
|
|
|
|
|
alertThresholdUnit: 'hours' as AlertThresholdUnit,
|
|
|
|
|
alertThresholdHours: undefined, // Remove old field
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return state;
|
|
|
|
|
},
|
2026-01-07 16:03:02 +01:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default useModQueueStore;
|