Remove mock data files and consolidate into single mock module
Delete separate dev and prod mock files, create unified mock module with fullMockState and minimalState exports, and update store to select appropriate mock based on environment. Remove mock-data alias from Vite config.
This commit is contained in:
1 parent
093d5b2a11
commit
b4278523f2
4 files changed
+61
-73
No files matched your search
@@ -1,46 +0,0 @@
|
||||
import type { CultivarState } from './types';
|
||||
|
||||
const NOW = Math.floor(Date.now() / 1000);
|
||||
|
||||
export const initialState: CultivarState = {
|
||||
meta: {
|
||||
device_id: '',
|
||||
firmware_version: '',
|
||||
uptime_s: 0,
|
||||
wifi_rssi: 0,
|
||||
timestamp_utc: NOW,
|
||||
},
|
||||
environment: {
|
||||
history: [],
|
||||
live: { temp_c: 0, rh_pct: 0, co2_ppm: 0, co2e_ppm: 0, voc_ppb: 0, vpd: 0 },
|
||||
targets: { temp_c: 0, rh_pct: 0, co2_ppm: 0 },
|
||||
alerts: [],
|
||||
},
|
||||
chambers: [],
|
||||
hardware: {
|
||||
fans: [],
|
||||
humidifier: { active: false, mode: 'auto', reservoir_pct: 0 },
|
||||
lights: [],
|
||||
doors: [],
|
||||
cameras: [],
|
||||
},
|
||||
recipe: {
|
||||
id: '',
|
||||
name: '',
|
||||
species: '',
|
||||
stage: 'inoculation',
|
||||
stage_started_ts: 0,
|
||||
stage_target_duration_h: 0,
|
||||
stage_history: [],
|
||||
next_actions: [],
|
||||
},
|
||||
maintenance: {
|
||||
last_wipe_ts: 0,
|
||||
last_reservoir_clean_ts: 0,
|
||||
},
|
||||
ui: {
|
||||
scrubber_ts: null,
|
||||
selected_bag_id: null,
|
||||
onboarding_complete: false,
|
||||
},
|
||||
};
|
||||
@@ -72,7 +72,7 @@ const inoculatedF_A2 = NOW - 28 * HOUR * 24;
|
||||
const inoculatedF_B2 = NOW - 20 * HOUR * 24;
|
||||
const inoculatedF_C1 = NOW - 22 * HOUR * 24;
|
||||
|
||||
export const initialState: CultivarState = {
|
||||
const fullMockState: CultivarState = {
|
||||
meta: {
|
||||
device_id: 'CVR-0042',
|
||||
firmware_version: '0.9.4',
|
||||
@@ -413,3 +413,48 @@ export const initialState: CultivarState = {
|
||||
onboarding_complete: localStorage.getItem('onboarding_complete') === 'true',
|
||||
},
|
||||
};
|
||||
|
||||
const minimalState: CultivarState = {
|
||||
meta: {
|
||||
device_id: '',
|
||||
firmware_version: '',
|
||||
uptime_s: 0,
|
||||
wifi_rssi: 0,
|
||||
timestamp_utc: NOW,
|
||||
},
|
||||
environment: {
|
||||
history: [],
|
||||
live: { temp_c: 0, rh_pct: 0, co2_ppm: 0, co2e_ppm: 0, voc_ppb: 0, vpd: 0 },
|
||||
targets: { temp_c: 0, rh_pct: 0, co2_ppm: 0 },
|
||||
alerts: [],
|
||||
},
|
||||
chambers: [],
|
||||
hardware: {
|
||||
fans: [],
|
||||
humidifier: { active: false, mode: 'auto', reservoir_pct: 0 },
|
||||
lights: [],
|
||||
doors: [],
|
||||
cameras: [],
|
||||
},
|
||||
recipe: {
|
||||
id: '',
|
||||
name: '',
|
||||
species: '',
|
||||
stage: 'inoculation',
|
||||
stage_started_ts: 0,
|
||||
stage_target_duration_h: 0,
|
||||
stage_history: [],
|
||||
next_actions: [],
|
||||
},
|
||||
maintenance: {
|
||||
last_wipe_ts: 0,
|
||||
last_reservoir_clean_ts: 0,
|
||||
},
|
||||
ui: {
|
||||
scrubber_ts: null,
|
||||
selected_bag_id: null,
|
||||
onboarding_complete: false,
|
||||
},
|
||||
};
|
||||
|
||||
export { fullMockState, minimalState };
|
||||
@@ -1,4 +1,4 @@
|
||||
import { initialState } from '@mock-data';
|
||||
import { fullMockState, minimalState } from './mock';
|
||||
import type { CultivarState, EnvironmentReading, WsDiff } from './types';
|
||||
|
||||
function deepClone<T>(v: T): T {
|
||||
@@ -6,6 +6,8 @@ function deepClone<T>(v: T): T {
|
||||
}
|
||||
|
||||
function createStore() {
|
||||
// @ts-ignore - Vite provides import.meta.env.DEV
|
||||
const initialState = (import.meta as any).env?.DEV ? fullMockState : minimalState;
|
||||
let state = $state<CultivarState>(deepClone(initialState));
|
||||
|
||||
// Mock WS diff interval
|
||||
|
||||
Reference in new issue
Block a user