Minor changes

This commit is contained in:
Paul Carroll 2025-08-08 15:48:12 -04:00
parent c31291e95a
commit 9f85845973
2 changed files with 9 additions and 14 deletions

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from "react";
import { useGameGuard } from 'hooks'; import { useGameGuard } from "hooks";
import { RefreshGuardModal } from '../RefreshGuardModal/RefreshGuardModal'; import { RefreshGuardModal } from "../RefreshGuardModal/RefreshGuardModal";
interface RefreshGuardProviderProps { interface RefreshGuardProviderProps {
children: React.ReactNode; children: React.ReactNode;
@ -8,28 +8,26 @@ interface RefreshGuardProviderProps {
/** /**
* Provider component that wraps the entire app to provide refresh and navigation guarding. * Provider component that wraps the entire app to provide refresh and navigation guarding.
* Should be placed high in the component tree, ideally in AppShell.
*/ */
export const RefreshGuardProvider: React.FC<RefreshGuardProviderProps> = ({ children }) => { export const RefreshGuardProvider: React.FC<RefreshGuardProviderProps> = ({
children,
}) => {
const { const {
showNavigationModal, showNavigationModal,
setShowNavigationModal,
handleConfirmNavigation, handleConfirmNavigation,
handleCancelNavigation, handleCancelNavigation,
navigationMessage, navigationMessage,
showRefreshModal, showRefreshModal,
setShowRefreshModal,
handleConfirmRefresh, handleConfirmRefresh,
handleCancelRefresh, handleCancelRefresh,
refreshMessage, refreshMessage,
isInActiveGame, isInActiveGame,
shouldGuard
} = useGameGuard(); } = useGameGuard();
return ( return (
<> <>
{children} {children}
{/* Custom modal for SPA navigation (React Router) */} {/* Custom modal for SPA navigation (React Router) */}
<RefreshGuardModal <RefreshGuardModal
open={showNavigationModal} open={showNavigationModal}
@ -40,7 +38,7 @@ export const RefreshGuardProvider: React.FC<RefreshGuardProviderProps> = ({ chil
confirmButtonText={isInActiveGame ? "Leave Game" : "Leave Anyway"} confirmButtonText={isInActiveGame ? "Leave Game" : "Leave Anyway"}
cancelButtonText="Stay" cancelButtonText="Stay"
/> />
{/* Custom modal for browser refresh (after native dialog) */} {/* Custom modal for browser refresh (after native dialog) */}
<RefreshGuardModal <RefreshGuardModal
open={showRefreshModal} open={showRefreshModal}
@ -53,4 +51,4 @@ export const RefreshGuardProvider: React.FC<RefreshGuardProviderProps> = ({ chil
/> />
</> </>
); );
}; };

View file

@ -61,9 +61,6 @@ export const useNavigationGuard = ({
return; // Skip navigation guard if Router is not available return; // Skip navigation guard if Router is not available
} }
// Note: React Router v6 doesn't have built-in navigation blocking like v5
// We'll implement a custom solution by intercepting link clicks and form submissions
const handleLinkClick = (event: Event) => { const handleLinkClick = (event: Event) => {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
const link = target.closest('a'); const link = target.closest('a');