From a890cfab96c91f505b3a11435b9edaec0a67edaf Mon Sep 17 00:00:00 2001 From: Inhji Date: Wed, 22 Mar 2023 23:17:24 +0100 Subject: [PATCH] create admin_components --- lib/chiya_web.ex | 1 + lib/chiya_web/components/admin_components.ex | 132 +++++++++++++++++++ lib/chiya_web/components/core_components.ex | 122 ----------------- 3 files changed, 133 insertions(+), 122 deletions(-) create mode 100644 lib/chiya_web/components/admin_components.ex diff --git a/lib/chiya_web.ex b/lib/chiya_web.ex index 7f807b4..4f08afc 100644 --- a/lib/chiya_web.ex +++ b/lib/chiya_web.ex @@ -93,6 +93,7 @@ defmodule ChiyaWeb do alias Phoenix.LiveView.JS # Custom functions + import ChiyaWeb.AdminComponents import ChiyaWeb.Format, only: [from_now: 1, pretty_date: 1] alias ChiyaWeb.Markdown diff --git a/lib/chiya_web/components/admin_components.ex b/lib/chiya_web/components/admin_components.ex new file mode 100644 index 0000000..2a8220d --- /dev/null +++ b/lib/chiya_web/components/admin_components.ex @@ -0,0 +1,132 @@ +defmodule ChiyaWeb.AdminComponents do + + use Phoenix.Component + use Phoenix.VerifiedRoutes, + endpoint: ChiyaWeb.Endpoint, + router: ChiyaWeb.Router, + statics: ChiyaWeb.static_paths() + + import ChiyaWeb.CoreComponents + + @doc """ + Renders a UI for uploading files + """ + + attr :upload, :map, required: true + attr :cancel_upload, :string, default: "cancel-upload" + + def live_upload(assigns) do + ~H""" +
+ <.live_file_input upload={@upload} class="dark:text-gray-300" /> + +
+ <%= for entry <- @upload.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(@upload, entry) do %> +

<%= upload_error_to_string(err) %>

+ <% end %> +
+ <% end %> + + <%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> + <%= for err <- upload_errors(@upload) do %> +

<%= upload_error_to_string(err) %>

+ <% end %> +
+
+ """ + end + + @doc """ + Renders the admin menu bar + """ + + attr :current_user, :map, required: true + + def admin_bar(assigns) do + ~H""" + + """ + end + + defp upload_error_to_string(:too_large), do: "Too large" + defp upload_error_to_string(:too_many_files), do: "You have selected too many files" + defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type" +end \ No newline at end of file diff --git a/lib/chiya_web/components/core_components.ex b/lib/chiya_web/components/core_components.ex index db7e93c..d7719c7 100644 --- a/lib/chiya_web/components/core_components.ex +++ b/lib/chiya_web/components/core_components.ex @@ -27,124 +27,6 @@ defmodule ChiyaWeb.CoreComponents do """ end - @doc """ - Renders the admin menu bar - """ - - attr :current_user, :map, required: true - - def admin_bar(assigns) do - ~H""" - - """ - end - - @doc """ - Renders a UI for uploading files - """ - - attr :upload, :map, required: true - attr :cancel_upload, :string, default: "cancel-upload" - - def live_upload(assigns) do - ~H""" -
- <.live_file_input upload={@upload} class="dark:text-gray-300" /> - -
- <%= for entry <- @upload.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(@upload, entry) do %> -

<%= upload_error_to_string(err) %>

- <% end %> -
- <% end %> - - <%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> - <%= for err <- upload_errors(@upload) do %> -

<%= upload_error_to_string(err) %>

- <% end %> -
-
- """ - end - @doc """ Renders a modal. @@ -820,8 +702,4 @@ defmodule ChiyaWeb.CoreComponents do def translate_errors(errors, field) when is_list(errors) do for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts}) end - - defp upload_error_to_string(:too_large), do: "Too large" - defp upload_error_to_string(:too_many_files), do: "You have selected too many files" - defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type" end