2025-10-01 15:21:07 +01:00
|
|
|
import type { SoundAction, SoundState } from "../../types/types";
|
2025-09-30 14:51:37 +01:00
|
|
|
|
2025-10-01 15:21:07 +01:00
|
|
|
export const initialState: SoundState = {
|
2025-09-30 14:51:37 +01:00
|
|
|
sightingSound: "switch",
|
|
|
|
|
NPEDsound: "popup",
|
2025-10-20 11:32:45 +01:00
|
|
|
hotlistSound: "warning",
|
2025-10-09 14:11:58 +01:00
|
|
|
hotlists: [{ name: "hotlistName", sound: "notification" }],
|
2025-10-01 15:21:07 +01:00
|
|
|
soundOptions: [
|
2025-10-20 11:32:45 +01:00
|
|
|
{ name: "Switch (Default)", soundFileName: "switch" },
|
|
|
|
|
{ name: "Popup", soundFileName: "popup" },
|
|
|
|
|
{ name: "Notification", soundFileName: "notification" },
|
|
|
|
|
{ name: "Beep", soundFileName: "beep" },
|
|
|
|
|
{ name: "Ding", soundFileName: "ding" },
|
|
|
|
|
{ name: "Shutter", soundFileName: "shutter" },
|
|
|
|
|
{ name: "Warning (voice)", soundFileName: "warning" },
|
2025-10-01 15:21:07 +01:00
|
|
|
],
|
2025-10-17 16:12:02 +01:00
|
|
|
sightingVolume: 1,
|
|
|
|
|
NPEDsoundVolume: 1,
|
|
|
|
|
hotlistSoundVolume: 1,
|
2025-09-30 14:51:37 +01:00
|
|
|
};
|
|
|
|
|
|
2025-10-01 15:21:07 +01:00
|
|
|
export function reducer(state: SoundState, action: SoundAction): SoundState {
|
2025-09-30 14:51:37 +01:00
|
|
|
switch (action.type) {
|
2025-10-01 15:21:07 +01:00
|
|
|
case "UPDATE": {
|
2025-09-30 14:51:37 +01:00
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
sightingSound: action.payload.sightingSound,
|
|
|
|
|
NPEDsound: action.payload.NPEDsound,
|
2025-10-20 11:32:45 +01:00
|
|
|
hotlistSound: action.payload.hotlistSound,
|
2025-10-08 11:08:41 +01:00
|
|
|
hotlists: action.payload.hotlists?.map((hotlist) => ({
|
2025-09-30 15:32:00 +01:00
|
|
|
name: hotlist.name,
|
|
|
|
|
sound: hotlist.sound,
|
|
|
|
|
})),
|
2025-10-20 09:11:05 +01:00
|
|
|
NPEDsoundVolume: action.payload.NPEDsoundVolume,
|
|
|
|
|
sightingVolume: action.payload.sightingVolume,
|
2025-10-20 11:32:45 +01:00
|
|
|
hotlistSoundVolume: action.payload.hotlistSoundVolume,
|
2025-10-21 12:52:14 +01:00
|
|
|
soundOptions: action.payload.soundOptions,
|
2025-09-30 14:51:37 +01:00
|
|
|
};
|
2025-10-01 15:21:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "ADD": {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
soundOptions: [...(state.soundOptions ?? []), action.payload],
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-10-17 16:12:02 +01:00
|
|
|
// 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,
|
|
|
|
|
};
|
2025-10-01 15:21:07 +01:00
|
|
|
|
2025-10-20 11:32:45 +01:00
|
|
|
case "HOTLISTVOLUME":
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
hotlistSoundVolume: action.payload,
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-01 15:21:07 +01:00
|
|
|
default:
|
|
|
|
|
return state;
|
2025-09-30 14:51:37 +01:00
|
|
|
}
|
|
|
|
|
}
|