- refactored code around hotlist hits and sounds
- improved performace for sounds playing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import switchSound from "../assets/sounds/ui/switch.mp3";
|
||||
import popup from "../assets/sounds/ui/popup_open.mp3";
|
||||
import notification from "../assets/sounds/ui/notification.mp3";
|
||||
import type { SightingType } from "../types/types";
|
||||
|
||||
export function getSoundFileURL(name: string) {
|
||||
const sounds: Record<string, string> = {
|
||||
@@ -129,59 +130,12 @@ export function drawRects(
|
||||
});
|
||||
}
|
||||
|
||||
// setSelectedRef(data?.ref);
|
||||
|
||||
//setItems(data);
|
||||
|
||||
// const selected = useMemo(
|
||||
// () =>
|
||||
// selectedRef == null
|
||||
// ? null
|
||||
// : items.find((x) => x?.ref === selectedRef) ?? null,
|
||||
// [items, selectedRef]
|
||||
// );
|
||||
// const effectiveSelected = selected ?? mostRecent ?? null;
|
||||
|
||||
// useEffect(() => {
|
||||
// let delay = pollMs;
|
||||
// let dead = false;
|
||||
// const controller = new AbortController();
|
||||
|
||||
// async function tick() {
|
||||
// try {
|
||||
// // Pause when tab hidden to save CPU/network
|
||||
// if (document.hidden) {
|
||||
// setTimeout(tick, Math.max(delay, 2000));
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (obj && typeof obj.ref === "number" && obj.ref > -1) {
|
||||
// setItems((prev) => {
|
||||
// const next = [obj, ...prev].slice(0, limit);
|
||||
// // maintain selection if still present; otherwise select newest if allowed
|
||||
// const stillExists =
|
||||
// selectedRef != null && next.some((x) => x?.ref === selectedRef);
|
||||
// if (autoSelectLatest && !stillExists) {
|
||||
// setSelectedRef(obj.ref);
|
||||
// }
|
||||
// return next;
|
||||
// });
|
||||
// setMostRecent(obj);
|
||||
// mostRecentRef.current = obj.ref;
|
||||
// delay = pollMs; // reset backoff on success
|
||||
// }
|
||||
// } catch {
|
||||
// // exponential backoff (max 10s)
|
||||
// delay = Math.min(delay * 2, 10000);
|
||||
// } finally {
|
||||
// if (!dead) setTimeout(tick, delay);
|
||||
// }
|
||||
// }
|
||||
|
||||
// const t = setTimeout(tick, pollMs);
|
||||
// return () => {
|
||||
// dead = true;
|
||||
// controller.abort();
|
||||
// clearTimeout(t);
|
||||
// };
|
||||
// }, [baseUrl, limit, pollMs, autoSelectLatest, selectedRef]);
|
||||
export const checkIsHotListHit = (sigthing: SightingType | null) => {
|
||||
if (!sigthing) return;
|
||||
if (sigthing?.metadata?.hotlistMatches) {
|
||||
const isHotListHit = Object.values(
|
||||
sigthing?.metadata?.hotlistMatches
|
||||
).includes(true);
|
||||
return isHotListHit;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user