This commit is contained in:
bobbert committed 2025-03-16 21:50:38 +00:00
1 parent 25e877cc3a
commit 2236dceac9
4 files changed
+441 -125

No files matched your search

+75 -13
View File
@@ -15,6 +15,7 @@ import {
updateCluePointStatus,
attachClueClickHandlers,
} from "@/utils/map-populate";
import { addDebugOverlay, fixCluePointsRendering } from "@/utils/map-debug";
export default function MapPage() {
const { data: session, status } = useSession();
@@ -565,28 +566,73 @@ export default function MapPage() {
}
}, [status, fetchClues, loadAndEnhanceMap, router]);
// Modified useEffect to better handle SVG loading and enhancement
// Modified useEffect to ensure SVG elements are visible
useEffect(() => {
// Only try to enhance the map if both the SVG and clues are loaded
if (!mapSvg || !clues.length) return;
console.log("Both SVG and clues are loaded, preparing to enhance map");
// Ensure the SVG is fully loaded in the DOM before enhancing
requestAnimationFrame(() => {
// Longer timeout to ensure the SVG is fully rendered in the DOM
setTimeout(() => {
if (
mapContainerRef.current &&
mapContainerRef.current.querySelector("svg")
) {
console.log("SVG found in DOM, enhancing map now");
enhanceSvgMap();
let enhancementAttempts = 0;
const maxAttempts = 3;
function attemptMapEnhancement() {
enhancementAttempts++;
console.log(
`Map enhancement attempt ${enhancementAttempts}/${maxAttempts}`
);
if (
mapContainerRef.current &&
mapContainerRef.current.querySelector("svg")
) {
const svgElement = mapContainerRef.current.querySelector("svg");
console.log("SVG found in DOM, enhancing map now");
// Try to enhance the map
enhanceSvgMap();
// Additional check after brief delay to ensure visibility
setTimeout(() => {
const cluePoints = svgElement.querySelectorAll(".clue-point");
console.log(
`Found ${cluePoints.length} clue points after enhancement`
);
if (cluePoints.length === 0 && enhancementAttempts < maxAttempts) {
console.log(
`No clue points found, retrying (attempt ${enhancementAttempts}/${maxAttempts})`
);
attemptMapEnhancement();
} else if (cluePoints.length === 0) {
console.error(
`Failed to create clue points after ${maxAttempts} attempts`
);
// Fix rendering issues as a last resort
fixCluePointsRendering(svgElement);
} else {
console.log(
"Map enhancement successful, fixing any rendering issues"
);
fixCluePointsRendering(svgElement);
}
}, 300);
} else {
console.error("SVG not found in DOM after rendering timeout");
if (enhancementAttempts < maxAttempts) {
// Try again after a delay
setTimeout(attemptMapEnhancement, 500);
} else {
console.error("SVG not found in DOM after rendering timeout");
setMapError(true);
}
}, 500); // Increased timeout for better reliability on slower devices
}
}
// Ensure the SVG is fully loaded in the DOM before enhancing
requestAnimationFrame(() => {
// Initial delay before first attempt
setTimeout(attemptMapEnhancement, 300);
});
}, [mapSvg, clues, enhanceSvgMap]);
@@ -669,6 +715,22 @@ export default function MapPage() {
</div>
</div>
{/* Add a refresh button for users if they have issues with the map */}
{mapSvg && (
<button
className={styles["refresh-map-button"]}
onClick={() => {
const svgElement = mapContainerRef.current?.querySelector("svg");
if (svgElement) {
enhanceSvgMap();
setTimeout(() => fixCluePointsRendering(svgElement), 300);
}
}}
>
Refresh Map
</button>
)}
{/* Navigation bar */}
<nav className={styles["nav-bar"]}>
<Link