diff --git a/web/src/routes/Event.jsx b/web/src/routes/Event.jsx index 761e515dd..54a142f66 100644 --- a/web/src/routes/Event.jsx +++ b/web/src/routes/Event.jsx @@ -1,5 +1,5 @@ import { h, Fragment } from 'preact'; -import { useCallback, useState } from 'preact/hooks'; +import { useCallback, useState, useEffect } from 'preact/hooks'; import ActivityIndicator from '../components/ActivityIndicator'; import Button from '../components/Button'; import Clip from '../icons/Clip'; @@ -11,13 +11,18 @@ import Heading from '../components/Heading'; import VideoPlayer from '../components/VideoPlayer'; import { FetchStatus, useApiHost, useEvent, useDelete } from '../api'; -export default function Event({ eventId, close }) { +export default function Event({ eventId, close, scrollIntoView }) { const apiHost = useApiHost(); const { data, status } = useEvent(eventId); const [showDialog, setShowDialog] = useState(false); const [deleteStatus, setDeleteStatus] = useState(FetchStatus.NONE); const setDeleteEvent = useDelete(); + useEffect(() => { + // Call Events.js scroll when this event has been mounted. + scrollIntoView(eventId); + }, []); + const handleClickDelete = () => { setShowDialog(true); }; diff --git a/web/src/routes/Events.jsx b/web/src/routes/Events.jsx index 35dbd0da3..ece0984f7 100644 --- a/web/src/routes/Events.jsx +++ b/web/src/routes/Events.jsx @@ -128,19 +128,16 @@ export default function Events({ path: pathname, limit = API_LIMIT } = {}) { //Set event id to be rendered. setViewEvent(id); + }; - //scroll the event into view + // Called from the mounted event.js to prevent + // race condition between scollIntoView and if component has been mounted. + const scrollIntoView = (id) => { if (id in scrollToRef) scrollToRef[id].scrollIntoView(); }; + const searchParams = useMemo(() => new URLSearchParams(searchString), [searchString]); - const viewEventById = (eventId) => ( -