commit 7803007814b224bdac9a6cfacf2ef5f09e1a1827
parent c456c17f2b09f765c4f9b6085f2593d56e209d7d
Author: mtmn <miro@haravara.org>
Date: Sun, 19 Apr 2026 20:59:08 +0200
feat: scrobbles searchable by album
Diffstat:
5 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/src/Client.elm b/src/Client.elm
@@ -939,12 +939,7 @@ renderListen userSlug currentTime failedCovers hoveredCover similarStates idx li
, div [ class "track-artist" ] [ text artist ]
, div [ class "track-time" ]
[ span []
- (a
- [ href ("https://www.discogs.com/search/?q=" ++ Url.percentEncode (artist ++ " " ++ release) ++ "&type=release")
- , target "_blank"
- , class "album-link"
- ]
- [ text release ]
+ (button [ class "album-link", onClick (FilterBy "album" release) ] [ text release ]
:: (case listen.label of
Just l ->
[ text " • "
diff --git a/src/Db.purs b/src/Db.purs
@@ -35,12 +35,13 @@ import Metrics as Metrics
foreign import data Connection :: Type
-data FilterField = FilterArtist | FilterLabel | FilterYear | FilterGenre
+data FilterField = FilterArtist | FilterAlbum | FilterLabel | FilterYear | FilterGenre
derive instance Eq FilterField
instance Show FilterField where
show FilterArtist = "FilterArtist"
+ show FilterAlbum = "FilterAlbum"
show FilterLabel = "FilterLabel"
show FilterYear = "FilterYear"
show FilterGenre = "FilterGenre"
@@ -213,6 +214,10 @@ filterQuery FilterArtist =
scrobbleCols <> scrobbleFromLeft
<> " WHERE s.artist_name = ?"
<> scrobbleOrderPage
+filterQuery FilterAlbum =
+ scrobbleCols <> scrobbleFromLeft
+ <> " WHERE s.release_name = ?"
+ <> scrobbleOrderPage
filterQuery FilterLabel =
scrobbleCols <> scrobbleFromInner
<> " WHERE rm.label = ?"
diff --git a/src/Main.purs b/src/Main.purs
@@ -435,6 +435,7 @@ getQueryParam name url = URLSearchParams.get name (URL.searchParams url)
parseFilterField :: String -> Maybe FilterField
parseFilterField "artist" = Just FilterArtist
+parseFilterField "album" = Just FilterAlbum
parseFilterField "label" = Just FilterLabel
parseFilterField "year" = Just FilterYear
parseFilterField "genre" = Just FilterGenre
diff --git a/src/Templates.purs b/src/Templates.purs
@@ -94,8 +94,14 @@ indexHtml userSlug allUsers =
}
.album-link {
+ background: none;
+ border: none;
+ padding: 0;
color: #9fbfe7;
text-decoration: underline;
+ font-family: inherit;
+ font-size: inherit;
+ cursor: pointer;
}
.album-link:hover {
diff --git a/test/Main.purs b/test/Main.purs
@@ -32,6 +32,7 @@ main = runSpecAndExitProcess [consoleReporter] do
describe "parseFilterField" do
it "maps all valid field names" do
parseFilterField "artist" `shouldEqual` Just FilterArtist
+ parseFilterField "album" `shouldEqual` Just FilterAlbum
parseFilterField "label" `shouldEqual` Just FilterLabel
parseFilterField "year" `shouldEqual` Just FilterYear
parseFilterField "genre" `shouldEqual` Just FilterGenre
@@ -211,6 +212,28 @@ main = runSpecAndExitProcess [consoleReporter] do
listensNone <- getScrobbles conn 10 0 (Just { field: FilterArtist, value: "Gamma" }) Nothing
length listensNone `shouldEqual` 0
+ it "filters by album" do
+ conn <- connect ":memory:"
+ initDb conn
+ initReleaseMetadata conn
+ let mkListen artist release = Listen
+ { listenedAt: Just 1
+ , trackMetadata: TrackMetadata
+ { trackName: Just "Track"
+ , artistName: Just artist
+ , releaseName: Just release
+ , mbidMapping: Nothing
+ , genre: Nothing
+ , label: Nothing
+ }
+ }
+ upsertScrobble conn (mkListen "Artist" "Album A")
+ upsertScrobble conn (mkListen "Artist" "Album B")
+ listens <- getScrobbles conn 10 0 (Just { field: FilterAlbum, value: "Album A" }) Nothing
+ length listens `shouldEqual` 1
+ listensNone <- getScrobbles conn 10 0 (Just { field: FilterAlbum, value: "Album C" }) Nothing
+ length listensNone `shouldEqual` 0
+
it "filters by label" do
conn <- connect ":memory:"
initDb conn