more changes to notes
This commit is contained in:
@ -26,13 +26,13 @@ defmodule MemexWeb.NoteLive.Index do
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: %{id: current_user_id}}} = socket, :new, _params) do
|
||||
socket
|
||||
|> assign(page_title: "new note")
|
||||
|> assign(page_title: gettext("new note"))
|
||||
|> assign(note: %Note{user_id: current_user_id})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(page_title: "notes")
|
||||
|> assign(page_title: gettext("notes"))
|
||||
|> assign(search: nil)
|
||||
|> assign(note: nil)
|
||||
|> display_notes()
|
||||
@ -40,7 +40,7 @@ defmodule MemexWeb.NoteLive.Index do
|
||||
|
||||
defp apply_action(socket, :search, %{"search" => search}) do
|
||||
socket
|
||||
|> assign(page_title: "notes")
|
||||
|> assign(page_title: gettext("notes"))
|
||||
|> assign(search: search)
|
||||
|> assign(note: nil)
|
||||
|> display_notes()
|
||||
@ -48,8 +48,8 @@ defmodule MemexWeb.NoteLive.Index do
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do
|
||||
%{title: title} = note = Notes.get_note!(id, current_user)
|
||||
{:ok, _} = Notes.delete_note(note, current_user)
|
||||
note = Notes.get_note!(id, current_user)
|
||||
{:ok, %{title: title}} = Notes.delete_note(note, current_user)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|
@ -8,10 +8,14 @@
|
||||
for={:search}
|
||||
phx-change="search"
|
||||
phx-submit="search"
|
||||
phx-debounce="500"
|
||||
class="self-stretch flex flex-col items-stretch"
|
||||
>
|
||||
<%= text_input(f, :search_term, class: "input input-primary", value: @search) %>
|
||||
<%= text_input(f, :search_term,
|
||||
class: "input input-primary",
|
||||
value: @search,
|
||||
phx_debounce: 300,
|
||||
placeholder: gettext("search")
|
||||
) %>
|
||||
</.form>
|
||||
|
||||
<%= if @notes |> Enum.empty?() do %>
|
||||
|
@ -20,6 +20,22 @@ defmodule MemexWeb.NoteLive.Show do
|
||||
|> assign(:note, Notes.get_note!(id, current_user))}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "show note"
|
||||
defp page_title(:edit), do: "edit note"
|
||||
@impl true
|
||||
def handle_event(
|
||||
"delete",
|
||||
_params,
|
||||
%{assigns: %{note: note, current_user: current_user}} = socket
|
||||
) do
|
||||
{:ok, %{title: title}} = Notes.delete_note(note, current_user)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> put_flash(:info, gettext("%{title} deleted", title: title))
|
||||
|> push_navigate(to: Routes.note_index_path(Endpoint, :index))
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: gettext("show note")
|
||||
defp page_title(:edit), do: gettext("edit note")
|
||||
end
|
||||
|
@ -20,12 +20,22 @@
|
||||
|
||||
<div class="self-end flex space-x-4">
|
||||
<.link class="btn btn-primary" patch={Routes.note_index_path(@socket, :index)}>
|
||||
<%= dgettext("actions", "Back") %>
|
||||
<%= dgettext("actions", "back") %>
|
||||
</.link>
|
||||
<%= if @current_user do %>
|
||||
<.link class="btn btn-primary" patch={Routes.note_show_path(@socket, :edit, @note)}>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="delete"
|
||||
data-confirm={dgettext("prompts", "are you sure?")}
|
||||
data-qa={"delete-note-#{@note.id}"}
|
||||
>
|
||||
<%= dgettext("actions", "delete") %>
|
||||
</button>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user