<%= error_to_string(err) %>
+ <% end %> +diff --git a/lib/mihainator_web/live/file_input_component.ex b/lib/mihainator_web/live/file_input_component.ex new file mode 100644 index 0000000..9efb021 --- /dev/null +++ b/lib/mihainator_web/live/file_input_component.ex @@ -0,0 +1,34 @@ +defmodule MihainatorWeb.FileInputComponent do + @moduledoc false + + use Phoenix.LiveComponent + + @impl true + def mount(socket) do + {:ok, + socket + |> assign(:submit_disabled?, true) + |> allow_upload(:history, accept: ~w(.csv))} + end + + @impl true + def handle_event("validate", _params, socket) do + {:noreply, + socket + |> assign(:submit_disabled?, false)} + end + + @impl true + 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} + 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 diff --git a/lib/mihainator_web/live/file_input_component.html.heex b/lib/mihainator_web/live/file_input_component.html.heex new file mode 100644 index 0000000..8e9d00b --- /dev/null +++ b/lib/mihainator_web/live/file_input_component.html.heex @@ -0,0 +1,56 @@ +
Upload a Threema chat history file (.csv) and see who's more interactive!
+ + + + <%= for entry <- @uploads.history.entries do %> +<%= error_to_string(err) %>
+ <% end %> +<%= error_to_string(err) %>
+ <% end %> +This is the result of your history:
Upload a Threema chat history file (.csv) and see who's more interactive!
- - - - <%= for entry <- @uploads.history.entries do %> -<%= error_to_string(err) %>
- <% end %> -<%= error_to_string(err) %>
- <% end %> -