From 8b8ea11c530e01c1167c289354375847e7fc9f2f Mon Sep 17 00:00:00 2001 From: Pascal Schmid Date: Thu, 10 Oct 2024 11:19:16 +0200 Subject: [PATCH] Style upload form --- lib/mihainator_web/live/upload_live.ex | 23 +++--- lib/mihainator_web/live/upload_live.html.heex | 73 +++++++++++-------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/lib/mihainator_web/live/upload_live.ex b/lib/mihainator_web/live/upload_live.ex index ef66271..2622a0a 100644 --- a/lib/mihainator_web/live/upload_live.ex +++ b/lib/mihainator_web/live/upload_live.ex @@ -4,27 +4,26 @@ defmodule MihainatorWeb.UploadLive do @impl Phoenix.LiveView def mount(_params, _session, socket) do {:ok, - socket - |> assign(:uploaded_files, []) - |> allow_upload(:avatar, accept: ~w(.csv .jpeg))} + socket + |> assign(:uploaded_files, []) + |> assign(:submit_disabled?, true) + |> allow_upload(:history, accept: ~w(.csv))} end @impl Phoenix.LiveView def handle_event("validate", _params, socket) do - {:noreply, socket} - end - - @impl Phoenix.LiveView - def handle_event("cancel-upload", %{"ref" => ref}, socket) do - {:noreply, cancel_upload(socket, :avatar, ref)} + {:noreply, + socket + |> assign(:submit_disabled?, false)} end @impl Phoenix.LiveView def handle_event("save", _params, socket) do uploaded_files = - consume_uploaded_entries(socket, :avatar, fn %{path: path}, _entry -> - line_count = File.stream!(path) - |> Enum.count() + consume_uploaded_entries(socket, :history, fn %{path: path}, _entry -> + line_count = + File.stream!(path) + |> Enum.count() IO.puts(line_count) diff --git a/lib/mihainator_web/live/upload_live.html.heex b/lib/mihainator_web/live/upload_live.html.heex index 86a3dcd..14a895f 100644 --- a/lib/mihainator_web/live/upload_live.html.heex +++ b/lib/mihainator_web/live/upload_live.html.heex @@ -1,39 +1,52 @@ -
- +
+

Threema history checker

- <.live_file_input upload={@uploads.avatar} class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" /> - - -<%!-- use phx-drop-target with the upload ref to enable file drag and drop --%> -
- <%= for entry <- @uploads.avatar.entries do %> + + + + <%= for entry <- @uploads.history.entries do %>
- -
- <.live_img_preview entry={entry} /> -
<%= entry.client_name %>
-
- - <%!-- entry.progress will update automatically for in-flight entries --%> - <%= entry.progress %>% - - <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%> - - - <%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%> - <%= for err <- upload_errors(@uploads.avatar, entry) do %> + <%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%> + <%= for err <- upload_errors(@uploads.history, entry) do %>

<%= error_to_string(err) %>

- <% end %> - + <% end %>
- <% end %> + <% end %> + <%!-- use phx-drop-target with the upload ref to enable file drag and drop --%> +
<%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> - <%= for err <- upload_errors(@uploads.avatar) do %> -

<%= error_to_string(err) %>

+ <%= for err <- upload_errors(@uploads.history) do %> +

<%= error_to_string(err) %>

<% end %> - -
+
+