• Operand
  • license? go ahead.

gram:page

> ./src/main.tsx

Lenses
(coming soon!)


import { isValidAutomergeUrl, Repo, Counter } from "@automerge/automerge-repo"
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket"
import { BroadcastChannelNetworkAdapter } from "@automerge/automerge-repo-network-broadcastchannel"
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb"
import { RepoContext } from "@automerge/automerge-repo-react-hooks"
import React from "react"
import ReactDOM from "react-dom/client"
import App from "./App.tsx"
import "./index.css"

const base = ReactDOM.createRoot(document.getElementById("base")!)

const repo = new Repo({
  network: [
    // new BrowserWebSocketClientAdapter("wss://sync.automerge.org"),
    new BroadcastChannelNetworkAdapter(),
  ],
  storage: new IndexedDBStorageAdapter("pages"),
})

let loadHandle = () => {
  const rootDocUrl = `${document.location.hash.substring(1)}`
  let handle = isValidAutomergeUrl(rootDocUrl)
    ? repo.find(rootDocUrl)
    : repo.create({ page: "Blank page." })
  return (document.location.hash = handle.url)
}

const render = (docUrl) => base.render(
  <React.StrictMode>
    <RepoContext.Provider value={repo}>
      <App docUrl={docUrl} />
    </RepoContext.Provider>
  </React.StrictMode>
)

render(loadHandle())