|
|
|
@ -14,37 +14,69 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
|
|
|
|
|
|
|
|
|
|
def book_search(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<div class="bg-white shadow-md dark:bg-gray-800 sm:rounded-lg">
|
|
|
|
|
<div class="bg-slate-100 shadow-md dark:bg-gray-800 sm:rounded-lg">
|
|
|
|
|
<div class="flex items-center justify-center p-4 flex-row space-y-0 space-x-4">
|
|
|
|
|
<div class="w-full grow">
|
|
|
|
|
<form class="flex items-center" phx-change="search" phx-submit="search">
|
|
|
|
|
<label for="simple-search" class="sr-only">Search</label>
|
|
|
|
|
<div class="relative w-full">
|
|
|
|
|
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
|
|
|
|
|
<svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
|
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
|
|
|
|
|
<svg
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
class="w-5 h-5 text-gray-500 dark:text-gray-400"
|
|
|
|
|
fill="currentColor"
|
|
|
|
|
viewbox="0 0 20 20"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
fill-rule="evenodd"
|
|
|
|
|
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
|
|
|
clip-rule="evenodd"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
<input name="query" type="text" phx-debounce="300" autocomplete="off" id="simple-search" class="block w-full p-2 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" placeholder="Search" value={@search_query}>
|
|
|
|
|
<input
|
|
|
|
|
name="query"
|
|
|
|
|
type="text"
|
|
|
|
|
phx-debounce="300"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
id="simple-search"
|
|
|
|
|
class="block w-full p-2 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
|
|
|
|
|
placeholder="Search"
|
|
|
|
|
value={@search_query}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
|
|
|
|
<.link patch={~p"/books/new"} class="flex-shrink-0 my-auto">
|
|
|
|
|
<button type="button" class="flex items-center justify-between 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">
|
|
|
|
|
<path clip-rule="evenodd" fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" />
|
|
|
|
|
</svg>
|
|
|
|
|
Add book
|
|
|
|
|
</button>
|
|
|
|
|
</.link>
|
|
|
|
|
<% end %>
|
|
|
|
|
<.dropdown_settings
|
|
|
|
|
search_mode={@search_mode}
|
|
|
|
|
search_mode_options={@search_mode_options}
|
|
|
|
|
select_options={@select_options}
|
|
|
|
|
selected_option={@selected_option}
|
|
|
|
|
/>
|
|
|
|
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
|
|
|
|
<.link patch={~p"/books/new"} class="flex-shrink-0 my-auto">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="flex items-center justify-between 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"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
clip-rule="evenodd"
|
|
|
|
|
fill-rule="evenodd"
|
|
|
|
|
d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
Add book
|
|
|
|
|
</button>
|
|
|
|
|
</.link>
|
|
|
|
|
<% end %>
|
|
|
|
|
<.dropdown_settings
|
|
|
|
|
search_mode={@search_mode}
|
|
|
|
|
search_mode_options={@search_mode_options}
|
|
|
|
|
select_options={@select_options}
|
|
|
|
|
selected_option={@selected_option}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
@ -58,17 +90,42 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
|
|
|
|
|
def dropdown_settings(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<div class="flex justify-end px-4">
|
|
|
|
|
<button id="dropdownButtonSearchBook" data-dropdown-toggle="dropdownSearchBook" 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>
|
|
|
|
|
<svg class="w-5 h-5 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
|
|
|
|
<path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M20 6H10m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4m16 6h-2m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4m16 6H10m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4"/>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
<!-- Dropdown menu -->
|
|
|
|
|
<div id="dropdownSearchBook" class="z-10 hidden text-base list-none bg-white rounded-lg shadow-sm w-64 dark:bg-gray-700 p-2 flex flex-col gap-2">
|
|
|
|
|
<div class="flex items-center space-x-3 md:w-auto">
|
|
|
|
|
<form phx-change="change-search-mode" class="w-full">
|
|
|
|
|
<select name="search_mode" id="search_mode" 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">
|
|
|
|
|
<button
|
|
|
|
|
id="dropdownButtonSearchBook"
|
|
|
|
|
data-dropdown-toggle="dropdownSearchBook"
|
|
|
|
|
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>
|
|
|
|
|
<svg
|
|
|
|
|
class="w-5 h-5 text-gray-800 dark:text-white"
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
width="24"
|
|
|
|
|
height="24"
|
|
|
|
|
fill="none"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
d="M20 6H10m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4m16 6h-2m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4m16 6H10m0 0a2 2 0 1 0-4 0m4 0a2 2 0 1 1-4 0m0 0H4"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
<!-- Dropdown menu -->
|
|
|
|
|
<div
|
|
|
|
|
id="dropdownSearchBook"
|
|
|
|
|
class="z-10 hidden text-base list-none bg-slate-200 rounded-lg shadow-sm w-64 dark:bg-gray-700 p-2 flex flex-col gap-2"
|
|
|
|
|
>
|
|
|
|
|
<div class="flex items-center space-x-3 md:w-auto">
|
|
|
|
|
<form phx-change="change-search-mode" class="w-full">
|
|
|
|
|
<select
|
|
|
|
|
name="search_mode"
|
|
|
|
|
id="search_mode"
|
|
|
|
|
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"
|
|
|
|
|
>
|
|
|
|
|
<%= for {name, value} <- @search_mode_options do %>
|
|
|
|
|
<%= if value == @search_mode do %>
|
|
|
|
|
<option value={value} selected>{name}</option>
|
|
|
|
@ -77,11 +134,15 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
|
|
|
|
|
<% end %>
|
|
|
|
|
<% end %>
|
|
|
|
|
</select>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center space-x-3 md:w-auto">
|
|
|
|
|
<form phx-change="change-sort" class="w-full">
|
|
|
|
|
<select name="sort_by" id="sort_by" 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">
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center space-x-3 md:w-auto">
|
|
|
|
|
<form phx-change="change-sort" class="w-full">
|
|
|
|
|
<select
|
|
|
|
|
name="sort_by"
|
|
|
|
|
id="sort_by"
|
|
|
|
|
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"
|
|
|
|
|
>
|
|
|
|
|
<%= for {name, value} <- @select_options do %>
|
|
|
|
|
<%= if value == @selected_option do %>
|
|
|
|
|
<option value={value} selected>{name}</option>
|
|
|
|
@ -90,9 +151,9 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
|
|
|
|
|
<% end %>
|
|
|
|
|
<% end %>
|
|
|
|
|
</select>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|