add quilljs, create channel for syncing documents
This commit is contained in:
35
lib/poex_web/live/pad/pad_live.ex
Normal file
35
lib/poex_web/live/pad/pad_live.ex
Normal 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
|
5
lib/poex_web/live/pad/pad_live.html.heex
Normal file
5
lib/poex_web/live/pad/pad_live.html.heex
Normal 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>
|
Reference in New Issue
Block a user