Skip to content

Commit

Permalink
feat: roomIDs on URL (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesara authored Dec 13, 2023
1 parent 1c00214 commit 181a37c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
13 changes: 6 additions & 7 deletions examples/tiptap/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TextEditor } from "@/components/TextEditor";
import { nanoid } from "nanoid";
import { redirect } from "next/navigation";

export default function Home() {
return (
<main>
<TextEditor />
</main>
);
function Page() {
redirect("/r/" + nanoid(6));
}

export default Page;
12 changes: 12 additions & 0 deletions examples/tiptap/src/app/r/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";
import { TextEditor } from "@/components/TextEditor";

export default function Home() {
const [, , roomID] = location.pathname.split("/");

return (
<main>
<TextEditor roomID={roomID} />
</main>
);
}
9 changes: 3 additions & 6 deletions examples/tiptap/src/components/TextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Editor />;
export function TextEditor({ roomID }: { roomID: string }) {
return <Editor roomID={roomID} />;
}

const USER_INFO = [
Expand Down Expand Up @@ -86,17 +86,14 @@ 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<Y.Doc>();
const [provider, setProvider] = useState<Provider>();

useEffect(() => {
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,
Expand Down

0 comments on commit 181a37c

Please sign in to comment.