add support for /tags/:tag and other endpoints

This commit is contained in:
Laptop
2024-12-22 00:02:23 +02:00
parent bf22bbf13b
commit e4f6d7f608
6 changed files with 160 additions and 2 deletions

View File

@@ -12,7 +12,7 @@ templ Base(title string, content templ.Component, head templ.Component) {
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/global.css"/>
<link rel="stylesheet" href="global.css"/>
<link rel="stylesheet" href="/instance.css"/>
if title != "" {
<title>{ title } ~ soundcloak</title>
} else {

75
templates/tags.templ Normal file
View File

@@ -0,0 +1,75 @@
package templates
import (
"github.com/maid-zone/soundcloak/lib/sc"
"net/url"
"strings"
"strconv"
)
templ TagsButtons(current string, tag string) {
<div class="btns">
for _, b := range [...]btn{{"recent tracks", "", false},{"popular tracks", "/popular-tracks", false},{"playlists", "/playlists",false}} {
if b.text == current {
<a class="btn active">{ b.text }</a>
} else {
<a class="btn" href={ templ.URL("/tags/" + tag + b.href) }>{ b.text }</a>
}
}
</div>
<br/>
}
templ RecentTracks(tag string, p *sc.Paginated[*sc.Track]) {
<h1>Recent tracks tagged {url.PathUnescape(tag)}</h1>
@TagsButtons("recent tracks", tag)
if len(p.Collection) == 0 {
<p>no more tracks</p>
} else {
for _, track := range p.Collection {
@TrackItem(track, true, "")
}
if p.Next != "" {
<a class="btn" href={ templ.URL("/tags/" + tag + "?pagination=" + url.QueryEscape(strings.Split(p.Next, "/recent-tracks")[1])) } rel="noreferrer">more tracks</a>
}
}
}
templ PopularTracks(tag string, p *sc.Paginated[*sc.Track]) {
<h1>Popular tracks tagged {url.PathUnescape(tag)}</h1>
@TagsButtons("popular tracks", tag)
<span>Found { strconv.FormatInt(p.Total, 10) } tracks</span>
<br/>
<br/>
if len(p.Collection) == 0 {
<p>no more tracks</p>
} else {
for _, track := range p.Collection {
@TrackItem(track, true, "")
}
if p.Next != "" {
<a class="btn" href={ templ.URL("/tags/" + tag + "/popular-tracks?pagination=" + url.QueryEscape(strings.Split(p.Next, "/tracks")[1])) } rel="noreferrer">more tracks</a>
}
}
}
templ TaggedPlaylists(tag string, p *sc.Paginated[*sc.Playlist]) {
<h1>Playlists tagged {url.PathUnescape(tag)}</h1>
@TagsButtons("playlists", tag)
<span>Found { strconv.FormatInt(p.Total, 10) } playlists</span>
<br/>
<br/>
if len(p.Collection) == 0 {
if p.Total != 0 {
<p>no more results</p>
}
} else {
for _, playlist := range p.Collection {
@PlaylistItem(playlist, true)
}
if p.Next != "" && len(p.Collection) != int(p.Total) {
<a class="btn" href={ templ.URL("?type=playlists&pagination=" + url.QueryEscape(strings.Split(p.Next, "/playlists")[1])) } rel="noreferrer">more playlists</a>
}
}
}

View File

@@ -133,7 +133,7 @@ templ Track(prefs cfg.Preferences, t sc.Track, stream string, displayErr string,
<h1>{ t.Title }</h1>
@TrackPlayer(prefs, t, stream, displayErr, autoplay, nextTrack, playlist, volume, mode, audio)
if t.Genre != "" {
<p class="tag">{ t.Genre }</p>
<a href={templ.URL("/tags/"+t.Genre)}><p class="tag">{ t.Genre }</p></a>
}
if playlist != nil {
<details open style="margin-bottom: 1rem;">