basically working for one user (no user/all users actually)
This commit is contained in:
@ -17,8 +17,18 @@ import {Socket} from "phoenix"
|
||||
import NProgress from "nprogress"
|
||||
import {LiveSocket} from "phoenix_live_view"
|
||||
|
||||
let Hooks = {}
|
||||
Hooks.SnippetInput = {
|
||||
updated(){
|
||||
// + cursor reposition logic
|
||||
// console.log(['dings', this.el.dataset])
|
||||
this.el.value = this.el.dataset.updatedVal
|
||||
// this.el.select()
|
||||
}
|
||||
}
|
||||
|
||||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
||||
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
|
||||
let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})
|
||||
|
||||
// Show progress bar on live navigation and form submits
|
||||
window.addEventListener("phx:page-loading-start", info => NProgress.start())
|
||||
|
||||
38
lib/clip_web/live/board_live.ex
Normal file
38
lib/clip_web/live/board_live.ex
Normal file
@ -0,0 +1,38 @@
|
||||
defmodule ClipWeb.BoardLive do
|
||||
use ClipWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~L"""
|
||||
<form phx-change="paste">
|
||||
<input type="text" name="snippet" value="<%= @snippet %>" data-updated-val="<%= @snippet %>" phx-hook="SnippetInput" autocomplete="off"/>
|
||||
</form>
|
||||
Current content: <%= @snippet %>
|
||||
<button phx-click="normalize">
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
Phoenix.PubSub.subscribe(Clip.PubSub, "everybody") # actually only for single user
|
||||
{:ok, assign(socket, snippet: "")}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("normalize", _, %{"snippet" => snippet} = socket) do
|
||||
|
||||
Phoenix.PubSub.broadcast(Clip.PubSub, "everybody", {:snippet_pasted, %{"snippet" => snippet}})
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("paste", %{"snippet" => snippet}, socket) do
|
||||
Phoenix.PubSub.broadcast(Clip.PubSub, "everybody", {:snippet_pasted, %{"snippet" => snippet}})
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:snippet_pasted, %{"snippet" => snippet}}, socket) do
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
end
|
||||
@ -17,7 +17,8 @@ defmodule ClipWeb.Router do
|
||||
scope "/", ClipWeb do
|
||||
pipe_through :browser
|
||||
|
||||
live "/", PageLive, :index
|
||||
# live "/", PageLive, :index
|
||||
live "/", BoardLive, :index
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
Reference in New Issue
Block a user