Pārlūkot izejas kodu

Start index page

theenglishway (time) 4 gadi atpakaļ
vecāks
revīzija
779b1f169a

+ 20 - 0
lib/vaccins_web/live/index.ex

@@ -0,0 +1,20 @@
+defmodule VaccinsWeb.IndexLive do
+  use VaccinsWeb, :live_view
+  alias Vaccins.Queries
+
+  @impl true
+  def mount(_params, _session, socket) do
+    {:ok, socket |> assign(valid_queries: Queries.valid_queries())}
+  end
+
+  defp render_query(q) do
+    ~E"""
+      <dl class="show-metadata">
+        <dt>id</dt>
+        <dd><%= q.id %></dd>
+        <dt>booking page</dt>
+        <dd><%= link q.booking_page, to: q.booking_page %></dd>
+      </dl>
+    """
+  end
+end

+ 5 - 0
lib/vaccins_web/live/index_live.html.leex

@@ -0,0 +1,5 @@
+<ul>
+  <%= for q <- @valid_queries do %>
+    <li><%= q |> render_query %></li>
+  <% end %>
+</ul>

+ 0 - 39
lib/vaccins_web/live/page_live.ex

@@ -1,39 +0,0 @@
-defmodule VaccinsWeb.PageLive do
-  use VaccinsWeb, :live_view
-
-  @impl true
-  def mount(_params, _session, socket) do
-    {:ok, assign(socket, query: "", results: %{})}
-  end
-
-  @impl true
-  def handle_event("suggest", %{"q" => query}, socket) do
-    {:noreply, assign(socket, results: search(query), query: query)}
-  end
-
-  @impl true
-  def handle_event("search", %{"q" => query}, socket) do
-    case search(query) do
-      %{^query => vsn} ->
-        {:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")}
-
-      _ ->
-        {:noreply,
-         socket
-         |> put_flash(:error, "No dependencies found matching \"#{query}\"")
-         |> assign(results: %{}, query: query)}
-    end
-  end
-
-  defp search(query) do
-    if not VaccinsWeb.Endpoint.config(:code_reloader) do
-      raise "action disabled when not in development"
-    end
-
-    for {app, desc, vsn} <- Application.started_applications(),
-        app = to_string(app),
-        String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"),
-        into: %{},
-        do: {app, vsn}
-  end
-end

+ 0 - 48
lib/vaccins_web/live/page_live.html.leex

@@ -1,48 +0,0 @@
-<section class="phx-hero">
-  <h1><%= gettext "Welcome to %{name}!", name: "Phoenix" %></h1>
-  <p>Peace-of-mind from prototype to production</p>
-
-  <form phx-change="suggest" phx-submit="search">
-    <input type="text" name="q" value="<%= @query %>" placeholder="Live dependency search" list="results" autocomplete="off"/>
-    <datalist id="results">
-      <%= for {app, _vsn} <- @results do %>
-        <option value="<%= app %>"><%= app %></option>
-      <% end %>
-    </datalist>
-    <button type="submit" phx-disable-with="Searching...">Go to Hexdocs</button>
-  </form>
-</section>
-
-<section class="row">
-  <article class="column">
-    <h2>Resources</h2>
-    <ul>
-      <li>
-        <a href="https://hexdocs.pm/phoenix/overview.html">Guides &amp; Docs</a>
-      </li>
-      <li>
-        <a href="https://github.com/phoenixframework/phoenix">Source</a>
-      </li>
-      <li>
-        <a href="https://github.com/phoenixframework/phoenix/blob/v1.5/CHANGELOG.md">v1.5 Changelog</a>
-      </li>
-    </ul>
-  </article>
-  <article class="column">
-    <h2>Help</h2>
-    <ul>
-      <li>
-        <a href="https://elixirforum.com/c/phoenix-forum">Forum</a>
-      </li>
-      <li>
-        <a href="https://webchat.freenode.net/?channels=elixir-lang">#elixir-lang on Freenode IRC</a>
-      </li>
-      <li>
-        <a href="https://twitter.com/elixirphoenix">Twitter @elixirphoenix</a>
-      </li>
-      <li>
-        <a href="https://elixir-slackin.herokuapp.com/">Elixir on Slack</a>
-      </li>
-    </ul>
-  </article>
-</section>

+ 1 - 1
lib/vaccins_web/router.ex

@@ -17,7 +17,7 @@ defmodule VaccinsWeb.Router do
   scope "/", VaccinsWeb do
     pipe_through :browser
 
-    live "/", PageLive, :index
+    live "/", IndexLive, :index
   end
 
   # Other scopes may use custom stacks.

+ 0 - 15
lib/vaccins_web/templates/layout/root.html.leex

@@ -10,21 +10,6 @@
     <script defer phx-track-static type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
   </head>
   <body>
-    <header>
-      <section class="container">
-        <nav role="navigation">
-          <ul>
-            <li><a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a></li>
-            <%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
-              <li><%= link "LiveDashboard", to: Routes.live_dashboard_path(@conn, :home) %></li>
-            <% end %>
-          </ul>
-        </nav>
-        <a href="https://phoenixframework.org/" class="phx-logo">
-          <img src="<%= Routes.static_path(@conn, "/images/phoenix.png") %>" alt="Phoenix Framework Logo"/>
-        </a>
-      </section>
-    </header>
     <%= @inner_content %>
   </body>
 </html>