Skip to content

Commit

Permalink
experiment with routing
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Feb 5, 2024
1 parent 2dcd566 commit 6ee04f1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 17 deletions.
19 changes: 16 additions & 3 deletions web/src/components/Overlay/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { Tldraw, TldrawProps } from '@tldraw/tldraw';
import { Tldraw, TldrawProps, useEditor } from '@tldraw/tldraw';
import '@tldraw/tldraw/tldraw.css';
import { useYjsStore } from '../../hooks/useYjsStore';
import { useStore } from '../../store';


export function Editor(props: Partial<TldrawProps>) {
type Props = {
overlayId: string;
readonly?: boolean;
}

export function Editor(props: Partial<TldrawProps> & Props) {
const yjsWsUrl = useStore(state => state.yjsWsUrl);
const store = useYjsStore({
roomId: 'example17',
roomId: props.overlayId,
hostUrl: yjsWsUrl,
});
const editor = useEditor();


if (props.readonly && editor) {
console.log(editor);
// editor.setCamera({ x: 0, y: 0, z: 1 });
// editor.updateInstanceState({ isReadonly: true, canMoveCamera: false })
}

return <Tldraw inferDarkMode store={store} {...props} />
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import dynamic from 'next/dynamic';
import Head from 'next/head';
import { useParams } from 'next/navigation';

const Editor = dynamic(async () => (await import('./Editor')).Editor, { ssr: false })

export function OverlayPage() {
export function IframeOverlayPage() {
const { overlayId } = useParams<{ overlayId: string }>();

return (
<div className="relative w-full h-[100vh]">
<Head>
Expand All @@ -19,7 +22,7 @@ export function OverlayPage() {
}
`}</style>
</Head>
<Editor hideUi />
<Editor hideUi overlayId={overlayId} readonly />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dynamic from "next/dynamic";
import { useUserConfig } from "../../hooks/useUserConfig";
const Editor = dynamic(async () => (await import('./../Overlay/Editor')).Editor, { ssr: false })
const Editor = dynamic(async () => (await import('./Editor')).Editor, { ssr: false })

export function OverlaysPage() {
const [userCfg, setUserConfig, , loading, errorMessage] = useUserConfig();
Expand All @@ -9,6 +9,6 @@ export function OverlaysPage() {
}

return <div className="relative w-full h-[100vh]">
<Editor />
Table with overlays
</div>;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { initializeStore } from "../../service/initializeStore";
import { OverlayPage } from "../../components/Overlay/OverlayPage";
import { IframeOverlayPage } from "../../components/Overlay/IframeOverlayPage";

export default function Overlay() {
return <OverlayPage />
return <IframeOverlayPage />
}

export const getServerSideProps = initializeStore;
13 changes: 13 additions & 0 deletions web/src/pages/overlay/edit/[overlayId].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client';

import dynamic from "next/dynamic";
import { useParams } from "next/navigation";
const Editor = dynamic(async () => (await import('../../../components/Overlay/Editor')).Editor, { ssr: false })

export default function OverlaysEditPage() {
const params = useParams<{ overlayId: string }>();

return <div className="relative w-full h-[100vh]">
<Editor overlayId={params.overlayId} />
</div>;
}
8 changes: 8 additions & 0 deletions web/src/pages/overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { OverlaysPage } from "../../components/Overlay/OverlaysPage";
import { initializeStore } from "../../service/initializeStore";

export default function OverlaysPageRoute() {
return <OverlaysPage />
}

export const getServerSideProps = initializeStore;
8 changes: 0 additions & 8 deletions web/src/pages/overlays.tsx

This file was deleted.

0 comments on commit 6ee04f1

Please sign in to comment.