Files
Mav-Mobile-UI/src/context/reducers/SoundContextReducer.ts

60 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { SoundAction, SoundState } from "../../types/types";
export const initialState: SoundState = {
sightingSound: "switch",
NPEDsound: "popup",
hotlists: [{ name: "hotlistName", sound: "notification" }],
soundOptions: [
2025-10-17 10:17:01 +01:00
{ name: "Switch (Default)", soundFile: "switch" },
{ name: "Popup", soundFile: "popup" },
{ name: "Notification", soundFile: "notification" },
{ name: "Beep", soundFile: "beep" },
{ name: "Ding", soundFile: "ding" },
{ name: "Shutter", soundFile: "shutter" },
{ name: "Warning (voice)", soundFile: "warning" },
],
sightingVolume: 1,
NPEDsoundVolume: 1,
hotlistSoundVolume: 1,
};
export function reducer(state: SoundState, action: SoundAction): SoundState {
switch (action.type) {
case "UPDATE": {
return {
...state,
sightingSound: action.payload.sightingSound,
NPEDsound: action.payload.NPEDsound,
hotlists: action.payload.hotlists?.map((hotlist) => ({
name: hotlist.name,
sound: hotlist.sound,
})),
NPEDsoundVolume: action.payload.NPEDsoundVolume,
sightingVolume: action.payload.sightingVolume,
};
}
case "ADD": {
return {
...state,
soundOptions: [...(state.soundOptions ?? []), action.payload],
};
}
// todo: refactor to use single state coupled with sound name. e.g : {name: <soundname>, volume: <volume>}
case "SIGHTINGVOLUME":
return {
...state,
sightingVolume: action.payload,
};
case "NPEDVOLUME":
return {
...state,
NPEDsoundVolume: action.payload,
};
default:
return state;
}
}