diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex
index 57a0b143..4b2eff8f 100644
--- a/lib/music_library/records/record.ex
+++ b/lib/music_library/records/record.ex
@@ -221,6 +221,16 @@ defmodule MusicLibrary.Records.Record do
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
"#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}"
end
diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex
index 39c6f7d5..e5584d45 100644
--- a/lib/music_library_web/components/record_components.ex
+++ b/lib/music_library_web/components/record_components.ex
@@ -7,6 +7,7 @@ defmodule MusicLibraryWeb.RecordComponents do
attr :record_show_path, :any, required: true
attr :record_edit_path, :any, required: true
attr :records, :list, required: true
+ attr :current_date, Date, required: false, default: nil
def record_list(assigns) do
~H"""
@@ -43,6 +44,9 @@ defmodule MusicLibraryWeb.RecordComponents do
{Records.Record.format_release(record.release)}
+
+ ({gettext("Unreleased")})
+
{Records.Record.format_long_label(record.format)} · {Records.Record.type_long_label(
diff --git a/lib/music_library_web/live/wishlist_live/index.ex b/lib/music_library_web/live/wishlist_live/index.ex
index 5953ff95..371e2279 100644
--- a/lib/music_library_web/live/wishlist_live/index.ex
+++ b/lib/music_library_web/live/wishlist_live/index.ex
@@ -23,7 +23,12 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
socket
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
@impl true
diff --git a/lib/music_library_web/live/wishlist_live/index.html.heex b/lib/music_library_web/live/wishlist_live/index.html.heex
index 28fe19b7..98434f3a 100644
--- a/lib/music_library_web/live/wishlist_live/index.html.heex
+++ b/lib/music_library_web/live/wishlist_live/index.html.heex
@@ -18,6 +18,7 @@
<.record_list
+ current_date={@current_date}
records={@streams.records}
record_show_path={fn record -> ~p"/wishlist/#{record}" end}
record_edit_path={fn record -> ~p"/wishlist/#{record}/edit" end}
diff --git a/lib/music_library_web/live/wishlist_live/show.ex b/lib/music_library_web/live/wishlist_live/show.ex
index 2392ff20..8b48c9b5 100644
--- a/lib/music_library_web/live/wishlist_live/show.ex
+++ b/lib/music_library_web/live/wishlist_live/show.ex
@@ -13,7 +13,12 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
socket
end
- {:ok, socket}
+ current_date = DateTime.utc_now() |> DateTime.to_date()
+
+ {:ok,
+ socket
+ |> assign(nav_section: :wishlist)
+ |> assign(:current_date, current_date)}
end
@impl true
diff --git a/lib/music_library_web/live/wishlist_live/show.html.heex b/lib/music_library_web/live/wishlist_live/show.html.heex
index 568128ff..e0148163 100644
--- a/lib/music_library_web/live/wishlist_live/show.html.heex
+++ b/lib/music_library_web/live/wishlist_live/show.html.heex
@@ -22,9 +22,13 @@
{@record.title}
- {Records.Record.format_release(@record.release)} · {Records.Record.format_long_label(
- @record.format
- )} · {Records.Record.type_long_label(@record.type)}
+ {Records.Record.format_release(@record.release)}
+
+ ({gettext("Unreleased")})
+
+ · {Records.Record.format_long_label(@record.format)} · {Records.Record.type_long_label(
+ @record.type
+ )}
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot
index 573b83aa..f40c006e 100644
--- a/priv/gettext/default.pot
+++ b/priv/gettext/default.pot
@@ -16,9 +16,9 @@ msgstr ""
msgid "Actions"
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/wishlist_live/show.html.heex:144
+#: lib/music_library_web/live/wishlist_live/show.html.heex:148
#, elixir-autogen, elixir-format
msgid "Are you sure?"
msgstr ""
@@ -43,18 +43,18 @@ msgstr ""
msgid "Cover art"
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/wishlist_live/show.html.heex:152
+#: lib/music_library_web/live/wishlist_live/show.html.heex:156
#, elixir-autogen, elixir-format
msgid "Delete"
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.html.heex:70
-#: lib/music_library_web/live/wishlist_live/show.ex:137
-#: lib/music_library_web/live/wishlist_live/show.html.heex:70
+#: lib/music_library_web/live/wishlist_live/show.ex:142
+#: lib/music_library_web/live/wishlist_live/show.html.heex:74
#, elixir-autogen, elixir-format
msgid "Edit"
msgstr ""
@@ -63,8 +63,8 @@ msgstr ""
#: 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:59
-#: lib/music_library_web/live/wishlist_live/index.ex:115
-#: lib/music_library_web/live/wishlist_live/index.ex:122
+#: lib/music_library_web/live/wishlist_live/index.ex:120
+#: lib/music_library_web/live/wishlist_live/index.ex:127
#, elixir-autogen, elixir-format
msgid "Error importing record"
msgstr ""
@@ -85,7 +85,7 @@ msgid "Formats"
msgstr ""
#: 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
msgid "Genres"
msgstr ""
@@ -102,7 +102,7 @@ msgid "Import"
msgstr ""
#: 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
msgid "Inserted at"
msgstr ""
@@ -130,7 +130,7 @@ msgstr ""
#: 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/wishlist_live/show.html.heex:197
+#: lib/music_library_web/live/wishlist_live/show.html.heex:201
#, elixir-autogen, elixir-format
msgid "MusicBrainz ID"
msgstr ""
@@ -151,9 +151,9 @@ msgstr ""
msgid "No results"
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/wishlist_live/show.html.heex:38
+#: lib/music_library_web/live/wishlist_live/show.html.heex:42
#, elixir-autogen, elixir-format
msgid "Open options"
msgstr ""
@@ -169,9 +169,9 @@ msgstr ""
msgid "Previous"
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/wishlist_live/show.html.heex:135
+#: lib/music_library_web/live/wishlist_live/show.html.heex:139
#, elixir-autogen, elixir-format
msgid "Purchase"
msgstr ""
@@ -181,8 +181,8 @@ msgstr ""
msgid "Purchased at"
msgstr ""
-#: lib/music_library_web/components/record_components.ex:61
-#: lib/music_library_web/components/record_components.ex:90
+#: lib/music_library_web/components/record_components.ex:65
+#: lib/music_library_web/components/record_components.ex:94
#: lib/music_library_web/live/collection_live/show.html.heex:201
#, elixir-autogen, elixir-format
msgid "Purchased on"
@@ -190,14 +190,14 @@ msgstr ""
#: 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/wishlist_live/index.ex:107
+#: lib/music_library_web/live/wishlist_live/index.ex:112
#, elixir-autogen, elixir-format
msgid "Record imported successfully"
msgstr ""
#: 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/show.ex:106
+#: lib/music_library_web/live/wishlist_live/index.ex:140
+#: lib/music_library_web/live/wishlist_live/show.ex:111
#, elixir-autogen, elixir-format
msgid "Record updated successfully"
msgstr ""
@@ -217,7 +217,7 @@ msgstr ""
msgid "Saving..."
msgstr ""
-#: lib/music_library_web/components/record_components.ex:203
+#: lib/music_library_web/components/record_components.ex:207
#, elixir-autogen, elixir-format
msgid "Search"
msgstr ""
@@ -232,9 +232,9 @@ msgstr ""
msgid "Search for records"
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/wishlist_live/show.ex:136
+#: lib/music_library_web/live/wishlist_live/show.ex:141
#, elixir-autogen, elixir-format
msgid "Show"
msgstr ""
@@ -290,12 +290,12 @@ msgid "Types"
msgstr ""
#: 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
msgid "Updated at"
msgstr ""
-#: lib/music_library_web/components/record_components.ex:151
+#: lib/music_library_web/components/record_components.ex:155
#, elixir-autogen, elixir-format
msgid "View on MusicBrainz"
msgstr ""
@@ -307,8 +307,8 @@ msgstr ""
#: 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/wishlist_live/index.ex:154
-#: lib/music_library_web/live/wishlist_live/show.ex:130
+#: lib/music_library_web/live/wishlist_live/index.ex:159
+#: lib/music_library_web/live/wishlist_live/show.ex:135
#, elixir-autogen, elixir-format
msgid "Wishlist"
msgstr ""
@@ -325,13 +325,13 @@ msgid "close"
msgstr ""
#: 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
msgid "Copy MusicBrainz ID to clipboard"
msgstr ""
#: 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
msgid "MusicBrainz data"
msgstr ""
@@ -357,26 +357,26 @@ msgstr ""
msgid "Wishlisted"
msgstr ""
-#: lib/music_library_web/components/record_components.ex:54
-#: lib/music_library_web/components/record_components.ex:83
+#: lib/music_library_web/components/record_components.ex:58
+#: lib/music_library_web/components/record_components.ex:87
#, elixir-autogen, elixir-format
msgid "Number of included records"
msgstr ""
#: 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
msgid "Includes"
msgstr ""
#: 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
msgid "Error refreshing MusicBrainz data"
msgstr ""
#: 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
msgid "MusicBrainz data refreshed successfully"
msgstr ""
@@ -387,12 +387,12 @@ msgid "Refresh LastFm Feed"
msgstr ""
#: 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
msgid "Cover refreshed successfully"
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
msgid "Error refreshing Cover"
msgstr ""
@@ -418,7 +418,7 @@ msgstr ""
msgid "Import from MusicBrainz · Collection"
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
msgid "Import from MusicBrainz · Wishlist"
msgstr ""
@@ -454,31 +454,31 @@ msgid "Loading play count"
msgstr ""
#: 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
msgid "Error populating genres"
msgstr ""
#: 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
msgid "Genres populated successfully"
msgstr ""
#: 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
msgid "Populate genres"
msgstr ""
#: 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
msgid "Refresh MB data"
msgstr ""
#: 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
msgid "Refresh cover"
msgstr ""
@@ -528,13 +528,19 @@ msgstr[0] ""
msgstr[1] ""
#: 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
msgid "Copy record ID to clipboard"
msgstr ""
#: 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
msgid "ID"
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 ""
diff --git a/test/music_library/records/record_test.exs b/test/music_library/records/record_test.exs
new file mode 100644
index 00000000..82f20492
--- /dev/null
+++ b/test/music_library/records/record_test.exs
@@ -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