From fce682329dca11d6198095c2894fd9789e94c697 Mon Sep 17 00:00:00 2001 From: jxmoose Date: Tue, 9 Apr 2024 23:36:27 -0700 Subject: [PATCH] added linking from map --- src/app/exhibitsPage/page.tsx | 22 +++- .../userComponents/Exhibit/Exhibit.tsx | 2 +- .../SiteMap/DisplayPreviewCard.tsx | 122 +++++++++--------- src/supabase/exhibits/queries.tsx | 107 ++++----------- 4 files changed, 108 insertions(+), 145 deletions(-) diff --git a/src/app/exhibitsPage/page.tsx b/src/app/exhibitsPage/page.tsx index 43c0a5c7..a8625104 100644 --- a/src/app/exhibitsPage/page.tsx +++ b/src/app/exhibitsPage/page.tsx @@ -1,3 +1,4 @@ + 'use client'; import React, { useEffect, useState } from 'react'; @@ -11,10 +12,9 @@ import Exhibit from '../../components/userComponents/Exhibit/Exhibit'; /** * @param evt on click of button */ -function goBack(evt: React.SyntheticEvent) { +function goBack(evt : React.SyntheticEvent) { // ignore the native anchor action evt.preventDefault(); - window.history.back(); } @@ -42,7 +42,21 @@ function App() { setExhibits(fetchedExhibits); }; getExhibits(); + // Detect the hash in URL and scroll to the element with the corresponding ID }, [exhibits]); + + useEffect(() => { + const { hash } = window.location; + if (hash) { + setTimeout(() => { + const element = document.querySelector(hash); + const yOffset = -50; + const y = + element.getBoundingClientRect().top + window.scrollY + yOffset; + window.scrollTo({ top: y, behavior: 'smooth' }); + }, 1000); + } + }, []); return (
@@ -70,7 +84,7 @@ function App() { {exhibits.map(exhibit => ( +
  • diff --git a/src/components/userComponents/SiteMap/DisplayPreviewCard.tsx b/src/components/userComponents/SiteMap/DisplayPreviewCard.tsx index 19353bab..b6e5fb32 100644 --- a/src/components/userComponents/SiteMap/DisplayPreviewCard.tsx +++ b/src/components/userComponents/SiteMap/DisplayPreviewCard.tsx @@ -48,101 +48,105 @@ function DisplayPreviewCard({ useEffect(() => { const fetchDetails = async () => { setLoading(true); - - let imageUrl = ''; - let displayName = ''; - - if ('name' in tour) { + + let imageUrl = ''; + let displayName = ''; + + if ('name' in tour) { // Fetch images for a tour const images = await fetchImagesForTour(tour.id); if (images && images.length > 0) { - imageUrl = images[0].url; + imageUrl = images[0].url; } - displayName = tour.name; + displayName = tour.name; } else { // Handle as an ExhibitRow - const imageObj = await fetchExhibitImage(tour.id); + const imageObj = await fetchExhibitImage(tour.id); if (imageObj) { - imageUrl = imageObj.image; + imageUrl = imageObj.image; } - displayName = tour.title; + displayName = tour.title; } - + // Set state variables setPreviewImage(imageUrl); setname1(displayName); setLoading(false); }; - + fetchDetails(); }, [tour]); - /** route this to spotlights */ return ( -
    -