- added sounds for all hotlist sounds

This commit is contained in:
2025-10-20 11:32:45 +01:00
parent a152c15ec7
commit 0867b3b743
5 changed files with 63 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { Field, FieldArray, Form, Formik } from "formik"; import { Field, Form, Formik } from "formik";
import FormGroup from "../components/FormGroup"; import FormGroup from "../components/FormGroup";
import type { FormValues, Hotlist } from "../../../types/types"; import type { FormValues, Hotlist } from "../../../types/types";
import { useSoundContext } from "../../../context/SoundContext"; import { useSoundContext } from "../../../context/SoundContext";
@@ -13,13 +13,14 @@ const SoundSettingsFields = () => {
const hotlists: Hotlist[] = state.hotlists; const hotlists: Hotlist[] = state.hotlists;
const soundOptions = state?.soundOptions?.map((soundOption) => ({ const soundOptions = state?.soundOptions?.map((soundOption) => ({
value: soundOption?.soundFile, value: soundOption?.soundFileName,
label: soundOption?.name, label: soundOption?.name,
})); }));
const initialValues: FormValues = { const initialValues: FormValues = {
sightingSound: state.sightingSound ?? "switch", sightingSound: state.sightingSound ?? "switch",
NPEDsound: state.NPEDsound ?? "popup", NPEDsound: state.NPEDsound ?? "popup",
hotlistSound: state.hotlistSound ?? "notification",
hotlists, hotlists,
}; };
@@ -28,6 +29,7 @@ const SoundSettingsFields = () => {
...values, ...values,
sightingVolume: state.sightingVolume, sightingVolume: state.sightingVolume,
NPEDsoundVolume: state.NPEDsoundVolume, NPEDsoundVolume: state.NPEDsoundVolume,
hotlistSoundVolume: state.hotlistSoundVolume,
}; };
dispatch({ type: "UPDATE", payload: updatedValues }); dispatch({ type: "UPDATE", payload: updatedValues });
@@ -44,7 +46,7 @@ const SoundSettingsFields = () => {
}; };
return ( return (
<Formik initialValues={initialValues} onSubmit={handleSubmit}> <Formik initialValues={initialValues} onSubmit={handleSubmit}>
{({ values }) => ( {() => (
<Form className="flex flex-col space-y-3"> <Form className="flex flex-col space-y-3">
<FormGroup> <FormGroup>
<div className="flex flex-col md:flex-row space-y-2 w-full justify-between gap-3"> <div className="flex flex-col md:flex-row space-y-2 w-full justify-between gap-3">
@@ -85,6 +87,23 @@ const SoundSettingsFields = () => {
<div> <div>
<h3 className="text-lg font-semibold mb-2">Hotlist Sounds</h3> <h3 className="text-lg font-semibold mb-2">Hotlist Sounds</h3>
<FormGroup> <FormGroup>
<div className="flex flex-col md:flex-row space-y-2 w-full justify-between gap-3">
<label htmlFor="hotlistSound">All hotlist Sounds</label>
<Field
as="select"
name="hotlistSound"
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
>
{soundOptions?.map(({ value, label }) => (
<option key={value} value={value}>
{label}
</option>
))}
</Field>
<SliderComponent soundCategory="HOTLISTVOLUME" />
</div>
</FormGroup>
{/* <FormGroup>
<FieldArray <FieldArray
name="hotlists" name="hotlists"
render={() => ( render={() => (
@@ -115,7 +134,7 @@ const SoundSettingsFields = () => {
</div> </div>
)} )}
/> />
</FormGroup> </FormGroup> */}
</div> </div>
<button <button
type="submit" type="submit"

View File

@@ -47,11 +47,11 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
}, [state.NPEDsound]); }, [state.NPEDsound]);
const soundSrcHotlist = useMemo(() => { const soundSrcHotlist = useMemo(() => {
return getSoundFileURL(state?.hotlists?.[0]?.sound) ?? notification; return getSoundFileURL(state?.hotlistSound) ?? notification;
}, [state.hotlists]); }, [state?.hotlistSound]);
const { play: npedSound } = useSound(soundSrcNped, { volume: state.NPEDsoundVolume }); const { play: npedSound } = useSound(soundSrcNped, { volume: state.NPEDsoundVolume });
const { play: hotlistsound } = useSound(soundSrcHotlist); const { play: hotlistsound } = useSound(soundSrcHotlist, { volume: state.hotlistSoundVolume });
const { const {
sightings, sightings,
setSelectedSighting, setSelectedSighting,

View File

@@ -4,7 +4,20 @@ import { useSoundContext } from "../../context/SoundContext";
const SliderComponent = ({ soundCategory }: { soundCategory: "SIGHTINGVOLUME" | "NPEDVOLUME" | "HOTLISTVOLUME" }) => { const SliderComponent = ({ soundCategory }: { soundCategory: "SIGHTINGVOLUME" | "NPEDVOLUME" | "HOTLISTVOLUME" }) => {
const { dispatch, state } = useSoundContext(); const { dispatch, state } = useSoundContext();
const volume = soundCategory === "SIGHTINGVOLUME" ? state.sightingVolume : state.NPEDsoundVolume;
const getVolumeOption = (soundCategory: string) => {
if (soundCategory === "SIGHTINGVOLUME") {
return state.sightingVolume;
}
if (soundCategory === "NPEDVOLUME") {
return state.NPEDsoundVolume;
}
if (soundCategory === "HOTLISTVOLUME") {
return state.hotlistSoundVolume;
}
};
const volume = getVolumeOption(soundCategory);
const handleChange = (value: number | number[]) => { const handleChange = (value: number | number[]) => {
const number = typeof value === "number" ? value : value[0]; const number = typeof value === "number" ? value : value[0];
@@ -39,7 +52,7 @@ const SliderComponent = ({ soundCategory }: { soundCategory: "SIGHTINGVOLUME" |
}, },
}} }}
/> />
<span>{volume * 10}</span> <span>{volume ? volume * 10 : 1}</span>
</div> </div>
); );
}; };

View File

@@ -3,15 +3,16 @@ import type { SoundAction, SoundState } from "../../types/types";
export const initialState: SoundState = { export const initialState: SoundState = {
sightingSound: "switch", sightingSound: "switch",
NPEDsound: "popup", NPEDsound: "popup",
hotlistSound: "warning",
hotlists: [{ name: "hotlistName", sound: "notification" }], hotlists: [{ name: "hotlistName", sound: "notification" }],
soundOptions: [ soundOptions: [
{ name: "Switch (Default)", soundFile: "switch" }, { name: "Switch (Default)", soundFileName: "switch" },
{ name: "Popup", soundFile: "popup" }, { name: "Popup", soundFileName: "popup" },
{ name: "Notification", soundFile: "notification" }, { name: "Notification", soundFileName: "notification" },
{ name: "Beep", soundFile: "beep" }, { name: "Beep", soundFileName: "beep" },
{ name: "Ding", soundFile: "ding" }, { name: "Ding", soundFileName: "ding" },
{ name: "Shutter", soundFile: "shutter" }, { name: "Shutter", soundFileName: "shutter" },
{ name: "Warning (voice)", soundFile: "warning" }, { name: "Warning (voice)", soundFileName: "warning" },
], ],
sightingVolume: 1, sightingVolume: 1,
NPEDsoundVolume: 1, NPEDsoundVolume: 1,
@@ -25,12 +26,14 @@ export function reducer(state: SoundState, action: SoundAction): SoundState {
...state, ...state,
sightingSound: action.payload.sightingSound, sightingSound: action.payload.sightingSound,
NPEDsound: action.payload.NPEDsound, NPEDsound: action.payload.NPEDsound,
hotlistSound: action.payload.hotlistSound,
hotlists: action.payload.hotlists?.map((hotlist) => ({ hotlists: action.payload.hotlists?.map((hotlist) => ({
name: hotlist.name, name: hotlist.name,
sound: hotlist.sound, sound: hotlist.sound,
})), })),
NPEDsoundVolume: action.payload.NPEDsoundVolume, NPEDsoundVolume: action.payload.NPEDsoundVolume,
sightingVolume: action.payload.sightingVolume, sightingVolume: action.payload.sightingVolume,
hotlistSoundVolume: action.payload.hotlistSoundVolume,
}; };
} }
@@ -53,6 +56,12 @@ export function reducer(state: SoundState, action: SoundAction): SoundState {
NPEDsoundVolume: action.payload, NPEDsoundVolume: action.payload,
}; };
case "HOTLISTVOLUME":
return {
...state,
hotlistSoundVolume: action.payload,
};
default: default:
return state; return state;
} }

View File

@@ -285,17 +285,20 @@ export type FormValues = {
sightingSound: SoundValue; sightingSound: SoundValue;
NPEDsound: SoundValue; NPEDsound: SoundValue;
hotlists: Hotlist[]; hotlists: Hotlist[];
hotlistSound: SoundValue;
}; };
export type SoundUploadValue = { export type SoundUploadValue = {
name: string; name: string;
soundFile: File | null; soundFileName?: string;
soundFile?: File | null;
}; };
export type SoundState = { export type SoundState = {
sightingSound: SoundValue; sightingSound: SoundValue;
NPEDsound: SoundValue; NPEDsound: SoundValue;
hotlists: Hotlist[]; hotlists: Hotlist[];
hotlistSound: SoundValue;
soundOptions?: SoundUploadValue[]; soundOptions?: SoundUploadValue[];
sightingVolume: number; sightingVolume: number;
NPEDsoundVolume: number; NPEDsoundVolume: number;
@@ -310,7 +313,8 @@ type UpdateAction = {
hotlists: Hotlist[]; hotlists: Hotlist[];
sightingVolume: number; sightingVolume: number;
NPEDsoundVolume: number; NPEDsoundVolume: number;
hotlistSoundVolume?: number; hotlistSoundVolume: number;
hotlistSound: SoundValue;
}; };
}; };