/discover - featured playlists, some more fixes

This commit is contained in:
Laptop
2024-11-23 00:22:04 +02:00
parent 0e8244b3cc
commit ea3426edd9
7 changed files with 103 additions and 27 deletions

View File

@@ -1,16 +1,14 @@
package templates
// I made a separate templates file for this, since I'm planning on adding another "featured" feature later (soundcloud.com/discover)
import (
"github.com/maid-zone/soundcloak/lib/sc"
"net/url"
"strings"
"strconv"
)
templ FeaturedTracks(p *sc.Paginated[*sc.Track]) {
<h1>Featured Tracks</h1>
<br/>
if len(p.Collection) == 0 {
<p>no more tracks</p>
} else {
@@ -22,3 +20,27 @@ templ FeaturedTracks(p *sc.Paginated[*sc.Track]) {
}
}
}
templ Discover(p *sc.Paginated[*sc.Selection]) {
<h1>Discover Playlists</h1> // also tracks apparently? haven't seen any
<span>Got { strconv.FormatInt(int64(len(p.Collection)), 10) } playlists</span>
if len(p.Collection) != 0 {
for _, selection := range p.Collection {
// skip so we don't just include the title and zero playlists with it
if len(selection.Items.Collection) == 0 {
{{ continue }} // raw go code my beloved
}
<h2>{selection.Title}</h2>
for _, pl := range selection.Items.Collection {
// We don't need the username
@PlaylistItem(pl, false)
}
}
// I don't think they have pagination for this endpoint, just leaving this here, in case they actually do
// if p.Next != "" {
// <a class="btn" href={ templ.URL("/discover?pagination=" + url.QueryEscape(strings.Split(p.Next, "/discover")[1])) } rel="noreferrer">more playlists</a>
// }
}
}

View File

@@ -38,7 +38,7 @@ templ Playlist(p sc.Playlist) {
}
<h1>{ p.Title }</h1>
@UserItem(&p.Author)
<div class="btns">
<div style="display: flex;">
<a class="btn" href={ templ.URL("https://soundcloud.com/" + p.Author.Permalink + "/sets/" + p.Permalink) }>view on soundcloud</a>
</div>
<br/>