diff --git a/src/components/AwesomeArcadeList/extension.tsx b/src/components/AwesomeArcadeList/extension.tsx index 3662a0f..1786c66 100644 --- a/src/components/AwesomeArcadeList/extension.tsx +++ b/src/components/AwesomeArcadeList/extension.tsx @@ -9,13 +9,16 @@ import { copyTextToClipboard } from "@/scripts/Utils/Clipboard"; import Link from "next/link"; import { smoothScrollHash } from "@/components/AwesomeArcadeList/linkableHeader"; import { AnalyticEvents } from "@/components/Analytics"; +import { useRouter } from "next/router"; export function AwesomeArcadeExtension({ ext, + highlight, showImportURL, pad, }: { ext: Extension; + highlight?: boolean | undefined; showImportURL?: boolean | undefined; pad?: boolean | undefined; }): JSX.Element { @@ -62,7 +65,12 @@ export function AwesomeArcadeExtension({ }, [tooltip]); return ( -
+
(undefined); + + const onHashChange = (e?: HashChangeEvent | undefined) => { + const repo = e + ? e.newURL.split("#")[1] + : window.location.hash.replaceAll("#", ""); + console.log(`Changing extension to highlight ${repo}`); + setExtToHighlight(repo); + }; + + React.useEffect(() => { + setTimeout(() => { + onHashChange(); + }); + + window.addEventListener("hashchange", onHashChange); + return () => { + window.removeEventListener("hashchange", onHashChange); + }; + }, []); + + React.useEffect(() => { + router.events.on("routeChangeComplete", () => { + onHashChange(); + }); + + return () => + router.events.off("routeChangeComplete", () => { + onHashChange(); + }); + }, [router.events]); + return (
{title} @@ -227,6 +271,7 @@ export function AwesomeArcadeExtensionGroup({
diff --git a/src/components/AwesomeArcadeList/linkableHeader.tsx b/src/components/AwesomeArcadeList/linkableHeader.tsx index b83f59e..335ec51 100644 --- a/src/components/AwesomeArcadeList/linkableHeader.tsx +++ b/src/components/AwesomeArcadeList/linkableHeader.tsx @@ -6,10 +6,12 @@ export function smoothScrollHash( e: React.MouseEvent ) { e.preventDefault(); - const hash = e.currentTarget.href.split("#")[1]; + const href = e.currentTarget.href; setTimeout(() => { + const hash = href.split("#")[1]; console.log(`Smooth scrolling to ${hash}`); smoothScrollToID(hash); + window.dispatchEvent(new HashChangeEvent("hashchange", { newURL: href })); }); } @@ -17,6 +19,7 @@ export function smoothScrollToID(id: string) { const e = document.getElementById(id); e?.scrollIntoView({ behavior: "smooth", + block: "center", }); const u = new URL(window.location.toString()); u.hash = id; diff --git a/src/components/AwesomeArcadeList/tool.tsx b/src/components/AwesomeArcadeList/tool.tsx index 45ec5e4..5f9e55f 100644 --- a/src/components/AwesomeArcadeList/tool.tsx +++ b/src/components/AwesomeArcadeList/tool.tsx @@ -3,18 +3,26 @@ import React from "react"; import Link from "next/link"; import { smoothScrollHash } from "@/components/AwesomeArcadeList/linkableHeader"; import { AnalyticEvents } from "@/components/Analytics"; +import { useRouter } from "next/router"; export function AwesomeArcadeTool({ tool, + highlight, pad, }: { tool: Tool; + highlight?: boolean | undefined; pad?: boolean | undefined; }): JSX.Element { const [showCardLink, setShowCardLink] = React.useState(false); return ( -
+
(undefined); + + const onHashChange = (e?: HashChangeEvent | undefined) => { + const repo = e + ? e.newURL.split("#")[1] + : window.location.hash.replaceAll("#", ""); + console.log(`Changing tool to highlight ${repo}`); + setToolToHighlight(repo); + }; + + React.useEffect(() => { + setTimeout(() => { + onHashChange(); + }); + + window.addEventListener("hashchange", onHashChange); + return () => { + window.removeEventListener("hashchange", onHashChange); + }; + }, []); + + React.useEffect(() => { + router.events.on("routeChangeComplete", () => { + onHashChange(); + }); + + return () => + router.events.off("routeChangeComplete", () => { + onHashChange(); + }); + }, [router.events]); + return (
{title} @@ -154,7 +198,11 @@ export function AwesomeArcadeToolGroup({ {tools.map((tool, i) => { return (
- +
); })} diff --git a/src/components/Layout/layout.tsx b/src/components/Layout/layout.tsx index f19cc21..04a88b1 100644 --- a/src/components/Layout/layout.tsx +++ b/src/components/Layout/layout.tsx @@ -101,10 +101,10 @@ LayoutProps): JSX.Element { const baseURL = (() => { switch (appProps.environment) { case "production": { - return "https://awesome-arcade-extensions.vercel.app"; + return "https://awesome-arcade.vercel.app"; } case "preview": { - return "https://awesome-arcade-extensions-beta.vercel.app"; + return "https://awesome-arcade-beta.vercel.app"; } case "development": { return "http://localhost:3000"; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index bb59a8e..1cf9e6c 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -8,6 +8,7 @@ import Adsense from "../components/Adsense"; import Analytics from "../components/Analytics"; import ErrorBoundary from "../components/ErrorBoundary"; import { SessionProvider } from "next-auth/react"; +import { useRouter } from "next/router"; export default function AwesomeArcadeExtensions({ Component, @@ -17,6 +18,14 @@ export default function AwesomeArcadeExtensions({ import("bootstrap"); }, []); + const router = useRouter(); + + React.useEffect(() => { + window.addEventListener("popstate", () => { + router.push(window.location.href); + }); + }, [router]); + return (