Create a test liveview page
This commit is contained in:
		
							parent
							
								
									113b1ad2d6
								
							
						
					
					
						commit
						3786df57c3
					
				
							
								
								
									
										21
									
								
								lib/chronoscope_web/live/index_live.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								lib/chronoscope_web/live/index_live.ex
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					defmodule ChronoscopeWeb.IndexLive do
 | 
				
			||||||
 | 
					  use ChronoscopeWeb, :live_view
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @topic "test"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def mount(_params, _session, socket) do
 | 
				
			||||||
 | 
					    ChronoscopeWeb.Endpoint.subscribe(@topic)
 | 
				
			||||||
 | 
					    ChronoscopeWeb.Endpoint.broadcast_from(self(), @topic, "", %{temperature: 100})
 | 
				
			||||||
 | 
					    {:ok, assign(socket, :temperature, 100)}
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def handle_event("inc_temperature", _params, socket) do
 | 
				
			||||||
 | 
					    updated = socket.assigns.temperature + 1
 | 
				
			||||||
 | 
					    ChronoscopeWeb.Endpoint.broadcast_from(self(), @topic, "", %{temperature: updated})
 | 
				
			||||||
 | 
					    {:noreply, assign(socket, :temperature, updated)}
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def handle_info(%{topic: @topic, payload: state}, socket) do
 | 
				
			||||||
 | 
					    {:noreply, assign(socket, state)}
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										6
									
								
								lib/chronoscope_web/live/index_live.html.heex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								lib/chronoscope_web/live/index_live.html.heex
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					<div>
 | 
				
			||||||
 | 
					    Live!
 | 
				
			||||||
 | 
					    <br />
 | 
				
			||||||
 | 
					    Current temperature: <%= @temperature %>°F
 | 
				
			||||||
 | 
					    <button phx-click="inc_temperature">+</button>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
@ -14,6 +14,12 @@ defmodule ChronoscopeWeb.Router do
 | 
				
			|||||||
    plug :accepts, ["json"]
 | 
					    plug :accepts, ["json"]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  scope "/test", ChronoscopeWeb do
 | 
				
			||||||
 | 
					    pipe_through :browser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    live "/", IndexLive
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  scope "/", ChronoscopeWeb do
 | 
					  scope "/", ChronoscopeWeb do
 | 
				
			||||||
    pipe_through :browser
 | 
					    pipe_through :browser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user