From 181a37cd13d7332cfbe45af7b77d772cae801616 Mon Sep 17 00:00:00 2001 From: Cesar Alaestante Date: Wed, 13 Dec 2023 12:27:56 -0700 Subject: [PATCH] feat: roomIDs on URL (#30) --- examples/tiptap/src/app/page.tsx | 13 ++++++------- examples/tiptap/src/app/r/[id]/page.tsx | 12 ++++++++++++ examples/tiptap/src/components/TextEditor.tsx | 9 +++------ 3 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 examples/tiptap/src/app/r/[id]/page.tsx diff --git a/examples/tiptap/src/app/page.tsx b/examples/tiptap/src/app/page.tsx index 7eed77a..8765971 100644 --- a/examples/tiptap/src/app/page.tsx +++ b/examples/tiptap/src/app/page.tsx @@ -1,9 +1,8 @@ -import { TextEditor } from "@/components/TextEditor"; +import { nanoid } from "nanoid"; +import { redirect } from "next/navigation"; -export default function Home() { - return ( -
- -
- ); +function Page() { + redirect("/r/" + nanoid(6)); } + +export default Page; diff --git a/examples/tiptap/src/app/r/[id]/page.tsx b/examples/tiptap/src/app/r/[id]/page.tsx new file mode 100644 index 0000000..aa214fa --- /dev/null +++ b/examples/tiptap/src/app/r/[id]/page.tsx @@ -0,0 +1,12 @@ +"use client"; +import { TextEditor } from "@/components/TextEditor"; + +export default function Home() { + const [, , roomID] = location.pathname.split("/"); + + return ( +
+ +
+ ); +} diff --git a/examples/tiptap/src/components/TextEditor.tsx b/examples/tiptap/src/components/TextEditor.tsx index 8fb3540..47cd53b 100644 --- a/examples/tiptap/src/components/TextEditor.tsx +++ b/examples/tiptap/src/components/TextEditor.tsx @@ -23,8 +23,8 @@ import { Provider, mutators as yjsMutators } from "@rocicorp/reflect-yjs"; import { Reflect } from "@rocicorp/reflect/client"; import { nanoid } from "nanoid"; -export function TextEditor() { - return ; +export function TextEditor({ roomID }: { roomID: string }) { + return ; } const USER_INFO = [ @@ -86,7 +86,7 @@ if (!server) { } // Collaborative text editor with simple rich text and live cursors -export function Editor() { +export function Editor({ roomID }: { roomID: string }) { const [doc, setDoc] = useState(); const [provider, setProvider] = useState(); @@ -94,9 +94,6 @@ export function Editor() { console.log("creating new reflect instance"); const userID = nanoid(); - const roomID = - new URLSearchParams(location.search).get("roomID") ?? - `r-${Math.floor(new Date().getTime() / (1000 * 60 * 60))}`; const reflect = new Reflect({ server,