From 5c0ea0f88f25eb23a90e5e0204956952ad78b37f Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 12 Apr 2025 21:51:34 +0300 Subject: [PATCH] Update LiveViews and component to check if user can moderate. --- .../components/my_components/author_card.ex | 51 ++++++++++--------- .../components/my_components/author_search.ex | 21 +++++--- .../components/my_components/book_card.ex | 51 ++++++++++--------- .../components/my_components/book_search.ex | 22 +++++--- .../live/author_live/index.ex | 6 ++- .../live/author_live/show.ex | 14 +++-- .../live/book_live/index.ex | 6 ++- .../live/book_live/show.ex | 13 +++-- 8 files changed, 110 insertions(+), 74 deletions(-) diff --git a/lib/decentralised_book_index_web/components/my_components/author_card.ex b/lib/decentralised_book_index_web/components/my_components/author_card.ex index 0142273..dbc3b50 100644 --- a/lib/decentralised_book_index_web/components/my_components/author_card.ex +++ b/lib/decentralised_book_index_web/components/my_components/author_card.ex @@ -2,35 +2,40 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorCard do use Phoenix.Component use DecentralisedBookIndexWeb, :verified_routes + alias DecentralisedBookIndex.Accounts.Role + attr(:author, :map, required: true) + attr :current_user, :map, default: nil def author_card(assigns) do ~H"""
-
- - - + <% end %>
<.link navigate={~p"/authors/#{@author.id}"}> <%= if @author.avatar_url != nil do %> diff --git a/lib/decentralised_book_index_web/components/my_components/author_search.ex b/lib/decentralised_book_index_web/components/my_components/author_search.ex index 40b6ebc..02a0af8 100644 --- a/lib/decentralised_book_index_web/components/my_components/author_search.ex +++ b/lib/decentralised_book_index_web/components/my_components/author_search.ex @@ -2,9 +2,12 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do use Phoenix.Component use DecentralisedBookIndexWeb, :verified_routes + alias DecentralisedBookIndex.Accounts.Role + attr :search_query, :string, default: "" attr :select_options, :list, required: true attr :selected_option, :string, required: true + attr :current_user, :map, default: nil def author_search(assigns) do ~H""" @@ -24,14 +27,16 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
- <.link patch={~p"/authors/new"}> - - + <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %> + <.link patch={~p"/authors/new"}> + + + <% end %>