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

dev
KKlochko 3 months ago
parent 92a090575c
commit 5c0ea0f88f

@ -2,11 +2,15 @@ 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"""
<div class="w-full max-w-sm bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700 mx-auto my-3">
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<div class="flex justify-end px-4 pt-4">
<button id={"dropdownButton#{@author.id}"} data-dropdown-toggle={"dropdown#{@author.id}"} class="inline-block text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:ring-4 focus:outline-none focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-1.5" type="button">
<span class="sr-only">Open dropdown</span>
@ -31,6 +35,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorCard do
</ul>
</div>
</div>
<% end %>
<div class="flex flex-col items-center py-5 text-center">
<.link navigate={~p"/authors/#{@author.id}"}>
<%= if @author.avatar_url != nil do %>

@ -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,6 +27,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
</form>
</div>
<div class="flex flex-col items-stretch justify-end flex-shrink-0 w-full space-y-2 md:w-auto md:flex-row md:space-y-0 md:items-center md:space-x-3">
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<.link patch={~p"/authors/new"}>
<button type="button" class="flex items-center justify-center px-4 py-2 text-sm font-medium text-black dark:text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 focus:outline-none dark:focus:ring-primary-800">
<svg class="h-3.5 w-3.5 mr-2" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
@ -32,6 +36,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
Add author
</button>
</.link>
<% end %>
<div class="flex items-center w-full space-x-3 md:w-auto">
<form phx-change="change-sort">
<select name="sort_by" id="countries" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">

@ -2,11 +2,15 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookCard do
use Phoenix.Component
use DecentralisedBookIndexWeb, :verified_routes
alias DecentralisedBookIndex.Accounts.Role
attr(:book, :map, required: true)
attr :current_user, :map, default: nil
def book_card(assigns) do
~H"""
<div class="w-full max-w-sm bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700 mx-auto my-3">
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<div class="flex justify-end px-4 pt-4">
<button id={"dropdownButton#{@book.id}"} data-dropdown-toggle={"dropdown#{@book.id}"} class="inline-block text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:ring-4 focus:outline-none focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-1.5" type="button">
<span class="sr-only">Open dropdown</span>
@ -31,6 +35,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookCard do
</ul>
</div>
</div>
<% end %>
<div class="flex flex-col items-center py-5 text-center">
<.link navigate={~p"/books/#{@book.id}"}>
<%= if @book.cover_image_url != nil do %>

@ -2,12 +2,16 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
use Phoenix.Component
use DecentralisedBookIndexWeb, :verified_routes
alias DecentralisedBookIndex.Accounts.Role
attr :search_query, :string, default: ""
attr :search_mode, :string, default: "title"
attr :search_mode_options, :list, required: true
attr :select_options, :list, required: true
attr :selected_option, :string, required: true
attr :current_user, :map, default: nil
def book_search(assigns) do
~H"""
<div class="relative bg-white shadow-md dark:bg-gray-800 sm:rounded-lg">
@ -26,6 +30,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
</form>
</div>
<div class="flex flex-col items-stretch justify-end flex-shrink-0 w-full space-y-2 md:w-auto md:flex-row md:space-y-0 md:items-center md:space-x-3">
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<.link patch={~p"/books/new"}>
<button type="button" class="flex items-center justify-center px-4 py-2 text-sm font-medium text-black dark:text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 focus:outline-none dark:focus:ring-primary-800">
<svg class="h-3.5 w-3.5 mr-2" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
@ -34,6 +39,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
Add book
</button>
</.link>
<% end %>
<.dropdown_settings
search_mode={@search_mode}
search_mode_options={@search_mode_options}

@ -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>
<%= 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>
<%= 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>

Loading…
Cancel
Save