update liveview

This commit is contained in:
2022-11-16 21:11:02 -05:00
parent 2ce94fd6d1
commit 1f438d0fe5
32 changed files with 362 additions and 273 deletions

View File

@ -33,7 +33,7 @@ defmodule MemexWeb.ContextLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Context updated successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
@ -46,7 +46,7 @@ defmodule MemexWeb.ContextLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Context created successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}

View File

@ -2,7 +2,7 @@
<h2><%= @title %></h2>
<.form
let={f}
:let={f}
for={@changeset}
id="context-form"
phx-target={@myself}

View File

@ -34,18 +34,24 @@
<td>
<span>
<%= live_redirect("Show", to: Routes.context_show_path(@socket, :show, context)) %>
<.link navigate={Routes.context_show_path(@socket, :show, context)}>
<%= dgettext("actions", "Show") %>
</.link>
</span>
<span>
<%= live_patch("Edit", to: Routes.context_index_path(@socket, :edit, context)) %>
<.link patch={Routes.context_index_path(@socket, :edit, context)}>
<%= dgettext("actions", "Edit") %>
</.link>
</span>
<span>
<%= link("Delete",
to: "#",
phx_click: "delete",
phx_value_id: context.id,
data: [confirm: "Are you sure?"]
) %>
<.link
href="#"
phx-click="delete"
phx-value-id={context.id}
data-confirm={dgettext("prompts", "Are you sure?")}
>
<%= dgettext("actions", "Delete") %>
</.link>
</span>
</td>
</tr>
@ -53,4 +59,8 @@
</tbody>
</table>
<span><%= live_patch("New Context", to: Routes.context_index_path(@socket, :new)) %></span>
<span>
<.link patch={Routes.context_index_path(@socket, :new)}>
<%= dgettext("actions", "New Context") %>
</.link>
</span>

View File

@ -36,6 +36,13 @@
</ul>
<span>
<%= live_patch("Edit", to: Routes.context_show_path(@socket, :edit, @context), class: "button") %>
<.link patch={Routes.context_show_path(@socket, :edit, @context)} class="button">
<%= dgettext("actions", "Edit") %>
</.link>
</span>
|
<span>
<.link navigate={Routes.context_index_path(@socket, :index)}>
<%= dgettext("actions", "Back") %>
</.link>
</span>
| <span><%= live_redirect("Back", to: Routes.context_index_path(@socket, :index)) %></span>

View File

@ -88,10 +88,12 @@
</b>
<p>
<%= if @admins |> Enum.empty?() do %>
<%= link(dgettext("prompts", "Register to setup %{name}", name: "Cannery"),
class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
<.link
href={Routes.user_registration_path(MemexWeb.Endpoint, :new)}
class="hover:underline"
>
<%= dgettext("prompts", "Register to setup %{name}", name: "memex") %>
</.link>
<% else %>
<div class="flex flex-wrap justify-center space-x-2">
<%= for admin <- @admins do %>
@ -107,7 +109,7 @@
<li class="flex flex-row justify-center space-x-2">
<b>Registration:</b>
<p>
<%= Application.get_env(:cannery, CanneryWeb.Endpoint)[:registration]
<%= Application.get_env(:memex, MemexWeb.Endpoint)[:registration]
|> case do
"public" -> gettext("Public Signups")
_ -> gettext("Invite Only")
@ -117,13 +119,15 @@
<li class="flex flex-row justify-center items-center space-x-2">
<b>Version:</b>
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/memex/src/branch/stable/CHANGELOG.md",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
href="https://gitea.bubbletea.dev/shibao/memex/src/branch/stable/CHANGELOG.md"
class="flex flex-row justify-center items-center space-x-2 hover:underline"
target="_blank"
rel="noopener noreferrer"
>
<p>0.1.0</p>
<i class="fas fa-md fa-info-circle"></i>
<% end %>
</.link>
</li>
</ul>
@ -135,31 +139,37 @@
</h2>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/memex",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
href="https://gitea.bubbletea.dev/shibao/memex"
class="flex flex-row justify-center items-center space-x-2 hover:underline"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("View the source code") %></p>
<i class="fas fa-md fa-code"></i>
<% end %>
</.link>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://weblate.bubbletea.dev/engage/memex",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
href="https://weblate.bubbletea.dev/engage/memex"
class="flex flex-row justify-center items-center space-x-2 hover:underline"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("Help translate") %></p>
<i class="fas fa-md fa-language"></i>
<% end %>
</.link>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/memex/issues/new",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
href="https://gitea.bubbletea.dev/shibao/memex/issues/new"
class="flex flex-row justify-center items-center space-x-2 hover:underline"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("Report bugs or request features") %></p>
<i class="fas fa-md fa-spider"></i>
<% end %>
</.link>
</li>
</ul>
</div>

View File

@ -2,7 +2,7 @@ defmodule MemexWeb.InitAssigns do
@moduledoc """
Ensures common `assigns` are applied to all LiveViews attaching this hook.
"""
import Phoenix.LiveView
import Phoenix.Component
alias Memex.Accounts
def on_mount(:default, _params, %{"locale" => locale, "user_token" => user_token}, socket) do

View File

@ -41,7 +41,7 @@ defmodule MemexWeb.InviteLive.FormComponent do
prompt =
dgettext("prompts", "%{invite_name} updated successfully", invite_name: invite_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -61,7 +61,7 @@ defmodule MemexWeb.InviteLive.FormComponent do
prompt =
dgettext("prompts", "%{invite_name} created successfully", invite_name: invite_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -3,7 +3,7 @@
<%= @title %>
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="invite-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.InviteLive.Index do
else
prompt = dgettext("errors", "You are not authorized to view this page")
return_to = Routes.live_path(Endpoint, HomeLive)
socket |> put_flash(:error, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:error, prompt) |> push_navigate(to: return_to)
end
{:ok, socket}

View File

@ -8,15 +8,13 @@
<%= gettext("No invites 😔") %>
</h1>
<%= live_patch(dgettext("actions", "Invite someone new!"),
to: Routes.invite_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.invite_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Invite someone new!") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "Create Invite"),
to: Routes.invite_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.invite_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Create Invite") %>
</.link>
<% end %>
<div class="w-full flex flex-row flex-wrap justify-center items-center">
@ -33,25 +31,28 @@
</button>
</form>
</:code_actions>
<%= live_patch to: Routes.invite_index_path(Endpoint, :edit, invite),
class: "text-primary-400 link",
data: [qa: "edit-#{invite.id}"] do %>
<.link
patch={Routes.invite_index_path(Endpoint, :edit, invite)}
class="text-primary-400 link"
data-qa={"edit-#{invite.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-400 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
),
qa: "delete-#{invite.id}"
] do %>
<.link
href="#"
class="text-primary-400 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}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
<%= if invite.disabled_at |> is_nil() do %>
<a href="#" class="btn btn-primary" phx-click="disable_invite" phx-value-id={invite.id}>
@ -92,20 +93,21 @@
<div class="w-full flex flex-row flex-wrap justify-center items-center">
<%= for admin <- @admins do %>
<.user_card user={admin}>
<%= link to: "#",
class: "text-primary-400 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
)
] do %>
<.link
href="#"
class="text-primary-400 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
)
}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.user_card>
<% end %>
</div>
@ -121,20 +123,21 @@
<div class="w-full flex flex-row flex-wrap justify-center items-center">
<%= for user <- @users do %>
<.user_card user={user}>
<%= link to: "#",
class: "text-primary-400 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
)
] do %>
<.link
href="#"
class="text-primary-400 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
)
}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.user_card>
<% end %>
</div>

View File

@ -3,7 +3,7 @@ defmodule MemexWeb.LiveHelpers do
Contains resuable methods for all liveviews
"""
import Phoenix.LiveView.Helpers
import Phoenix.Component
alias Phoenix.LiveView.JS
@doc """
@ -27,17 +27,17 @@ defmodule MemexWeb.LiveHelpers do
"""
def modal(assigns) do
~H"""
<%= live_patch to: @return_to,
id: "modal-bg",
class:
"fade-in fixed z-10 left-0 top-0
<.link
patch={@return_to}
id="modal-bg"
class="fade-in fixed z-10 left-0 top-0
w-screen h-screen 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()
do %>
p-8 flex flex-col justify-center items-center cursor-auto"
style="background-color: rgba(0,0,0,0.4);"
phx-remove={hide_modal()}
>
<span class="hidden"></span>
<% end %>
</.link>
<div
id="modal"
@ -52,15 +52,16 @@ defmodule MemexWeb.LiveHelpers do
px-8 py-4 sm:py-8 flex flex-col justify-start items-stretch
bg-primary-800 text-primary-400 border-primary-900 border-2 rounded-lg"
>
<%= live_patch to: @return_to,
id: "close",
class:
"absolute top-8 right-10
<.link
patch={@return_to}
id="close"
class="absolute top-8 right-10
text-gray-500 hover:text-gray-800
transition-all duration-500 ease-in-out",
phx_remove: hide_modal() do %>
transition-all duration-500 ease-in-out"
phx-remove={hide_modal()}
>
<i class="fa-fw fa-lg fas fa-times"></i>
<% end %>
</.link>
<div class="overflow-x-hidden overflow-y-visible p-8 flex flex-col space-y-4 justify-start items-stretch">
<%= render_slot(@inner_block) %>

View File

@ -33,7 +33,7 @@ defmodule MemexWeb.NoteLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Note updated successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
@ -46,7 +46,7 @@ defmodule MemexWeb.NoteLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Note created successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}

View File

@ -2,7 +2,7 @@
<h2><%= @title %></h2>
<.form
let={f}
:let={f}
for={@changeset}
id="note-form"
phx-target={@myself}

View File

@ -34,16 +34,24 @@
<td>
<span>
<%= live_redirect("Show", to: Routes.note_show_path(@socket, :show, note)) %>
<.link navigate={Routes.note_show_path(@socket, :show, note)}>
<%= dgettext("actions", "Show") %>
</.link>
</span>
<span><%= live_patch("Edit", to: Routes.note_index_path(@socket, :edit, note)) %></span>
<span>
<%= link("Delete",
to: "#",
phx_click: "delete",
phx_value_id: note.id,
data: [confirm: "Are you sure?"]
) %>
<.link patch={Routes.note_index_path(@socket, :edit, note)}>
<%= dgettext("actions", "Edit") %>
</.link>
</span>
<span>
<.link
href="#"
phx-click="delete"
phx-value-id={note.id}
data-confirm={dgettext("prompts", "Are you sure?")}
>
<%= dgettext("actions", "Delete") %>
</.link>
</span>
</td>
</tr>
@ -51,4 +59,8 @@
</tbody>
</table>
<span><%= live_patch("New Note", to: Routes.note_index_path(@socket, :new)) %></span>
<span>
<.link patch={Routes.note_index_path(@socket, :new)}>
<%= dgettext("actions", "New Note") %>
</.link>
</span>

View File

@ -36,6 +36,13 @@
</ul>
<span>
<%= live_patch("Edit", to: Routes.note_show_path(@socket, :edit, @note), class: "button") %>
<.link patch={Routes.note_show_path(@socket, :edit, @note)} class="button">
<%= dgettext("actions", "Edit") %>
</.link>
</span>
|
<span>
<.link patch={Routes.note_index_path(@socket, :index)}>
<%= dgettext("actions", "Back") %>
</.link>
</span>
| <span><%= live_redirect("Back", to: Routes.note_index_path(@socket, :index)) %></span>

View File

@ -33,7 +33,7 @@ defmodule MemexWeb.PipelineLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Pipeline updated successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
@ -46,7 +46,7 @@ defmodule MemexWeb.PipelineLive.FormComponent do
{:noreply,
socket
|> put_flash(:info, "Pipeline created successfully")
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}

View File

@ -2,7 +2,7 @@
<h2><%= @title %></h2>
<.form
let={f}
:let={f}
for={@changeset}
id="pipeline-form"
phx-target={@myself}

View File

@ -32,18 +32,24 @@
<td>
<span>
<%= live_redirect("Show", to: Routes.pipeline_show_path(@socket, :show, pipeline)) %>
<.link navigate={Routes.pipeline_show_path(@socket, :show, pipeline)}>
<%= dgettext("actions", "Show") %>
</.link>
</span>
<span>
<%= live_patch("Edit", to: Routes.pipeline_index_path(@socket, :edit, pipeline)) %>
<.link patch={Routes.pipeline_index_path(@socket, :edit, pipeline)}>
<%= dgettext("actions", "Edit") %>
</.link>
</span>
<span>
<%= link("Delete",
to: "#",
phx_click: "delete",
phx_value_id: pipeline.id,
data: [confirm: "Are you sure?"]
) %>
<.link
href="#"
phx-click="delete"
phx-value-id={pipeline.id}
data-confirm={dgettext("prompts", "Are you sure?")}
>
<%= dgettext("actions", "Delete") %>
</.link>
</span>
</td>
</tr>
@ -51,4 +57,8 @@
</tbody>
</table>
<span><%= live_patch("New Pipeline", to: Routes.pipeline_index_path(@socket, :new)) %></span>
<span>
<.link patch={Routes.pipeline_index_path(@socket, :new)}>
<%= dgettext("actions", "New Pipeline") %>
</.link>
</span>

View File

@ -31,6 +31,13 @@
</ul>
<span>
<%= live_patch("Edit", to: Routes.pipeline_show_path(@socket, :edit, @pipeline), class: "button") %>
<.link patch={Routes.pipeline_show_path(@socket, :edit, @pipeline)} class="button">
<%= dgettext("actions", "Edit") %>
</.link>
</span>
|
<span>
<.link patch={Routes.pipeline_index_path(@socket, :index)}>
<%= dgettext("actions", "Back") %>
</.link>
</span>
| <span><%= live_redirect("Back", to: Routes.pipeline_index_path(@socket, :index)) %></span>