diff --git a/src/components/Events.tsx b/src/components/Events.tsx index 4ca0057..253a748 100644 --- a/src/components/Events.tsx +++ b/src/components/Events.tsx @@ -9,7 +9,7 @@ import { type EventSection, type UpcomingEvent, } from "../utils/eventSections"; -import { copyAnchorLink, copyEventLink } from "../utils/copyAnchorLink"; +import { copyAnchorLink, copyEventLink, clearEventLinkParam } from "../utils/copyAnchorLink"; import { formatSpeakerList, getDescriptionExcerpt, @@ -735,7 +735,13 @@ export default function Events({ )} - setSelectedEvent(null)} /> + { + setSelectedEvent(null); + clearEventLinkParam(); + }} + /> ); } diff --git a/src/components/events/EventsNew.tsx b/src/components/events/EventsNew.tsx index e0f435d..8056254 100644 --- a/src/components/events/EventsNew.tsx +++ b/src/components/events/EventsNew.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef, useState } from "react"; import type { EventItem } from "../../store/eventsClient"; import { groupIntoSections, isEventPast } from "../../utils/eventSections"; +import { clearEventLinkParam } from "../../utils/copyAnchorLink"; import { EventModalContext, useVisitorZoneReady, @@ -119,7 +120,13 @@ export default function EventsNew({ initialEvents = [] }: EventsNewProps) { )} {selectedEvent && ( - setSelectedEvent(null)} /> + { + setSelectedEvent(null); + clearEventLinkParam(); + }} + /> )} diff --git a/src/utils/copyAnchorLink.ts b/src/utils/copyAnchorLink.ts index 50086fb..08867d5 100644 --- a/src/utils/copyAnchorLink.ts +++ b/src/utils/copyAnchorLink.ts @@ -30,3 +30,13 @@ export async function copyEventLink(id: string): Promise { return false; } } + +// Strips a `?event=` param left by copyEventLink (or a pasted deep link) once +// its modal is closed, so the URL doesn't keep pointing at an event that's no +// longer on screen. +export function clearEventLinkParam(): void { + const url = new URL(window.location.href); + if (!url.searchParams.has("event")) return; + url.searchParams.delete("event"); + history.replaceState(null, "", `${url.pathname}${url.search}${url.hash}`); +}