diff --git a/lib/lokal_web/components/invite_card.ex b/lib/lokal_web/components/invite_card.ex index 31949bf5..8a58a7db 100644 --- a/lib/lokal_web/components/invite_card.ex +++ b/lib/lokal_web/components/invite_card.ex @@ -48,11 +48,9 @@ defmodule LokalWeb.Components.InviteCard do <%= render_slot(@code_actions) %> - <%= if @inner_block do %> -
- <%= render_slot(@inner_block) %> -
- <% end %> +
+ <%= render_slot(@inner_block) %> +
""" end diff --git a/lib/lokal_web/components/table_component.html.heex b/lib/lokal_web/components/table_component.html.heex index 1d0186da..002693b5 100644 --- a/lib/lokal_web/components/table_component.html.heex +++ b/lib/lokal_web/components/table_component.html.heex @@ -33,20 +33,16 @@ - <%= for values <- @rows do %> - - <%= for %{key: key} = value <- @columns do %> - - <%= case values |> Map.get(key) do %> - <% {_custom_sort_value, value} -> %> - <%= value %> - <% value -> %> - <%= value %> - <% end %> - + + + <%= case values |> Map.get(key) do %> + <% {_custom_sort_value, value} -> %> + <%= value %> + <% value -> %> + <%= value %> <% end %> - - <% end %> + + diff --git a/lib/lokal_web/components/topbar.ex b/lib/lokal_web/components/topbar.ex index 26e056fd..9e2ceff9 100644 --- a/lib/lokal_web/components/topbar.ex +++ b/lib/lokal_web/components/topbar.ex @@ -53,16 +53,14 @@ defmodule LokalWeb.Components.Topbar do <% end %> - <%= if @current_user.role == :admin do %> -
  • - <.link - navigate={Routes.invite_index_path(Endpoint, :index)} - class="text-white text-white hover:underline" - > - <%= gettext("Invites") %> - -
  • - <% end %> +
  • + <.link + navigate={Routes.invite_index_path(Endpoint, :index)} + class="text-white text-white hover:underline" + > + <%= gettext("Invites") %> + +
  • <.link navigate={Routes.user_settings_path(Endpoint, :edit)} @@ -80,27 +78,28 @@ defmodule LokalWeb.Components.Topbar do
  • - <%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %> -
  • - <.link - navigate={Routes.live_dashboard_path(Endpoint, :home)} - class="text-white text-white hover:underline" - > - - -
  • - <% end %> +
  • + <.link + navigate={Routes.live_dashboard_path(Endpoint, :home)} + class="text-white text-white hover:underline" + > + + +
  • <% else %> - <%= if Accounts.allow_registration?() do %> -
  • - <.link - navigate={Routes.user_registration_path(Endpoint, :new)} - class="text-white text-white hover:underline truncate" - > - <%= dgettext("actions", "Register") %> - -
  • - <% end %> +
  • + <.link + navigate={Routes.user_registration_path(Endpoint, :new)} + class="text-white text-white hover:underline truncate" + > + <%= dgettext("actions", "Register") %> + +
  • <.link navigate={Routes.user_session_path(Endpoint, :new)} diff --git a/lib/lokal_web/components/user_card.ex b/lib/lokal_web/components/user_card.ex index 4b77c014..2c3e11ab 100644 --- a/lib/lokal_web/components/user_card.ex +++ b/lib/lokal_web/components/user_card.ex @@ -10,8 +10,8 @@ defmodule LokalWeb.Components.UserCard do

    <%= @user.email %> @@ -39,11 +39,9 @@ defmodule LokalWeb.Components.UserCard do

    - <%= if @inner_block do %> -
    - <%= render_slot(@inner_block) %> -
    - <% end %> +
    + <%= render_slot(@inner_block) %> +
    """ end diff --git a/lib/lokal_web/live/home_live.ex b/lib/lokal_web/live/home_live.ex index 3bd671bf..fb45bcd6 100644 --- a/lib/lokal_web/live/home_live.ex +++ b/lib/lokal_web/live/home_live.ex @@ -1,43 +1,18 @@ defmodule LokalWeb.HomeLive do @moduledoc """ - Liveview for the main home page + Liveview for the home page """ use LokalWeb, :live_view + alias Lokal.Accounts + alias LokalWeb.Endpoint + + @version Mix.Project.config()[:version] @impl true def mount(_params, _session, socket) do - {:ok, socket |> assign(page_title: gettext("Home"), query: "", results: %{})} - end - - @impl true - def handle_event("suggest", %{"q" => query}, socket) do - {:noreply, socket |> assign(results: search(query), query: query)} - end - - @impl true - def handle_event("search", %{"q" => query}, socket) do - case search(query) do - %{^query => vsn} -> - {:noreply, socket |> redirect(external: "https://hexdocs.pm/#{query}/#{vsn}")} - - _ -> - {:noreply, - socket - |> put_flash(:error, "No dependencies found matching \"#{query}\"") - |> assign(results: %{}, query: query)} - end - end - - defp search(query) do - if not LokalWeb.Endpoint.config(:code_reloader) do - raise "action disabled when not in development" - end - - for {app, desc, vsn} <- Application.started_applications(), - app = to_string(app), - String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"), - into: %{}, - do: {app, vsn} + admins = Accounts.list_users_by_role(:admin) + socket = socket |> assign(page_title: gettext("Home"), admins: admins, version: @version) + {:ok, socket} end end diff --git a/lib/lokal_web/live/home_live.html.heex b/lib/lokal_web/live/home_live.html.heex index ae6e698f..f156a70f 100644 --- a/lib/lokal_web/live/home_live.html.heex +++ b/lib/lokal_web/live/home_live.html.heex @@ -1,9 +1,135 @@ -
    -

    +
    +

    <%= gettext("Welcome to Lokal") %>

    -

    - <%= gettext("Shop from your community") %> -

    +

    + <%= gettext("Shop from your local community") %> +

    + +
    + +
      +
    • + + <%= gettext("Easy to Use:") %> + +

      + <%= gettext("Lokal lets you easily shop from your local community") %> +

      +
    • +
    • + + <%= gettext("Secure:") %> + +

      + <%= gettext("Self-host your own instance, or use an instance from someone you trust.") %> + <%= gettext("Your data stays with you, period") %> +

      +
    • +
    • + + <%= gettext("Simple:") %> + +

      + <%= gettext("Access from any internet-capable device") %> +

      +
    • +
    + +
    + +
      +

      + <%= gettext("Instance Information") %> +

      + +
    • + + <%= gettext("Admins:") %> + +

      + <%= if @admins |> Enum.empty?() do %> + <.link href={Routes.user_registration_path(Endpoint, :new)} class="hover:underline"> + <%= dgettext("prompts", "Register to setup Lokal") %> + + <% else %> +

      + <% end %> +

      +
    • + +
    • + <%= gettext("Registration:") %> +

      + <%= case Application.get_env(:lokal, Lokal.Accounts)[:registration] do + "public" -> gettext("Public Signups") + _ -> gettext("Invite Only") + end %> +

      +
    • + +
    • + <%= gettext("Version:") %> + <.link + href="https://gitea.bubbletea.dev/shibao/lokal/src/branch/stable/CHANGELOG.md" + class="flex flex-row justify-center items-center space-x-2 hover:underline" + target="_blank" + rel="noopener noreferrer" + > +

      + <%= @version %> +

      + + +
    • +
    + +
    + +
      +

      + <%= gettext("Get involved!") %> +

      + +
    • + <.link + class="flex flex-row justify-center items-center space-x-2 hover:underline" + href="https://gitea.bubbletea.dev/shibao/lokal" + target="_blank" + rel="noopener noreferrer" + > +

      <%= gettext("View the source code") %>

      + + +
    • +
    • + <.link + class="flex flex-row justify-center items-center space-x-2 hover:underline" + href="https://weblate.bubbletea.dev/engage/lokal" + target="_blank" + rel="noopener noreferrer" + > +

      <%= gettext("Help translate") %>

      + + +
    • +
    • + <.link + class="flex flex-row justify-center items-center space-x-2 hover:underline" + href="https://gitea.bubbletea.dev/shibao/lokal/issues/new" + target="_blank" + rel="noopener noreferrer" + > +

      <%= gettext("Report bugs or request features") %>

      + + +
    • +
    diff --git a/lib/lokal_web/live/invite_live/form_component.html.heex b/lib/lokal_web/live/invite_live/form_component.html.heex index c56a37c3..42d24158 100644 --- a/lib/lokal_web/live/invite_live/form_component.html.heex +++ b/lib/lokal_web/live/invite_live/form_component.html.heex @@ -11,11 +11,12 @@ phx-change="validate" phx-submit="save" > - <%= if @changeset.action && not @changeset.valid? do %> -
    - <%= changeset_errors(@changeset) %> -
    - <% end %> +
    + <%= changeset_errors(@changeset) %> +
    <%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-600") %> <%= text_input(f, :name, class: "input input-primary col-span-2") %> diff --git a/lib/lokal_web/live/invite_live/index.ex b/lib/lokal_web/live/invite_live/index.ex index 72cfb553..0e14e317 100644 --- a/lib/lokal_web/live/invite_live/index.ex +++ b/lib/lokal_web/live/invite_live/index.ex @@ -61,7 +61,7 @@ defmodule LokalWeb.InviteLive.Index do ) do socket = Invites.get_invite!(id, current_user) - |> Invites.update_invite(%{"uses_left" => nil}, current_user) + |> Invites.update_invite(%{uses_left: nil}, current_user) |> case do {:ok, %{name: invite_name}} -> prompt = @@ -83,7 +83,7 @@ defmodule LokalWeb.InviteLive.Index do ) do socket = Invites.get_invite!(id, current_user) - |> Invites.update_invite(%{"uses_left" => nil, "disabled_at" => nil}, current_user) + |> Invites.update_invite(%{uses_left: nil, disabled_at: nil}, current_user) |> case do {:ok, %{name: invite_name}} -> prompt = @@ -107,7 +107,7 @@ defmodule LokalWeb.InviteLive.Index do socket = Invites.get_invite!(id, current_user) - |> Invites.update_invite(%{"uses_left" => 0, "disabled_at" => now}, current_user) + |> Invites.update_invite(%{uses_left: 0, disabled_at: now}, current_user) |> case do {:ok, %{name: invite_name}} -> prompt = diff --git a/lib/lokal_web/live/invite_live/index.html.heex b/lib/lokal_web/live/invite_live/index.html.heex index 4ebbd0ec..7dfbf77a 100644 --- a/lib/lokal_web/live/invite_live/index.html.heex +++ b/lib/lokal_web/live/invite_live/index.html.heex @@ -18,69 +18,65 @@ <% end %>
    - <%= for invite <- @invites do %> - <.invite_card invite={invite}> - <:code_actions> -
    - -
    - - <.link - patch={Routes.invite_index_path(Endpoint, :edit, invite)} - class="text-primary-600 link" - data-qa={"edit-#{invite.id}"} - > - - - - <.link - href="#" - class="text-primary-600 link" - phx-click="delete_invite" - phx-value-id={invite.id} - data-confirm={ - dgettext("prompts", "Are you sure you want to delete the invite for %{invite_name}?", - invite_name: invite.name - ) - } - data-qa={"delete-#{invite.id}"} - > - - - - <%= if invite.disabled_at |> is_nil() do %> - - <%= gettext("Disable") %> - - <% else %> - - <%= gettext("Enable") %> - - <% end %> - - <%= if invite.disabled_at |> is_nil() and not (invite.uses_left |> is_nil()) do %> - + <:code_actions> +
    + +
    + + <.link + patch={Routes.invite_index_path(Endpoint, :edit, invite)} + class="text-primary-600 link" + data-qa={"edit-#{invite.id}"} + > + + + + <.link + href="#" + class="text-primary-600 link" + phx-click="delete_invite" + phx-value-id={invite.id} + data-confirm={ + dgettext("prompts", "Are you sure you want to delete the invite for %{invite_name}?", + invite_name: invite.name + ) + } + data-qa={"delete-#{invite.id}"} + > + + + + + <%= if invite.disabled_at, do: gettext("Enable"), else: gettext("Disable") %> + + + is_nil() and not (invite.uses_left |> is_nil())} + href="#" + class="btn btn-primary" + phx-click="set_unlimited" + phx-value-id={invite.id} + data-confirm={ + dgettext("prompts", "Are you sure you want to make %{invite_name} unlimited?", + invite_name: invite.name + ) + } + > + <%= gettext("Set Unlimited") %> + +
    <%= unless @admins |> Enum.empty?() do %> @@ -91,25 +87,23 @@

    - <%= for admin <- @admins do %> - <.user_card user={admin}> - <.link - href="#" - class="text-primary-600 link" - phx-click="delete_user" - phx-value-id={admin.id} - data-confirm={ - dgettext( - "prompts", - "Are you sure you want to delete %{email}? This action is permanent!", - email: admin.email - ) - } - > - - - - <% end %> + <.user_card :for={admin <- @admins} user={admin}> + <.link + href="#" + class="text-primary-600 link" + phx-click="delete_user" + phx-value-id={admin.id} + data-confirm={ + dgettext( + "prompts", + "Are you sure you want to delete %{email}? This action is permanent!", + email: admin.email + ) + } + > + + +
    <% end %> @@ -121,39 +115,35 @@
    - <%= for user <- @users do %> - <.user_card user={user}> - <.link - href="#" - class="text-primary-600 link" - phx-click="delete_user" - phx-value-id={user.id} - data-confirm={ - dgettext( - "prompts", - "Are you sure you want to delete %{email}? This action is permanent!", - email: user.email - ) - } - > - - - - <% end %> + <.user_card :for={user <- @users} user={user}> + <.link + href="#" + class="text-primary-600 link" + phx-click="delete_user" + phx-value-id={user.id} + data-confirm={ + dgettext( + "prompts", + "Are you sure you want to delete %{email}? This action is permanent!", + email: user.email + ) + } + > + + +
    <% end %>
    -<%= if @live_action in [:new, :edit] do %> - <.modal return_to={Routes.invite_index_path(Endpoint, :index)}> - <.live_component - module={LokalWeb.InviteLive.FormComponent} - id={@invite.id || :new} - title={@page_title} - action={@live_action} - invite={@invite} - return_to={Routes.invite_index_path(Endpoint, :index)} - current_user={@current_user} - /> - -<% end %> +<.modal :if={@live_action in [:new, :edit]} return_to={Routes.invite_index_path(Endpoint, :index)}> + <.live_component + module={LokalWeb.InviteLive.FormComponent} + id={@invite.id || :new} + title={@page_title} + action={@live_action} + invite={@invite} + return_to={Routes.invite_index_path(Endpoint, :index)} + current_user={@current_user} + /> + diff --git a/lib/lokal_web/live/live_helpers.ex b/lib/lokal_web/live/live_helpers.ex index d3c1371e..0c1e8821 100644 --- a/lib/lokal_web/live/live_helpers.ex +++ b/lib/lokal_web/live/live_helpers.ex @@ -31,10 +31,10 @@ defmodule LokalWeb.LiveHelpers do id="modal-bg" patch={@return_to} class="fade-in fixed z-10 left-0 top-0 - w-full h-full overflow-hidden - p-8 flex flex-col justify-center items-center cursor-auto" + w-full h-full overflow-hidden + p-8 flex flex-col justify-center items-center cursor-auto" style="background-color: rgba(0,0,0,0.4);" - phx_remove={hide_modal()} + phx-remove={hide_modal()} > @@ -48,18 +48,18 @@ defmodule LokalWeb.LiveHelpers do