mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 05:39:38 +05:00
288 lines
8.3 KiB
Plaintext
288 lines
8.3 KiB
Plaintext
package templates
|
|
|
|
import (
|
|
"git.maid.zone/stuff/soundcloak/lib/cfg"
|
|
"git.maid.zone/stuff/soundcloak/lib/sc"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
templ UserHeader(u sc.User) {
|
|
<meta name="og:site_name" content="soundcloak"/>
|
|
<meta name="og:title" content={ u.FormatUsername() }/>
|
|
<meta name="og:description" content={ u.FormatDescription() }/>
|
|
<meta name="og:image" content={ u.Avatar }/>
|
|
<link rel="icon" type="image/x-icon" href={ u.Avatar }/>
|
|
}
|
|
|
|
templ UserItem(user *sc.User) {
|
|
<a class="listing" href={ templ.SafeURL("/" + user.Permalink) }>
|
|
if user.Avatar != "" {
|
|
<img loading="lazy" fetchpriority="low" src={ user.Avatar }/>
|
|
} else {
|
|
<img loading="lazy" fetchpriority="low" src="/_/static/placeholder.jpg"/>
|
|
}
|
|
<div class="meta">
|
|
<h3>{ user.Username }</h3>
|
|
if user.FullName != "" {
|
|
<span>{ user.FullName }</span>
|
|
}
|
|
</div>
|
|
</a>
|
|
}
|
|
|
|
templ UserLinks(links []sc.Link) {
|
|
for _, link := range links {
|
|
if len(link.URL) > 0 {
|
|
if link.URL[0] == '/' {
|
|
<p><a class="link" href={ templ.SafeURL(link.URL) }>- { link.Title }</a></p>
|
|
} else {
|
|
<p><a class="link" href={ templ.URL(link.URL) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">- { link.Title }</a></p>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
templ UserBase(prefs cfg.Preferences, u sc.User) {
|
|
<div>
|
|
if u.Avatar != "" {
|
|
<img src={ u.Avatar } width="300px"/>
|
|
}
|
|
<h1>{ u.Username }</h1>
|
|
if u.FullName != "" {
|
|
<h2>{ u.FullName }</h2>
|
|
}
|
|
if u.Verified {
|
|
<p style="color: var(--accent)">Verified</p>
|
|
}
|
|
</div>
|
|
if len(u.WebProfiles) != 0 {
|
|
@Description(prefs, u.Description, UserLinks(u.WebProfiles))
|
|
} else {
|
|
@Description(prefs, u.Description, nil)
|
|
}
|
|
<div>
|
|
<p><a class="link" href={templ.SafeURL("/" + u.Permalink + "/followers")}>{ strconv.FormatInt(u.Followers, 10) } followers</a></p>
|
|
<p><a class="link" href={templ.SafeURL("/" + u.Permalink + "/following")}>{ strconv.FormatInt(u.Following, 10) } followings</a></p>
|
|
<p><a class="link" href={templ.SafeURL("/" + u.Permalink + "/likes")}>{ strconv.FormatInt(u.Liked, 10) } liked</a></p>
|
|
<p>{ strconv.FormatInt(u.Tracks, 10) } tracks</p>
|
|
<p>{ strconv.FormatInt(u.Playlists, 10) } playlists & albums</p>
|
|
<br/>
|
|
<p>Created: { u.CreatedAt }</p>
|
|
<p>Last modified: { u.LastModified }</p>
|
|
</div>
|
|
}
|
|
|
|
type btn struct {
|
|
text string
|
|
href string
|
|
override bool
|
|
external bool
|
|
}
|
|
|
|
templ UserButtons(current string, user sc.User) {
|
|
<div class="btns">
|
|
// this part is the tedious one now, because formatting breaks if i space the list out with newlines
|
|
for _, b := range [...]btn{{"tracks", "", false, false},{"popular tracks", "/popular-tracks", false, false},{"playlists", "/sets", false, false},{"albums", "/albums", false, false},{"reposts","/reposts", false, false},{"related", "/_/related", false, false},{"user station", "/discover/sets/"+user.Station, true, false},{"view on soundcloud", "https://soundcloud.com/"+user.Permalink, true, true}} {
|
|
if b.text == current {
|
|
<a class="btn active">{ b.text }</a>
|
|
} else {
|
|
if b.external {
|
|
<a class="btn" href={ templ.SafeURL(b.href) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">{ b.text }</a>
|
|
} else {
|
|
if b.override {
|
|
<a class="btn" href={ templ.SafeURL(b.href) }>{ b.text }</a>
|
|
} else {
|
|
<a class="btn" href={ templ.SafeURL("/" + user.Permalink + b.href) }>{ b.text }</a>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</div>
|
|
}
|
|
|
|
templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
|
|
@UserBase(prefs, u)
|
|
// kinda tedious but whatever, might make it more flexible in the future
|
|
// ^ outdated, no longer tedious but whatever
|
|
@UserButtons("tracks", u)
|
|
<br/>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, track := range p.Collection {
|
|
@TrackItem(track, false, "")
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(u.Tracks) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/tracks")[1])) } rel="noreferrer">more tracks</a>
|
|
}
|
|
} else {
|
|
<span>no more tracks</span>
|
|
}
|
|
}
|
|
|
|
templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("playlists", u)
|
|
<br/>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, playlist := range p.Collection {
|
|
@PlaylistItem(playlist, false)
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/playlists_without_albums")[1])) } rel="noreferrer">more playlists</a>
|
|
}
|
|
} else {
|
|
<span>no more playlists</span>
|
|
}
|
|
}
|
|
|
|
templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("albums", u)
|
|
<br/>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, playlist := range p.Collection {
|
|
@PlaylistItem(playlist, false)
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/albums")[1])) } rel="noreferrer">more albums</a>
|
|
}
|
|
} else {
|
|
<span>no more albums</span>
|
|
}
|
|
}
|
|
|
|
templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("reposts", u)
|
|
<br/>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, repost := range p.Collection {
|
|
if repost.Type == sc.TrackRepost && repost.Track != nil {
|
|
@TrackItem(repost.Track, true, "")
|
|
} else if repost.Type == sc.PlaylistRepost && repost.Playlist != nil {
|
|
@PlaylistItem(repost.Playlist, true)
|
|
}
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/reposts")[1])) } rel="noreferrer">more reposts</a>
|
|
}
|
|
} else {
|
|
<span>no more reposts</span>
|
|
}
|
|
}
|
|
|
|
templ UserLikes(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Like]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("", u)
|
|
<h1>Likes</h1>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, like := range p.Collection {
|
|
if like.Track != nil {
|
|
@TrackItem(like.Track, true, "")
|
|
} else if like.Playlist != nil {
|
|
@PlaylistItem(like.Playlist, true)
|
|
}
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/likes")[1])) } rel="noreferrer">more likes</a>
|
|
}
|
|
} else {
|
|
<span>no more likes</span>
|
|
}
|
|
}
|
|
|
|
templ UserRelated(prefs cfg.Preferences, u sc.User, r []*sc.User) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("related", u)
|
|
<br/>
|
|
if len(r) != 0 {
|
|
<div>
|
|
for _, u := range r {
|
|
@UserItem(u)
|
|
}
|
|
</div>
|
|
} else {
|
|
<span>no related users</span>
|
|
}
|
|
}
|
|
|
|
templ UserTopTracks(prefs cfg.Preferences, u sc.User, t []*sc.Track) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("popular tracks", u)
|
|
<br/>
|
|
if len(t) != 0 {
|
|
<div>
|
|
for _, track := range t {
|
|
@TrackItem(track, false, "")
|
|
}
|
|
</div>
|
|
} else {
|
|
<span>no popular tracks</span>
|
|
}
|
|
}
|
|
|
|
templ UserFollowers(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.User]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("", u)
|
|
<h1>Followers</h1>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, user := range p.Collection {
|
|
@UserItem(user)
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/followers")[1])) } rel="noreferrer">more users</a>
|
|
}
|
|
} else {
|
|
<span>no more users</span>
|
|
}
|
|
}
|
|
|
|
templ UserFollowing(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.User]) {
|
|
@UserBase(prefs, u)
|
|
@UserButtons("", u)
|
|
<h1>Following</h1>
|
|
if len(p.Collection) != 0 {
|
|
<div>
|
|
for _, user := range p.Collection {
|
|
@UserItem(user)
|
|
}
|
|
</div>
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/following")[1])) } rel="noreferrer">more users</a>
|
|
}
|
|
} else {
|
|
<span>no more users</span>
|
|
}
|
|
}
|
|
|
|
templ SearchUsers(p *sc.Paginated[*sc.User]) {
|
|
<span>Found { strconv.FormatInt(p.Total, 10) } users</span>
|
|
<br/>
|
|
<br/>
|
|
if len(p.Collection) == 0 {
|
|
if p.Total != 0 {
|
|
<p>no more results</p>
|
|
}
|
|
} else {
|
|
for _, user := range p.Collection {
|
|
@UserItem(user)
|
|
}
|
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
|
<a class="btn" href={ templ.SafeURL("?type=users&pagination=" + url.QueryEscape(strings.Split(p.Next, "/users")[1])) } rel="noreferrer">more users</a>
|
|
}
|
|
}
|
|
}
|