- storing changes for now

This commit is contained in:
2025-10-28 09:54:29 +00:00
parent a64fa76ecb
commit 907555cb0d
4 changed files with 47 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import { toast } from "sonner";
import { getOrCacheBlob } from "../utils/cacheSound";
const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : CAM_BASE;
type UseFileUploadProps = {
@@ -22,11 +23,8 @@ const uploadFile = async (file: File) => {
const getUploadFiles = async ({ queryKey }: { queryKey: string[] }) => {
const [, fileName] = queryKey;
const response = await fetch(`${camBase}/Mobile/${fileName}`);
if (!response.ok) {
throw new Error("Cannot reach upload file endpoint");
}
return response.blob();
const url = `${camBase}/Mobile/${fileName}`;
return getOrCacheBlob(url);
};
export const useFileUpload = ({ queryKey }: UseFileUploadProps) => {

View File

@@ -8,6 +8,7 @@ import { checkIsHotListHit, getNPEDCategory, getSoundFileURL } from "../utils/ut
import switchSound from "../assets/sounds/ui/switch.mp3";
import notification from "../assets/sounds/ui/notification.mp3";
import popup from "../assets/sounds/ui/popup_open.mp3";
import { useFileUpload } from "./useFileUpload";
async function fetchSighting(url: string | undefined, ref: number): Promise<SightingType> {
const res = await fetch(`${url}${ref}`, {
@@ -18,12 +19,22 @@ async function fetchSighting(url: string | undefined, ref: number): Promise<Sigh
}
export function useSightingFeed(url: string | undefined) {
const { state, audioArmed } = useSoundContext();
const { state, audioArmed, dispatch } = useSoundContext();
const [sightings, setSightings] = useState<SightingType[]>([]);
const [selectedRef, setSelectedRef] = useState<number | null>(null);
const [sessionStarted, setSessionStarted] = useState(false);
const [selectedSighting, setSelectedSighting] = useState<SightingType | null>(null);
const isUploaded = state?.sightingSound?.endsWith(".mp3") || state?.sightingSound?.endsWith(".wav");
const fileName = isUploaded ? state.sightingSound : switchSound;
const { query: fileQuery } = useFileUpload({
queryKey: fileName ? [fileName] : undefined,
});
const objUrlRef = useRef<string | null>(null);
const soundSrcHotlist = useMemo(() => {
if (state?.hotlistSound?.includes(".mp3") || state.hotlistSound?.includes(".wav")) {
const file = state.soundOptions?.find((item) => item.name === state.hotlistSound);
@@ -41,12 +52,20 @@ export function useSightingFeed(url: string | undefined) {
}, [state.NPEDsound, state.soundOptions]);
const soundSrc = useMemo(() => {
if (state?.sightingSound?.includes(".mp3") || state.sightingSound?.includes(".wav")) {
const file = state.soundOptions?.find((item) => item.name === state.sightingSound);
return file?.soundUrl ?? switchSound;
if (isUploaded && fileQuery?.data instanceof Blob) {
if (objUrlRef.current) URL.revokeObjectURL(objUrlRef.current);
objUrlRef.current = URL.createObjectURL(fileQuery.data);
console.log(fileQuery.data);
return objUrlRef.current;
}
return getSoundFileURL(state?.sightingSound) ?? switchSound;
}, [state.sightingSound, state.soundOptions]);
}, [isUploaded, fileQuery?.data, state?.sightingSound]);
useEffect(() => {
return () => {
if (objUrlRef.current) URL.revokeObjectURL(objUrlRef.current);
};
}, []);
const { play: hotlistsound } = useSound(soundSrcHotlist, { volume: state.hotlistSoundVolume });
const { play: npedSound } = useSound(soundSrcNped, { volume: state.NPEDsoundVolume });