-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
454 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client"; | ||
|
||
import { useEffect } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
function AutoRefresh({ children }) { | ||
return children; | ||
} | ||
|
||
if (process.env.NODE_ENV === "development") { | ||
AutoRefresh = function AutoRefresh({ children }) { | ||
const router = useRouter(); | ||
useEffect(() => { | ||
const ws = new WebSocket("ws://localhost:3001"); | ||
ws.onmessage = (event) => { | ||
if (event.data === "refresh") { | ||
router.refresh(); | ||
} | ||
}; | ||
return () => { | ||
ws.close(); | ||
}; | ||
}, [router]); | ||
return children; | ||
}; | ||
} | ||
|
||
export default AutoRefresh; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
import Link from "./Link"; | ||
import HomeLink from "./HomeLink"; | ||
import AutoRefresh from "./AutoRefresh"; | ||
import { serif } from "./fonts"; | ||
import "./global.css"; | ||
|
||
export default function RootLayout({ children }) { | ||
return ( | ||
<html lang="en" className={serif.className}> | ||
<body className="mx-auto max-w-2xl bg-[--bg] px-5 py-12 text-[--text]"> | ||
<header className="mb-14 flex flex-row place-content-between"> | ||
<HomeLink /> | ||
<span className="relative top-[4px] italic"> | ||
by{" "} | ||
<Link href="https://danabra.mov" target="_blank"> | ||
<img | ||
alt="Dan Abramov" | ||
src="https://pbs.twimg.com/profile_images/1545194945161707520/rqkwPViA_400x400.jpg" | ||
className="relative -top-1 mx-1 inline h-8 w-8 rounded-full" | ||
/> | ||
</Link> | ||
</span> | ||
</header> | ||
<main>{children}</main> | ||
</body> | ||
</html> | ||
<AutoRefresh> | ||
<html lang="en" className={serif.className}> | ||
<body className="mx-auto max-w-2xl bg-[--bg] px-5 py-12 text-[--text]"> | ||
<header className="mb-14 flex flex-row place-content-between"> | ||
<HomeLink /> | ||
<span className="relative top-[4px] italic"> | ||
by{" "} | ||
<Link href="https://danabra.mov" target="_blank"> | ||
<img | ||
alt="Dan Abramov" | ||
src="https://pbs.twimg.com/profile_images/1545194945161707520/rqkwPViA_400x400.jpg" | ||
className="relative -top-1 mx-1 inline h-8 w-8 rounded-full" | ||
/> | ||
</Link> | ||
</span> | ||
</header> | ||
<main>{children}</main> | ||
</body> | ||
</html> | ||
</AutoRefresh> | ||
); | ||
} |
Oops, something went wrong.