Make collection ordered by purchase by default

This commit is contained in:
Claudio Ortolina
2025-04-04 13:58:25 +01:00
parent 8de88fcf72
commit 8b846298a7
4 changed files with 21 additions and 21 deletions
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
query: "",
page: 1,
page_size: 20,
order: :alphabetical
order: :purchase
}
@impl true
@@ -78,7 +78,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
defp apply_action(socket, :index, params) do
query = params["query"] || ""
order = parse_order(params["order"] || "alphabetical")
order = parse_order(params["order"] || "purchase")
total_records = Collection.search_records_count(query)
record_list_params =
@@ -37,23 +37,10 @@
<div class="flex items-end justify-between gap-6 mt-8">
<span class="isolate inline-flex rounded-md shadow-xs">
<.link
patch={order_path(@record_list_params, :alphabetical)}
class={[
"relative inline-flex items-center rounded-l-md",
"px-3 py-2 text-xs sm:text-sm font-semibold",
"ring-1 ring-inset focus:z-10",
"bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-700 ring-zinc-300",
@record_list_params.order == :alphabetical && "!bg-zinc-100 dark:!bg-zinc-700"
]}
>
<.icon name="hero-user-solid" class="mr-1 h-4 w-4" aria-hidden="true" data-slot="icon" />
{gettext("A->Z")}
</.link>
<.link
patch={order_path(@record_list_params, :purchase)}
class={[
"relative -ml-px inline-flex items-center rounded-r-md",
"relative inline-flex items-center rounded-l-md",
"px-3 py-2 text-xs sm:text-sm font-semibold",
"ring-1 ring-inset focus:z-10",
"bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-700 ring-zinc-300",
@@ -68,6 +55,19 @@
/>
{gettext("Purchase")}
</.link>
<.link
patch={order_path(@record_list_params, :alphabetical)}
class={[
"relative -ml-px inline-flex items-center rounded-r-md",
"px-3 py-2 text-xs sm:text-sm font-semibold",
"ring-1 ring-inset focus:z-10",
"bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-700 ring-zinc-300",
@record_list_params.order == :alphabetical && "!bg-zinc-100 dark:!bg-zinc-700"
]}
>
<.icon name="hero-user-solid" class="mr-1 h-4 w-4" aria-hidden="true" data-slot="icon" />
{gettext("A->Z")}
</.link>
</span>
<p class="text-right text-sm max-sm:text-xs text-zinc-900 dark:text-zinc-400">
+2 -2
View File
@@ -158,7 +158,7 @@ msgstr ""
msgid "Previous"
msgstr ""
#: lib/music_library_web/live/collection_live/index.html.heex:69
#: lib/music_library_web/live/collection_live/index.html.heex:56
#, elixir-autogen, elixir-format
msgid "Purchase"
msgstr ""
@@ -458,7 +458,7 @@ msgstr ""
msgid "Error loading play count"
msgstr ""
#: lib/music_library_web/live/collection_live/index.html.heex:51
#: lib/music_library_web/live/collection_live/index.html.heex:69
#, elixir-autogen, elixir-format
msgid "A->Z"
msgstr ""
@@ -41,7 +41,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
{expected_present, expected_absent} = Enum.split(records, @default_records_page_size)
session = visit(conn, ~p"/collection")
session = visit(conn, ~p"/collection?order=alphabetical")
for record <- expected_present do
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
@@ -80,7 +80,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
{page_2_records, rest_of_records} = Enum.split(rest_of_records, page_size)
page_2_session =
visit(conn, ~p"/collection?page=2&page_size=#{page_size}")
visit(conn, ~p"/collection?order=alphabetical&page=2&page_size=#{page_size}")
for record <- page_1_records do
refute_has(page_2_session, "#records-#{record.id}")
@@ -102,7 +102,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
{page_3_records, rest_of_records} = Enum.split(rest_of_records, page_size)
page_3_session =
visit(conn, ~p"/collection?page=3&page_size=#{page_size}")
visit(conn, ~p"/collection?order=alphabetical&page=3&page_size=#{page_size}")
for record <- page_3_records do
assert_has(page_3_session, "#records-#{record.id}")