Update LiveViews and component to check if user can moderate.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,11 +2,15 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorCard do
|
|||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
use DecentralisedBookIndexWeb, :verified_routes
|
use DecentralisedBookIndexWeb, :verified_routes
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
attr(:author, :map, required: true)
|
attr(:author, :map, required: true)
|
||||||
|
attr :current_user, :map, default: nil
|
||||||
|
|
||||||
def author_card(assigns) do
|
def author_card(assigns) do
|
||||||
~H"""
|
~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">
|
<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">
|
<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">
|
<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>
|
<span class="sr-only">Open dropdown</span>
|
||||||
@@ -31,6 +35,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorCard do
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
<div class="flex flex-col items-center py-5 text-center">
|
<div class="flex flex-col items-center py-5 text-center">
|
||||||
<.link navigate={~p"/authors/#{@author.id}"}>
|
<.link navigate={~p"/authors/#{@author.id}"}>
|
||||||
<%= if @author.avatar_url != nil do %>
|
<%= if @author.avatar_url != nil do %>
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
|
|||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
use DecentralisedBookIndexWeb, :verified_routes
|
use DecentralisedBookIndexWeb, :verified_routes
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
attr :search_query, :string, default: ""
|
attr :search_query, :string, default: ""
|
||||||
attr :select_options, :list, required: true
|
attr :select_options, :list, required: true
|
||||||
attr :selected_option, :string, required: true
|
attr :selected_option, :string, required: true
|
||||||
|
attr :current_user, :map, default: nil
|
||||||
|
|
||||||
def author_search(assigns) do
|
def author_search(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -24,6 +27,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</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">
|
<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"}>
|
<.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">
|
<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">
|
<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
|
Add author
|
||||||
</button>
|
</button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<% end %>
|
||||||
<div class="flex items-center w-full space-x-3 md:w-auto">
|
<div class="flex items-center w-full space-x-3 md:w-auto">
|
||||||
<form phx-change="change-sort">
|
<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">
|
<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 Phoenix.Component
|
||||||
use DecentralisedBookIndexWeb, :verified_routes
|
use DecentralisedBookIndexWeb, :verified_routes
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
attr(:book, :map, required: true)
|
attr(:book, :map, required: true)
|
||||||
|
attr :current_user, :map, default: nil
|
||||||
|
|
||||||
def book_card(assigns) do
|
def book_card(assigns) do
|
||||||
~H"""
|
~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">
|
<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">
|
<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">
|
<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>
|
<span class="sr-only">Open dropdown</span>
|
||||||
@@ -31,6 +35,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookCard do
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
<div class="flex flex-col items-center py-5 text-center">
|
<div class="flex flex-col items-center py-5 text-center">
|
||||||
<.link navigate={~p"/books/#{@book.id}"}>
|
<.link navigate={~p"/books/#{@book.id}"}>
|
||||||
<%= if @book.cover_image_url != nil do %>
|
<%= if @book.cover_image_url != nil do %>
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
|
|||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
use DecentralisedBookIndexWeb, :verified_routes
|
use DecentralisedBookIndexWeb, :verified_routes
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
attr :search_query, :string, default: ""
|
attr :search_query, :string, default: ""
|
||||||
attr :search_mode, :string, default: "title"
|
attr :search_mode, :string, default: "title"
|
||||||
attr :search_mode_options, :list, required: true
|
attr :search_mode_options, :list, required: true
|
||||||
attr :select_options, :list, required: true
|
attr :select_options, :list, required: true
|
||||||
attr :selected_option, :string, required: true
|
attr :selected_option, :string, required: true
|
||||||
|
|
||||||
|
attr :current_user, :map, default: nil
|
||||||
|
|
||||||
def book_search(assigns) do
|
def book_search(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="relative bg-white shadow-md dark:bg-gray-800 sm:rounded-lg">
|
<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>
|
</form>
|
||||||
</div>
|
</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">
|
<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"}>
|
<.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">
|
<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">
|
<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
|
Add book
|
||||||
</button>
|
</button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<% end %>
|
||||||
<.dropdown_settings
|
<.dropdown_settings
|
||||||
search_mode={@search_mode}
|
search_mode={@search_mode}
|
||||||
search_mode_options={@search_mode_options}
|
search_mode_options={@search_mode_options}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|||||||
search_query={@search_query}
|
search_query={@search_query}
|
||||||
select_options={@select_options}
|
select_options={@select_options}
|
||||||
selected_option={@sort_by}
|
selected_option={@sort_by}
|
||||||
|
current_user={@current_user}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<.table
|
<.table
|
||||||
@@ -58,7 +59,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|||||||
<% else %>
|
<% else %>
|
||||||
<div class="flex flex-wrap flex-[3_1_auto]">
|
<div class="flex flex-wrap flex-[3_1_auto]">
|
||||||
<%= for author <- @page.results do %>
|
<%= for author <- @page.results do %>
|
||||||
<.author_card author={author} />
|
<.author_card
|
||||||
|
author={author}
|
||||||
|
current_user={@current_user}
|
||||||
|
/>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -8,11 +10,13 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
|||||||
{@author.name}
|
{@author.name}
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
<.link navigate={~p"/authors/#{@author}/edit"}>
|
<.link navigate={~p"/authors/#{@author}/edit"}>
|
||||||
<.edit_button>
|
<.edit_button>
|
||||||
Edit
|
Edit
|
||||||
</.edit_button>
|
</.edit_button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<% end %>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
|||||||
search_mode_options={@search_mode_options}
|
search_mode_options={@search_mode_options}
|
||||||
select_options={@select_options}
|
select_options={@select_options}
|
||||||
selected_option={@sort_by}
|
selected_option={@sort_by}
|
||||||
|
current_user={@current_user}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<.table
|
<.table
|
||||||
@@ -68,7 +69,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
|||||||
<% else %>
|
<% else %>
|
||||||
<div class="flex flex-wrap flex-[3_1_auto]">
|
<div class="flex flex-wrap flex-[3_1_auto]">
|
||||||
<%= for book <- @page.results do %>
|
<%= for book <- @page.results do %>
|
||||||
<.book_card book={book} />
|
<.book_card
|
||||||
|
book={book}
|
||||||
|
current_user={@current_user}
|
||||||
|
/>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
|||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
@@ -11,11 +12,13 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
|||||||
<:subtitle>{@authors_string}</:subtitle>
|
<:subtitle>{@authors_string}</:subtitle>
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
<.link patch={~p"/books/#{@book}/edit"}>
|
<.link patch={~p"/books/#{@book}/edit"}>
|
||||||
<.edit_button>
|
<.edit_button>
|
||||||
Edit
|
Edit
|
||||||
</.edit_button>
|
</.edit_button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<% end %>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user