|
@@ -17,45 +17,32 @@ const CruiseSpace: React.FC = () => {
|
|
|
const t = CONTENT[language].shipsPage as any;
|
|
const t = CONTENT[language].shipsPage as any;
|
|
|
const location = useLocation();
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
-//
|
|
|
|
|
-// const params = new URLSearchParams(location.search);
|
|
|
|
|
-// const section = params.get('section');
|
|
|
|
|
-//
|
|
|
|
|
-// let elementId = '';
|
|
|
|
|
-// if (section === 'tips') {
|
|
|
|
|
-// elementId = 'guide-tips';
|
|
|
|
|
-// } else if (section === 'faq') {
|
|
|
|
|
-// elementId = 'guide-faq';
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// if (elementId) {
|
|
|
|
|
-// const element = document.getElementById(elementId);
|
|
|
|
|
-// if (element) {
|
|
|
|
|
-// element.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }, [location.search]);
|
|
|
|
|
-
|
|
|
|
|
-// Scroll to section on load or location change
|
|
|
|
|
|
|
+ // Scroll to section on load or location change
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ const SECTION_PREFIX = 'space-';
|
|
|
|
|
+ const SCROLL_DELAY = 300; // ms - delay to ensure DOM is fully rendered
|
|
|
|
|
+
|
|
|
const params = new URLSearchParams(location.search);
|
|
const params = new URLSearchParams(location.search);
|
|
|
const section = params.get('section');
|
|
const section = params.get('section');
|
|
|
- const preStr = 'space-';
|
|
|
|
|
- let elementId = preStr;
|
|
|
|
|
|
|
|
|
|
- // Always scroll to top first
|
|
|
|
|
if (!section) {
|
|
if (!section) {
|
|
|
|
|
+ // Scroll to top when no section specified
|
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
- } else {
|
|
|
|
|
- // Correctly construct elementId with section parameter
|
|
|
|
|
- elementId = preStr + section;
|
|
|
|
|
- const element = document.getElementById(elementId);
|
|
|
|
|
- if (element) {
|
|
|
|
|
- // Small delay to ensure render
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- element.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
- }, 300);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Construct element ID and scroll to target section
|
|
|
|
|
+ const elementId = `${SECTION_PREFIX}${section}`;
|
|
|
|
|
+ const element = document.getElementById(elementId);
|
|
|
|
|
+
|
|
|
|
|
+ if (element) {
|
|
|
|
|
+ // Delay to ensure DOM is fully rendered before scrolling
|
|
|
|
|
+ const timeoutId = setTimeout(() => {
|
|
|
|
|
+ element.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
|
|
|
+ }, SCROLL_DELAY);
|
|
|
|
|
+
|
|
|
|
|
+ // Cleanup timeout on unmount or search change
|
|
|
|
|
+ return () => clearTimeout(timeoutId);
|
|
|
}
|
|
}
|
|
|
}, [location.search]);
|
|
}, [location.search]);
|
|
|
|
|
|