Split logic in multiple components
This commit is contained in:
@@ -1,30 +1,13 @@
|
||||
defmodule MihainatorWeb.UploadLive do
|
||||
@moduledoc false
|
||||
|
||||
use MihainatorWeb, :live_view
|
||||
|
||||
@impl Phoenix.LiveView
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:submit_disabled?, true)
|
||||
|> allow_upload(:history, accept: ~w(.csv))}
|
||||
end
|
||||
|
||||
@impl Phoenix.LiveView
|
||||
def handle_event("validate", _params, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:submit_disabled?, false)}
|
||||
end
|
||||
|
||||
@impl Phoenix.LiveView
|
||||
def handle_event("save", _params, socket) do
|
||||
consume_uploaded_entries(socket, :history, fn %{path: path}, _entry ->
|
||||
Task.async(fn -> Mihainator.Extractor.extract(path) end)
|
||||
|
||||
{:ok, nil}
|
||||
end)
|
||||
|
||||
{:noreply, socket}
|
||||
|> assign(:has_result, false)}
|
||||
end
|
||||
|
||||
@impl Phoenix.LiveView
|
||||
@@ -32,11 +15,8 @@ defmodule MihainatorWeb.UploadLive do
|
||||
def handle_info({ref, result}, socket) do
|
||||
Process.demonitor(ref, [:flush])
|
||||
|
||||
socket = assign(socket, :calendar_dates, result)
|
||||
socket = assign(socket, calendar_dates: result, has_result: true)
|
||||
|
||||
{:noreply, push_navigate(socket, to: ~p"/result")}
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp error_to_string(:too_large), do: "Too large"
|
||||
defp error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user