add quilljs, create channel for syncing documents

This commit is contained in:
2023-11-24 19:07:52 -05:00
parent 7de2bad456
commit 52a7a64d23
35 changed files with 1092 additions and 250 deletions

View File

@@ -0,0 +1,35 @@
defmodule PoexWeb.PadLive do
alias Poex.Pads
alias Poex.Pads.Document
alias Poex.Repo
alias Poex.Utils
use PoexWeb, :live_view
def mount(%{"id" => "new"}, _session, socket) do
# Create a new PadDocument
{:ok, new_document} =
Document.changeset(%Document{}, %{title: "Untitled"})
|> Repo.insert()
Poex.Pads.DocumentDynamicSupervisor.start_document_supervisor(new_document)
# Redirect to the new document with its ID
{:ok, push_navigate(socket, to: ~p"/pad/#{new_document.id}", replace: true)}
end
def mount(%{"id" => id}, _session, socket) do
%{
id: id,
title: title,
state: state
} = Repo.get!(Document, id)
# init editor and assigns with latest state from doc
{:ok, assign(socket, id: id, title: title, state: state |> Utils.atomize_keys())}
end
def handle_info(:new_document, socket) do
{:noreply, push_navigate(socket, to: "/pad/new")}
end
end

View File

@@ -0,0 +1,5 @@
<main class="container h-96 mx-auto py-12">
<div id="poex-text-editor" phx-hook="TextEditor" data-pad-id={@id} class="flex-auto">
</div>
</main>