Update LiveViews and component to check if user can moderate.
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-04-12 21:51:34 +03:00
parent 92a090575c
commit 5c0ea0f88f
8 changed files with 110 additions and 74 deletions
@@ -14,6 +14,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
search_query={@search_query}
select_options={@select_options}
selected_option={@sort_by}
current_user={@current_user}
/>
<.table
@@ -58,7 +59,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
<% else %>
<div class="flex flex-wrap flex-[3_1_auto]">
<%= for author <- @page.results do %>
<.author_card author={author} />
<.author_card
author={author}
current_user={@current_user}
/>
<% end %>
</div>
@@ -1,6 +1,8 @@
defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
use DecentralisedBookIndexWeb, :live_view
alias DecentralisedBookIndex.Accounts.Role
@impl true
def render(assigns) do
~H"""
@@ -8,11 +10,13 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
{@author.name}
<:actions>
<.link navigate={~p"/authors/#{@author}/edit"}>
<.edit_button>
Edit
</.edit_button>
</.link>
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<.link navigate={~p"/authors/#{@author}/edit"}>
<.edit_button>
Edit
</.edit_button>
</.link>
<% end %>
</:actions>
</.header>
@@ -16,6 +16,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
search_mode_options={@search_mode_options}
select_options={@select_options}
selected_option={@sort_by}
current_user={@current_user}
/>
<.table
@@ -68,7 +69,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
<% else %>
<div class="flex flex-wrap flex-[3_1_auto]">
<%= for book <- @page.results do %>
<.book_card book={book} />
<.book_card
book={book}
current_user={@current_user}
/>
<% end %>
</div>
@@ -2,6 +2,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
use DecentralisedBookIndexWeb, :live_view
alias DecentralisedBookIndex.Metadata
alias DecentralisedBookIndex.Accounts.Role
@impl true
def render(assigns) do
@@ -11,11 +12,13 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
<:subtitle>{@authors_string}</:subtitle>
<:actions>
<.link patch={~p"/books/#{@book}/edit"}>
<.edit_button>
Edit
</.edit_button>
</.link>
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<.link patch={~p"/books/#{@book}/edit"}>
<.edit_button>
Edit
</.edit_button>
</.link>
<% end %>
</:actions>
</.header>