Merge pull request 'Change conflict file app.jsx' (#319) from Capacitorcookies into main
Reviewed-on: Pozomind/pozo-retail-app#319
This commit is contained in:
commit
e4561cf444
129
src/App.jsx
129
src/App.jsx
|
|
@ -8,7 +8,7 @@ import SelfBooking from './Pages/SelfBooking/SelfBooking.jsx';
|
||||||
import { isMobile, isIOS } from 'react-device-detect';
|
import { isMobile, isIOS } from 'react-device-detect';
|
||||||
import { routesConfig } from './routesConfig';
|
import { routesConfig } from './routesConfig';
|
||||||
import { GlobalItemCard } from './Features/BookingScreen/BookingData/BookingData.js';
|
import { GlobalItemCard } from './Features/BookingScreen/BookingData/BookingData.js';
|
||||||
import { clearSession, getSession } from './Services/Others.js';
|
import { clearSession, getSession, sessionStore } from './Services/Others.js';
|
||||||
|
|
||||||
const KisokSelBooking = lazy(
|
const KisokSelBooking = lazy(
|
||||||
() => import('./Pages/SelfBooking/KisokSelBooking')
|
() => import('./Pages/SelfBooking/KisokSelBooking')
|
||||||
|
|
@ -26,9 +26,11 @@ import useSubscriptionManager from './useSubscriptionManager.js';
|
||||||
import useSessionManager from './useSessionManager.js';
|
import useSessionManager from './useSessionManager.js';
|
||||||
import ExtendSubscriptionModal from './Pages/ExtentedModal/ExtendSubscriptionModal.jsx';
|
import ExtendSubscriptionModal from './Pages/ExtentedModal/ExtendSubscriptionModal.jsx';
|
||||||
import devtools from 'devtools-detect';
|
import devtools from 'devtools-detect';
|
||||||
|
import { useDevToolsDetection } from './utils/useDevToolsDetection.js';
|
||||||
|
import { Capacitor } from '@capacitor/core';
|
||||||
|
|
||||||
const isCapacitor = () => !!window.Capacitor?.isNativePlatform?.();
|
// const isCapacitor = () => !!window.Capacitor?.isNativePlatform?.();
|
||||||
|
const isCapacitor = () => Capacitor.isNativePlatform();
|
||||||
// ✅ Define your home/exit pages here
|
// ✅ Define your home/exit pages here
|
||||||
const HOME_PAGES = [
|
const HOME_PAGES = [
|
||||||
'/app-page/home', // android minimize
|
'/app-page/home', // android minimize
|
||||||
|
|
@ -54,7 +56,7 @@ const AppRoutes = () => {
|
||||||
const [devToolsOpen, setDevToolsOpen] = useState(false);
|
const [devToolsOpen, setDevToolsOpen] = useState(false);
|
||||||
// ✅ Flag to prevent stack push when back button navigates
|
// ✅ Flag to prevent stack push when back button navigates
|
||||||
const isBackNav = useRef(false);
|
const isBackNav = useRef(false);
|
||||||
|
console.log(isCapacitor(), 'Is Capacitor');
|
||||||
// ✅ Build navigation stack
|
// ✅ Build navigation stack
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Skip pushing to stack when back button caused this navigation
|
// Skip pushing to stack when back button caused this navigation
|
||||||
|
|
@ -69,13 +71,14 @@ const AppRoutes = () => {
|
||||||
// Don't track login pages
|
// Don't track login pages
|
||||||
if (LOGIN_PAGES.some((p) => path.includes(p))) return;
|
if (LOGIN_PAGES.some((p) => path.includes(p))) return;
|
||||||
|
|
||||||
const raw = sessionStorage.getItem('navStack');
|
const raw = getSession('navStack');
|
||||||
|
console.log('🎯 Current path:', path);
|
||||||
let stack = raw ? JSON.parse(raw) : [];
|
let stack = raw ? JSON.parse(raw) : [];
|
||||||
|
|
||||||
if (stack.length === 0 || stack[stack.length - 1] !== path) {
|
if (stack.length === 0 || stack[stack.length - 1] !== path) {
|
||||||
stack.push(path);
|
stack.push(path);
|
||||||
if (stack.length > 50) stack = stack.slice(-50);
|
if (stack.length > 50) stack = stack.slice(-50);
|
||||||
sessionStorage.setItem('navStack', JSON.stringify(stack));
|
sessionStore('navStack', JSON.stringify(stack));
|
||||||
console.log('📍 Stack:', stack);
|
console.log('📍 Stack:', stack);
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|
@ -89,7 +92,7 @@ const AppRoutes = () => {
|
||||||
const currentPath = location.pathname;
|
const currentPath = location.pathname;
|
||||||
|
|
||||||
const SessionId = getSession('SessionId');
|
const SessionId = getSession('SessionId');
|
||||||
|
console.log('SessionId:', SessionId, 'CurrentPath:', currentPath)
|
||||||
// 🟢 If session exists → allow navigation
|
// 🟢 If session exists → allow navigation
|
||||||
if (SessionId) {
|
if (SessionId) {
|
||||||
console.log('Browser back allowed');
|
console.log('Browser back allowed');
|
||||||
|
|
@ -116,101 +119,109 @@ const AppRoutes = () => {
|
||||||
|
|
||||||
const handler = async () => {
|
const handler = async () => {
|
||||||
try {
|
try {
|
||||||
const currentPath = location.pathname + (location.search || '');
|
const currentPath = window.location.pathname + window.location.search; // Bug 2 fix
|
||||||
console.log('🔙 Back pressed:', currentPath);
|
|
||||||
|
|
||||||
const raw = sessionStorage.getItem('navStack');
|
const raw = getSession('navStack');
|
||||||
let stack = raw ? JSON.parse(raw) : [];
|
let stack = raw ? JSON.parse(raw) : [];
|
||||||
|
|
||||||
// Remove current path from stack if it's at the end
|
|
||||||
while (stack.length && stack[stack.length - 1] === currentPath) {
|
while (stack.length && stack[stack.length - 1] === currentPath) {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are pages in history, go back to previous page
|
|
||||||
if (stack.length > 0) {
|
if (stack.length > 0) {
|
||||||
const previous = stack[stack.length - 1];
|
const previous = stack[stack.length - 1];
|
||||||
sessionStorage.setItem('navStack', JSON.stringify(stack));
|
sessionStore('navStack', JSON.stringify(stack));
|
||||||
isBackNav.current = true;
|
isBackNav.current = true; // Bug 3 fix — BEFORE navigate
|
||||||
navigate(previous);
|
navigate(previous);
|
||||||
console.log('Navigate to previous:', previous);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stack is empty - check where we are
|
|
||||||
// 🏠 Home page → minimize
|
|
||||||
if (HOME_PAGES?.some((p) => currentPath?.includes(p))) {
|
if (HOME_PAGES?.some((p) => currentPath?.includes(p))) {
|
||||||
console.log('Home page & empty stack → minimizing app');
|
|
||||||
await CapacitorApp.minimizeApp();
|
await CapacitorApp.minimizeApp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🚪 Login page → minimize
|
|
||||||
if (LOGIN_PAGES?.some((p) => currentPath?.includes(p))) {
|
if (LOGIN_PAGES?.some((p) => currentPath?.includes(p))) {
|
||||||
console.log('Login page & empty stack → minimizing app');
|
|
||||||
await CapacitorApp.minimizeApp();
|
await CapacitorApp.minimizeApp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anywhere else with empty stack → go to home
|
|
||||||
const home = '/app-page/home';
|
const home = '/app-page/home';
|
||||||
sessionStorage.setItem('navStack', JSON.stringify([home]));
|
isBackNav.current = true; // Bug 3 fix here too
|
||||||
isBackNav.current = true;
|
sessionStore('navStack', JSON.stringify([home]));
|
||||||
navigate(home);
|
navigate(home);
|
||||||
console.log('Empty stack, navigate to home');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Back handler error:', e);
|
console.error('Back handler error:', e);
|
||||||
await CapacitorApp.minimizeApp();
|
await CapacitorApp.minimizeApp();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const listener = CapacitorApp.addListener('backButton', handler);
|
const listenerPromise = CapacitorApp.addListener('backButton', handler); // Bug 1 fix
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
listener.remove();
|
listenerPromise.then(({ remove }) => remove());
|
||||||
};
|
};
|
||||||
}, [navigate,location.pathname, location.search]);
|
}, [navigate,location.pathname, location.search]);
|
||||||
// mohan
|
// mohan
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (isMobile || isIOS) {
|
// if (isMobile || isIOS) {
|
||||||
console.log('📱 Mobile/iOS device → skipping DevTools detection');
|
// console.log('📱 Mobile/iOS device → skipping DevTools detection');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const checkDevTools = setInterval(() => {
|
// const checkDevTools = setInterval(() => {
|
||||||
if (devtools.isOpen && !devToolsOpen) {
|
// if (devtools.isOpen && !devToolsOpen) {
|
||||||
setDevToolsOpen(true);
|
// setDevToolsOpen(true);
|
||||||
document.body.innerHTML =
|
// document.body.innerHTML =
|
||||||
"<h1 style='color: red; text-align: center;'>Close Inspect to continue using the application.</h1>";
|
// "<h1 style='color: red; text-align: center;'>Close Inspect to continue using the application.</h1>";
|
||||||
} else if (!devtools.isOpen && devToolsOpen) {
|
// } else if (!devtools.isOpen && devToolsOpen) {
|
||||||
setDevToolsOpen(false);
|
// setDevToolsOpen(false);
|
||||||
|
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
window.location.reload();
|
// window.location.reload();
|
||||||
}, 100);
|
// }, 100);
|
||||||
|
|
||||||
clearInterval(checkDevTools);
|
// clearInterval(checkDevTools);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!devtools.isOpen) {
|
// if (!devtools.isOpen) {
|
||||||
let before = performance.now();
|
// let before = performance.now();
|
||||||
|
|
||||||
let after = performance.now();
|
// let after = performance.now();
|
||||||
|
|
||||||
let executionDelay = after - before;
|
// let executionDelay = after - before;
|
||||||
|
|
||||||
if (executionDelay > 100) {
|
// if (executionDelay > 100) {
|
||||||
setDevToolsOpen(true);
|
// setDevToolsOpen(true);
|
||||||
document.body.innerHTML =
|
// document.body.innerHTML =
|
||||||
"<h1 style='color: red; text-align: center;'>Close Inspect to continue using the application.</h1>";
|
// "<h1 style='color: red; text-align: center;'>Close Inspect to continue using the application.</h1>";
|
||||||
} else {
|
// } else {
|
||||||
setDevToolsOpen(false);
|
// setDevToolsOpen(false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}, 1000);
|
// }, 1000);
|
||||||
|
|
||||||
return () => clearInterval(checkDevTools);
|
// return () => clearInterval(checkDevTools);
|
||||||
}, [devToolsOpen]);
|
// }, [devToolsOpen]);
|
||||||
|
// const isBlocked = useDevToolsDetection(() => {
|
||||||
|
// // optional: log, notify, etc.
|
||||||
|
// console.warn('DevTools detected');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (isBlocked) {
|
||||||
|
// return (
|
||||||
|
// <div style={{
|
||||||
|
// display: 'flex',
|
||||||
|
// justifyContent: 'center',
|
||||||
|
// alignItems: 'center',
|
||||||
|
// height: '100vh',
|
||||||
|
// flexDirection: 'column',
|
||||||
|
// gap: '1rem'
|
||||||
|
// }}>
|
||||||
|
// <h1 style={{ color: 'red' }}>
|
||||||
|
// DevTools detected. Please close it to continue.
|
||||||
|
// </h1>
|
||||||
|
// </div>
|
||||||
|
// );
|
||||||
|
// }
|
||||||
if (extendModel) {
|
if (extendModel) {
|
||||||
return (
|
return (
|
||||||
<ExtendSubscriptionModal
|
<ExtendSubscriptionModal
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue