Show if a wishlisted album is unreleased

This commit is contained in:
Claudio Ortolina
2025-01-29 10:08:28 +00:00
parent 32bc4067ff
commit 06f1997d59
8 changed files with 122 additions and 50 deletions
+10
View File
@@ -221,6 +221,16 @@ defmodule MusicLibrary.Records.Record do
end end
end end
def released?(record, current_day) do
case Date.from_iso8601(record.release) do
{:ok, release_date} ->
Date.compare(current_day, release_date) != :lt
_error ->
false
end
end
def format_as_date(purchased_at) do def format_as_date(purchased_at) do
"#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}" "#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}"
end end
@@ -7,6 +7,7 @@ defmodule MusicLibraryWeb.RecordComponents do
attr :record_show_path, :any, required: true attr :record_show_path, :any, required: true
attr :record_edit_path, :any, required: true attr :record_edit_path, :any, required: true
attr :records, :list, required: true attr :records, :list, required: true
attr :current_date, Date, required: false, default: nil
def record_list(assigns) do def record_list(assigns) do
~H""" ~H"""
@@ -43,6 +44,9 @@ defmodule MusicLibraryWeb.RecordComponents do
</h2> </h2>
<p class="mt-1 text-xs leading-5 text-zinc-500 dark:text-zinc-400"> <p class="mt-1 text-xs leading-5 text-zinc-500 dark:text-zinc-400">
{Records.Record.format_release(record.release)} {Records.Record.format_release(record.release)}
<span :if={@current_date && !Records.Record.released?(record, @current_date)}>
({gettext("Unreleased")})
</span>
</p> </p>
<p class="sm:hidden mt-1 text-xs leading-5 text-zinc-500 dark:text-zinc-400"> <p class="sm:hidden mt-1 text-xs leading-5 text-zinc-500 dark:text-zinc-400">
{Records.Record.format_long_label(record.format)} · {Records.Record.type_long_label( {Records.Record.format_long_label(record.format)} · {Records.Record.type_long_label(
@@ -23,7 +23,12 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
socket socket
end end
{:ok, assign(socket, :nav_section, :wishlist)} current_date = DateTime.utc_now() |> DateTime.to_date()
{:ok,
socket
|> assign(nav_section: :wishlist)
|> assign(:current_date, current_date)}
end end
@impl true @impl true
@@ -18,6 +18,7 @@
</div> </div>
<.record_list <.record_list
current_date={@current_date}
records={@streams.records} records={@streams.records}
record_show_path={fn record -> ~p"/wishlist/#{record}" end} record_show_path={fn record -> ~p"/wishlist/#{record}" end}
record_edit_path={fn record -> ~p"/wishlist/#{record}/edit" end} record_edit_path={fn record -> ~p"/wishlist/#{record}/edit" end}
@@ -13,7 +13,12 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
socket socket
end end
{:ok, socket} current_date = DateTime.utc_now() |> DateTime.to_date()
{:ok,
socket
|> assign(nav_section: :wishlist)
|> assign(:current_date, current_date)}
end end
@impl true @impl true
@@ -22,9 +22,13 @@
{@record.title} {@record.title}
</h2> </h2>
<p class="mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400"> <p class="mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
{Records.Record.format_release(@record.release)} · {Records.Record.format_long_label( {Records.Record.format_release(@record.release)}
@record.format <span :if={@current_date && !Records.Record.released?(@record, @current_date)}>
)} · {Records.Record.type_long_label(@record.type)} ({gettext("Unreleased")})
</span>
· {Records.Record.format_long_label(@record.format)} · {Records.Record.type_long_label(
@record.type
)}
</p> </p>
</div> </div>
<div class="relative flex-none"> <div class="relative flex-none">
+51 -45
View File
@@ -16,9 +16,9 @@ msgstr ""
msgid "Actions" msgid "Actions"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:181 #: lib/music_library_web/components/record_components.ex:185
#: lib/music_library_web/live/collection_live/show.html.heex:127 #: lib/music_library_web/live/collection_live/show.html.heex:127
#: lib/music_library_web/live/wishlist_live/show.html.heex:144 #: lib/music_library_web/live/wishlist_live/show.html.heex:148
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Are you sure?" msgid "Are you sure?"
msgstr "" msgstr ""
@@ -43,18 +43,18 @@ msgstr ""
msgid "Cover art" msgid "Cover art"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:183 #: lib/music_library_web/components/record_components.ex:187
#: lib/music_library_web/live/collection_live/show.html.heex:135 #: lib/music_library_web/live/collection_live/show.html.heex:135
#: lib/music_library_web/live/wishlist_live/show.html.heex:152 #: lib/music_library_web/live/wishlist_live/show.html.heex:156
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Delete" msgid "Delete"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:161 #: lib/music_library_web/components/record_components.ex:165
#: lib/music_library_web/live/collection_live/show.ex:139 #: lib/music_library_web/live/collection_live/show.ex:139
#: lib/music_library_web/live/collection_live/show.html.heex:70 #: lib/music_library_web/live/collection_live/show.html.heex:70
#: lib/music_library_web/live/wishlist_live/show.ex:137 #: lib/music_library_web/live/wishlist_live/show.ex:142
#: lib/music_library_web/live/wishlist_live/show.html.heex:70 #: lib/music_library_web/live/wishlist_live/show.html.heex:74
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit" msgid "Edit"
msgstr "" msgstr ""
@@ -63,8 +63,8 @@ msgstr ""
#: lib/music_library_web/live/collection_live/index.ex:125 #: lib/music_library_web/live/collection_live/index.ex:125
#: lib/music_library_web/live/stats_live/index.ex:53 #: lib/music_library_web/live/stats_live/index.ex:53
#: lib/music_library_web/live/stats_live/index.ex:59 #: lib/music_library_web/live/stats_live/index.ex:59
#: lib/music_library_web/live/wishlist_live/index.ex:115 #: lib/music_library_web/live/wishlist_live/index.ex:120
#: lib/music_library_web/live/wishlist_live/index.ex:122 #: lib/music_library_web/live/wishlist_live/index.ex:127
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error importing record" msgid "Error importing record"
msgstr "" msgstr ""
@@ -85,7 +85,7 @@ msgid "Formats"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:165 #: lib/music_library_web/live/collection_live/show.html.heex:165
#: lib/music_library_web/live/wishlist_live/show.html.heex:183 #: lib/music_library_web/live/wishlist_live/show.html.heex:187
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Genres" msgid "Genres"
msgstr "" msgstr ""
@@ -102,7 +102,7 @@ msgid "Import"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:224 #: lib/music_library_web/live/collection_live/show.html.heex:224
#: lib/music_library_web/live/wishlist_live/show.html.heex:234 #: lib/music_library_web/live/wishlist_live/show.html.heex:238
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Inserted at" msgid "Inserted at"
msgstr "" msgstr ""
@@ -130,7 +130,7 @@ msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:179 #: lib/music_library_web/live/collection_live/show.html.heex:179
#: lib/music_library_web/live/record_live/form_component.ex:50 #: lib/music_library_web/live/record_live/form_component.ex:50
#: lib/music_library_web/live/wishlist_live/show.html.heex:197 #: lib/music_library_web/live/wishlist_live/show.html.heex:201
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "MusicBrainz ID" msgid "MusicBrainz ID"
msgstr "" msgstr ""
@@ -151,9 +151,9 @@ msgstr ""
msgid "No results" msgid "No results"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:106 #: lib/music_library_web/components/record_components.ex:110
#: lib/music_library_web/live/collection_live/show.html.heex:38 #: lib/music_library_web/live/collection_live/show.html.heex:38
#: lib/music_library_web/live/wishlist_live/show.html.heex:38 #: lib/music_library_web/live/wishlist_live/show.html.heex:42
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Open options" msgid "Open options"
msgstr "" msgstr ""
@@ -169,9 +169,9 @@ msgstr ""
msgid "Previous" msgid "Previous"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:172 #: lib/music_library_web/components/record_components.ex:176
#: lib/music_library_web/live/collection_live/index.html.heex:42 #: lib/music_library_web/live/collection_live/index.html.heex:42
#: lib/music_library_web/live/wishlist_live/show.html.heex:135 #: lib/music_library_web/live/wishlist_live/show.html.heex:139
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Purchase" msgid "Purchase"
msgstr "" msgstr ""
@@ -181,8 +181,8 @@ msgstr ""
msgid "Purchased at" msgid "Purchased at"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:61 #: lib/music_library_web/components/record_components.ex:65
#: lib/music_library_web/components/record_components.ex:90 #: lib/music_library_web/components/record_components.ex:94
#: lib/music_library_web/live/collection_live/show.html.heex:201 #: lib/music_library_web/live/collection_live/show.html.heex:201
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Purchased on" msgid "Purchased on"
@@ -190,14 +190,14 @@ msgstr ""
#: lib/music_library_web/live/collection_live/index.ex:110 #: lib/music_library_web/live/collection_live/index.ex:110
#: lib/music_library_web/live/stats_live/index.ex:45 #: lib/music_library_web/live/stats_live/index.ex:45
#: lib/music_library_web/live/wishlist_live/index.ex:107 #: lib/music_library_web/live/wishlist_live/index.ex:112
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Record imported successfully" msgid "Record imported successfully"
msgstr "" msgstr ""
#: lib/music_library_web/live/record_live/form_component.ex:127 #: lib/music_library_web/live/record_live/form_component.ex:127
#: lib/music_library_web/live/wishlist_live/index.ex:135 #: lib/music_library_web/live/wishlist_live/index.ex:140
#: lib/music_library_web/live/wishlist_live/show.ex:106 #: lib/music_library_web/live/wishlist_live/show.ex:111
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Record updated successfully" msgid "Record updated successfully"
msgstr "" msgstr ""
@@ -217,7 +217,7 @@ msgstr ""
msgid "Saving..." msgid "Saving..."
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:203 #: lib/music_library_web/components/record_components.ex:207
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Search" msgid "Search"
msgstr "" msgstr ""
@@ -232,9 +232,9 @@ msgstr ""
msgid "Search for records" msgid "Search for records"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:141 #: lib/music_library_web/components/record_components.ex:145
#: lib/music_library_web/live/collection_live/show.ex:138 #: lib/music_library_web/live/collection_live/show.ex:138
#: lib/music_library_web/live/wishlist_live/show.ex:136 #: lib/music_library_web/live/wishlist_live/show.ex:141
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Show" msgid "Show"
msgstr "" msgstr ""
@@ -290,12 +290,12 @@ msgid "Types"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:232 #: lib/music_library_web/live/collection_live/show.html.heex:232
#: lib/music_library_web/live/wishlist_live/show.html.heex:242 #: lib/music_library_web/live/wishlist_live/show.html.heex:246
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Updated at" msgid "Updated at"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:151 #: lib/music_library_web/components/record_components.ex:155
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "View on MusicBrainz" msgid "View on MusicBrainz"
msgstr "" msgstr ""
@@ -307,8 +307,8 @@ msgstr ""
#: lib/music_library_web/components/layouts/app.html.heex:20 #: lib/music_library_web/components/layouts/app.html.heex:20
#: lib/music_library_web/live/artist_live/show.html.heex:76 #: lib/music_library_web/live/artist_live/show.html.heex:76
#: lib/music_library_web/live/wishlist_live/index.ex:154 #: lib/music_library_web/live/wishlist_live/index.ex:159
#: lib/music_library_web/live/wishlist_live/show.ex:130 #: lib/music_library_web/live/wishlist_live/show.ex:135
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Wishlist" msgid "Wishlist"
msgstr "" msgstr ""
@@ -325,13 +325,13 @@ msgid "close"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:189 #: lib/music_library_web/live/collection_live/show.html.heex:189
#: lib/music_library_web/live/wishlist_live/show.html.heex:207 #: lib/music_library_web/live/wishlist_live/show.html.heex:211
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy MusicBrainz ID to clipboard" msgid "Copy MusicBrainz ID to clipboard"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:243 #: lib/music_library_web/live/collection_live/show.html.heex:243
#: lib/music_library_web/live/wishlist_live/show.html.heex:253 #: lib/music_library_web/live/wishlist_live/show.html.heex:257
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "MusicBrainz data" msgid "MusicBrainz data"
msgstr "" msgstr ""
@@ -357,26 +357,26 @@ msgstr ""
msgid "Wishlisted" msgid "Wishlisted"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:54 #: lib/music_library_web/components/record_components.ex:58
#: lib/music_library_web/components/record_components.ex:83 #: lib/music_library_web/components/record_components.ex:87
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Number of included records" msgid "Number of included records"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:212 #: lib/music_library_web/live/collection_live/show.html.heex:212
#: lib/music_library_web/live/wishlist_live/show.html.heex:222 #: lib/music_library_web/live/wishlist_live/show.html.heex:226
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Includes" msgid "Includes"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.ex:54 #: lib/music_library_web/live/collection_live/show.ex:54
#: lib/music_library_web/live/wishlist_live/show.ex:53 #: lib/music_library_web/live/wishlist_live/show.ex:58
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error refreshing MusicBrainz data" msgid "Error refreshing MusicBrainz data"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.ex:46 #: lib/music_library_web/live/collection_live/show.ex:46
#: lib/music_library_web/live/wishlist_live/show.ex:45 #: lib/music_library_web/live/wishlist_live/show.ex:50
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "MusicBrainz data refreshed successfully" msgid "MusicBrainz data refreshed successfully"
msgstr "" msgstr ""
@@ -387,12 +387,12 @@ msgid "Refresh LastFm Feed"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.ex:86 #: lib/music_library_web/live/collection_live/show.ex:86
#: lib/music_library_web/live/wishlist_live/show.ex:65 #: lib/music_library_web/live/wishlist_live/show.ex:70
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Cover refreshed successfully" msgid "Cover refreshed successfully"
msgstr "" msgstr ""
#: lib/music_library_web/live/wishlist_live/show.ex:73 #: lib/music_library_web/live/wishlist_live/show.ex:78
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error refreshing Cover" msgid "Error refreshing Cover"
msgstr "" msgstr ""
@@ -418,7 +418,7 @@ msgstr ""
msgid "Import from MusicBrainz · Collection" msgid "Import from MusicBrainz · Collection"
msgstr "" msgstr ""
#: lib/music_library_web/live/wishlist_live/index.ex:44 #: lib/music_library_web/live/wishlist_live/index.ex:49
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Import from MusicBrainz · Wishlist" msgid "Import from MusicBrainz · Wishlist"
msgstr "" msgstr ""
@@ -454,31 +454,31 @@ msgid "Loading play count"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.ex:74 #: lib/music_library_web/live/collection_live/show.ex:74
#: lib/music_library_web/live/wishlist_live/show.ex:93 #: lib/music_library_web/live/wishlist_live/show.ex:98
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error populating genres" msgid "Error populating genres"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.ex:66 #: lib/music_library_web/live/collection_live/show.ex:66
#: lib/music_library_web/live/wishlist_live/show.ex:85 #: lib/music_library_web/live/wishlist_live/show.ex:90
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Genres populated successfully" msgid "Genres populated successfully"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:118 #: lib/music_library_web/live/collection_live/show.html.heex:118
#: lib/music_library_web/live/wishlist_live/show.html.heex:118 #: lib/music_library_web/live/wishlist_live/show.html.heex:122
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Populate genres" msgid "Populate genres"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:102 #: lib/music_library_web/live/collection_live/show.html.heex:102
#: lib/music_library_web/live/wishlist_live/show.html.heex:102 #: lib/music_library_web/live/wishlist_live/show.html.heex:106
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Refresh MB data" msgid "Refresh MB data"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:86 #: lib/music_library_web/live/collection_live/show.html.heex:86
#: lib/music_library_web/live/wishlist_live/show.html.heex:86 #: lib/music_library_web/live/wishlist_live/show.html.heex:90
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Refresh cover" msgid "Refresh cover"
msgstr "" msgstr ""
@@ -528,13 +528,19 @@ msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: lib/music_library_web/live/collection_live/show.html.heex:153 #: lib/music_library_web/live/collection_live/show.html.heex:153
#: lib/music_library_web/live/wishlist_live/show.html.heex:171 #: lib/music_library_web/live/wishlist_live/show.html.heex:175
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy record ID to clipboard" msgid "Copy record ID to clipboard"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex:145 #: lib/music_library_web/live/collection_live/show.html.heex:145
#: lib/music_library_web/live/wishlist_live/show.html.heex:163 #: lib/music_library_web/live/wishlist_live/show.html.heex:167
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "ID" msgid "ID"
msgstr "" msgstr ""
#: lib/music_library_web/components/record_components.ex:48
#: lib/music_library_web/live/wishlist_live/show.html.heex:27
#, elixir-autogen, elixir-format
msgid "Unreleased"
msgstr ""
@@ -0,0 +1,37 @@
defmodule MusicLibrary.Records.RecordTest do
use ExUnit.Case, async: true
defp get_current_date(_) do
%{current_date: ~D[2025-01-01]}
end
describe "released?/2" do
setup :get_current_date
test "returns true if the record has a release date in the past", %{
current_date: current_date
} do
record = %MusicLibrary.Records.Record{release: "2024-01-01"}
assert MusicLibrary.Records.Record.released?(record, current_date)
end
test "returns false if the record has a release date in the future", %{
current_date: current_date
} do
record = %MusicLibrary.Records.Record{release: "2025-02-01"}
refute MusicLibrary.Records.Record.released?(record, current_date)
end
test "returns true if the record is released today", %{current_date: current_date} do
record = %MusicLibrary.Records.Record{release: "2025-01-01"}
assert MusicLibrary.Records.Record.released?(record, current_date)
end
test "it returns false if the release date is not precise enough", %{
current_date: current_date
} do
record = %MusicLibrary.Records.Record{release: "2019"}
refute MusicLibrary.Records.Record.released?(record, current_date)
end
end
end