Compare commits
2 Commits
feature/IO
...
feature/IO
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28abd9707e | ||
|
|
5f621e1ae0 |
@@ -3,6 +3,7 @@ import axios from "axios";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
|
import cleanAxios from "../../utils/CleanAxios";
|
||||||
import formatBytes from "../../utils/formatbytes";
|
import formatBytes from "../../utils/formatbytes";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
const socketRef = useRef(null);
|
const socketRef = useRef(null);
|
||||||
const [clientId, setClientId] = useState(null);
|
const [clientId, setClientId] = useState(null);
|
||||||
const [isConnected, setIsConnected] = useState(false);
|
const [isConnected, setIsConnected] = useState(false);
|
||||||
const [socketInitialized, setSocketInitialized] = useState(false);
|
|
||||||
const notification = useNotification();
|
const notification = useNotification();
|
||||||
const userAssociationId = bodyshop?.associations?.[0]?.id;
|
const userAssociationId = bodyshop?.associations?.[0]?.id;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -147,13 +146,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
onError: (err) => console.error("MARK_ALL_NOTIFICATIONS_READ error:", err)
|
onError: (err) => console.error("MARK_ALL_NOTIFICATIONS_READ error:", err)
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkAndReconnect = () => {
|
|
||||||
if (socketRef.current && !socketRef.current.connected) {
|
|
||||||
console.log("Attempting manual reconnect due to event trigger");
|
|
||||||
socketRef.current.connect();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeSocket = async (token) => {
|
const initializeSocket = async (token) => {
|
||||||
if (!bodyshop || !bodyshop.id || socketRef.current) return;
|
if (!bodyshop || !bodyshop.id || socketRef.current) return;
|
||||||
@@ -172,7 +164,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socketRef.current = socketInstance;
|
socketRef.current = socketInstance;
|
||||||
setSocketInitialized(true);
|
|
||||||
|
|
||||||
const handleBodyshopMessage = (message) => {
|
const handleBodyshopMessage = (message) => {
|
||||||
if (!message || !message.type) return;
|
if (!message || !message.type) return;
|
||||||
@@ -481,57 +472,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
t
|
t
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!socketInitialized) return;
|
|
||||||
|
|
||||||
const onVisibilityChange = () => {
|
|
||||||
if (document.visibilityState === "visible") {
|
|
||||||
checkAndReconnect();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFocus = () => {
|
|
||||||
checkAndReconnect();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onOnline = () => {
|
|
||||||
checkAndReconnect();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onPageShow = (event) => {
|
|
||||||
if (event.persisted) {
|
|
||||||
checkAndReconnect();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
||||||
window.addEventListener("focus", onFocus);
|
|
||||||
window.addEventListener("online", onOnline);
|
|
||||||
window.addEventListener("pageshow", onPageShow);
|
|
||||||
|
|
||||||
// Sleep/wake detection using timer
|
|
||||||
let lastTime = Date.now();
|
|
||||||
const intervalMs = 1000; // Check every second
|
|
||||||
const thresholdMs = 2000; // If more than 2 seconds elapsed, assume sleep/wake
|
|
||||||
|
|
||||||
const sleepCheckInterval = setInterval(() => {
|
|
||||||
const currentTime = Date.now();
|
|
||||||
if (currentTime > lastTime + intervalMs + thresholdMs) {
|
|
||||||
console.log("Detected potential wake from sleep/hibernate");
|
|
||||||
checkAndReconnect();
|
|
||||||
}
|
|
||||||
lastTime = currentTime;
|
|
||||||
}, intervalMs);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
||||||
window.removeEventListener("focus", onFocus);
|
|
||||||
window.removeEventListener("online", onOnline);
|
|
||||||
window.removeEventListener("pageshow", onPageShow);
|
|
||||||
clearInterval(sleepCheckInterval);
|
|
||||||
};
|
|
||||||
}, [socketInitialized]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SocketContext.Provider
|
<SocketContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ const jobLifecycle = async (req, res) => {
|
|||||||
const finalTotal = Object.values(flatGroupedAllDurations).reduce((total, statusArr) => {
|
const finalTotal = Object.values(flatGroupedAllDurations).reduce((total, statusArr) => {
|
||||||
return total + statusArr.reduce((acc, curr) => acc + curr.value, 0);
|
return total + statusArr.reduce((acc, curr) => acc + curr.value, 0);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
Object.keys(flatGroupedAllDurations).forEach((status) => {
|
Object.keys(flatGroupedAllDurations).forEach((status) => {
|
||||||
const value = flatGroupedAllDurations[status].reduce((acc, curr) => acc + curr.value, 0);
|
const value = flatGroupedAllDurations[status].reduce((acc, curr) => acc + curr.value, 0);
|
||||||
const humanReadable = durationToHumanReadable(moment.duration(value));
|
const humanReadable = durationToHumanReadable(moment.duration(value));
|
||||||
|
|||||||
@@ -50,12 +50,7 @@ const autoAddWatchers = async (req) => {
|
|||||||
try {
|
try {
|
||||||
// Fetch bodyshop data from Redis
|
// Fetch bodyshop data from Redis
|
||||||
const bodyshopData = await getBodyshopFromRedis(shopId);
|
const bodyshopData = await getBodyshopFromRedis(shopId);
|
||||||
let notificationFollowers = bodyshopData?.notification_followers;
|
const notificationFollowers = bodyshopData?.notification_followers || [];
|
||||||
|
|
||||||
// Bail if notification_followers is missing or not an array
|
|
||||||
if (!notificationFollowers || !Array.isArray(notificationFollowers)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute queries in parallel
|
// Execute queries in parallel
|
||||||
const [notificationData, existingWatchersData] = await Promise.all([
|
const [notificationData, existingWatchersData] = await Promise.all([
|
||||||
|
|||||||
Reference in New Issue
Block a user