Pārlūkot izejas kodu

Fix compilation warnings

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

+ 1 - 1
config/dev.exs

@@ -7,7 +7,7 @@ use Mix.Config
 # watchers to your application. For example, we use it
 # with webpack to recompile .js and .css sources.
 config :vaccins, VaccinsWeb.Endpoint,
-  http: [port: 4004],
+  http: [port: 4005],
   debug_errors: true,
   code_reloader: true,
   check_origin: false,

+ 21 - 24
lib/vaccins/location_store.ex

@@ -23,9 +23,7 @@ defmodule Vaccins.LocationStore do
         when params != [],
         do: %{l | availability_query: params |> provider.new}
 
-    def query_availability(
-          l = %Location{id: id, availability_query: q, booking_page: bp, provider: provider}
-        ) do
+    def query_availability(%Location{availability_query: q, provider: provider}) do
       with url <- q |> provider.to_url() |> URI.to_string(),
            {:ok, result} <- url |> Vaccins.Scraper.get_json() do
         case result |> provider.analyze_result() do
@@ -120,29 +118,28 @@ defmodule Vaccins.LocationStore do
   def handle_call({:add_location, params}, _, state = %{locations: locations}) do
     cs = params |> LocationRaw.changeset()
 
-    resp =
-      with {:ok, raw_location} <- cs |> apply_action(:insert),
-           processed <-
-             %Location{
-               name: raw_location.name,
-               location: raw_location.location,
-               booking_page: raw_location.booking_page,
-               availability_query_params: raw_location |> LocationRaw.to_query_params(),
-               provider: Doctolib
-             }
-             |> Location.set_id(),
-           locations <- locations |> Map.put(processed.id, processed),
-           new_state <- %{locations: locations},
-           :ok <- new_state |> dump_state do
-        :ok
-        {:reply, :ok, new_state}
-      else
-        e = {:error, _} -> {:reply, e, state}
-      end
+    with {:ok, raw_location} <- cs |> apply_action(:insert),
+         processed <-
+           %Location{
+             name: raw_location.name,
+             location: raw_location.location,
+             booking_page: raw_location.booking_page,
+             availability_query_params: raw_location |> LocationRaw.to_query_params(),
+             provider: Doctolib
+           }
+           |> Location.set_id(),
+         locations <- locations |> Map.put(processed.id, processed),
+         new_state <- %{locations: locations},
+         :ok <- new_state |> dump_state do
+      :ok
+      {:reply, :ok, new_state}
+    else
+      e = {:error, _} -> {:reply, e, state}
+    end
   end
 
   @impl true
-  def handle_call({:delete_location, id}, _, state = %{locations: locations}) do
+  def handle_call({:delete_location, id}, _, %{locations: locations}) do
     with locations <- locations |> Map.delete(id),
          new_state <- %{locations: locations},
          :ok <- new_state |> dump_state,
@@ -159,7 +156,7 @@ defmodule Vaccins.LocationStore do
         do: decoded |> Enum.map(&Location.from_json/1)
       )
 
-  defp dump_state(state = %{locations: locations}), do: locations |> Map.values() |> write_file()
+  defp dump_state(%{locations: locations}), do: locations |> Map.values() |> write_file()
 
   defp write_file(locations),
     do:

+ 1 - 1
lib/vaccins/poller.ex

@@ -20,7 +20,7 @@ defmodule Vaccins.Poller do
   end
 
   @impl true
-  def handle_info({:location_availabilities, id, res}, state = %{locations: locations}) do
+  def handle_info({:location_availabilities, id, res}, state) do
     Phoenix.PubSub.broadcast(Vaccins.PubSub, "locations", {:new_availabilities, id, res})
     {:noreply, state}
   end

+ 1 - 1
lib/vaccins/queries.ex

@@ -52,7 +52,7 @@ defmodule Vaccins.Queries do
        |> Enum.concat()
        |> Enum.map(& &1.start_date)
        |> Enum.map(
-         &with {:ok, date, offset} <- &1 |> DateTime.from_iso8601(),
+         &with {:ok, date, _offset} <- &1 |> DateTime.from_iso8601(),
                {:ok, converted} <-
                  date |> DateTime.shift_zone("Europe/Paris", Tzdata.TimeZoneDatabase),
                do: converted

+ 0 - 1
lib/vaccins/search.ex

@@ -1,5 +1,4 @@
 defmodule Vaccins.Search do
-  alias Vaccins.Scraper
   alias Vaccins.LocationStore.Location
 
   def async_trigger_query(q, target \\ nil)

+ 13 - 18
lib/vaccins_web/live/index.ex

@@ -1,8 +1,6 @@
 defmodule VaccinsWeb.IndexLive do
   use VaccinsWeb, :live_view
-  alias Vaccins.{LocationStore, Search}
-
-  @refresh_period_ms 5 * 1000
+  alias Vaccins.LocationStore
 
   @impl true
   def mount(_params, %{"is_local?" => is_local?}, socket) do
@@ -82,18 +80,16 @@ defmodule VaccinsWeb.IndexLive do
     do: socket |> push_patch(to: Routes.index_path(socket, :index))
 
   @impl true
-  def handle_info({:new_availabilities, id, res}, socket = %{assigns: %{locations: valid}}) do
+  def handle_info({:new_availabilities, id, res}, socket) do
     send_update(VaccinsWeb.LocationComponent, id: id, availabilities: res)
     {:noreply, socket}
   end
 
-  defp locations_by_availability(
-         assigns = %{
-           locations: locations,
-           locations_with_slots: with_slots,
-           locations_with_early_slots: with_early_slots
-         }
-       ) do
+  defp locations_by_availability(%{
+         locations: locations,
+         locations_with_slots: with_slots,
+         locations_with_early_slots: with_early_slots
+       }) do
     locations
     |> Enum.sort(fn e1, e2 ->
       e1_has_early_spot? = e1.id in with_early_slots
@@ -101,13 +97,12 @@ defmodule VaccinsWeb.IndexLive do
       e2_has_early_spot? = e2.id in with_early_slots
       e2_has_spot? = e2.id in with_slots
 
-      res =
-        cond do
-          e2_has_early_spot? -> false
-          e2_has_spot? and not e1_has_early_spot? -> false
-          e2_has_spot? and e1_has_spot? -> false
-          true -> true
-        end
+      cond do
+        e2_has_early_spot? -> false
+        e2_has_spot? and not e1_has_early_spot? -> false
+        e2_has_spot? and e1_has_spot? -> false
+        true -> true
+      end
     end)
   end
 end

+ 8 - 8
lib/vaccins_web/live/location_component.ex

@@ -1,6 +1,6 @@
 defmodule VaccinsWeb.LocationComponent do
   use VaccinsWeb, :live_component
-  alias Vaccins.{LocationStore, Search}
+  alias Vaccins.LocationStore
 
   @impl true
   def mount(socket),
@@ -91,9 +91,9 @@ defmodule VaccinsWeb.LocationComponent do
     do: ~L"""
       <%= cond do %>
         <%= @loading -> %>...
-        <%= not has_slots?(assigns) -> %>Pas de créneau <%= if @last_early_slot_seen do %>(<%= @last_early_slot_seen |> DateTime.to_time() |> Time.truncate(:second) |> Time.to_string %>)<% end %>
-        <%= has_early_slots?(assigns) -> %><span class="alert-danger">Des dispos sous 24h !</span>
-        <%= has_slots?(assigns) -> %>Des dispos dans plus de 24h
+        <% not has_slots?(assigns) -> %>Pas de créneau <%= if @last_early_slot_seen do %>(<%= @last_early_slot_seen |> DateTime.to_time() |> Time.truncate(:second) |> Time.to_string %>)<% end %>
+        <% has_early_slots?(assigns) -> %><span class="alert-danger">Des dispos sous 24h !</span>
+        <% has_slots?(assigns) -> %>Des dispos dans plus de 24h
       <% end %>
     """
 
@@ -115,7 +115,7 @@ defmodule VaccinsWeb.LocationComponent do
       </ul>
     """
 
-  defp integrate_availabilities(assigns = %{availabilities: {:error, reason}}),
+  defp integrate_availabilities(assigns = %{availabilities: {:error, _reason}}),
     do:
       assigns
       |> Map.put(:slots_after, [])
@@ -138,10 +138,10 @@ defmodule VaccinsWeb.LocationComponent do
 
   defp integrate_availabilities(assigns), do: assigns
 
-  defp has_slots?(assigns = %{slots_before: before, slots_after: after_}),
+  defp has_slots?(%{slots_before: before, slots_after: after_}),
     do: not (before |> Enum.empty?() and after_ |> Enum.empty?())
 
-  defp has_early_slots?(assigns = %{slots_before: before}),
+  defp has_early_slots?(%{slots_before: before}),
     do: not (before |> Enum.empty?())
 
   defp get_refresh_time() do
@@ -164,6 +164,6 @@ defmodule VaccinsWeb.LocationComponent do
 
   defp signal_availabilities(socket), do: socket
 
-  defp to_json_query(l = %{availability_query: q, provider: provider}),
+  defp to_json_query(%{availability_query: q, provider: provider}),
     do: q |> provider.to_url() |> URI.to_string()
 end

+ 1 - 1
lib/vaccins_web/plugs.ex

@@ -1,7 +1,7 @@
 defmodule VaccinsWeb.Plugs do
   import Plug.Conn
 
-  def set_local_conn(conn = %{remote_ip: {ip1, _, _, _}}, opts) do
+  def set_local_conn(conn = %{remote_ip: {ip1, _, _, _}}, _opts) do
     is_local? = ip1 in [192, 127]
     conn |> assign(:is_local?, is_local?) |> put_session(:is_local?, is_local?)
   end