Refactor Sort UI

This commit is contained in:
James Mills 2020-03-27 21:50:19 +10:00
parent f4afd2eb6b
commit fd3f210a36
No known key found for this signature in database
GPG key ID: AC4C014F1440EBD6
3 changed files with 8 additions and 7 deletions

View file

@ -177,12 +177,13 @@ func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
if len(pl) > 0 { if len(pl) > 0 {
http.Redirect(w, r, fmt.Sprintf("/v/%s?%s", pl[0].ID, r.URL.RawQuery), 302) http.Redirect(w, r, fmt.Sprintf("/v/%s?%s", pl[0].ID, r.URL.RawQuery), 302)
} else { } else {
sort := strings.ToLower(r.URL.Query().Get("sort"))
ctx := &struct { ctx := &struct {
Sort string Sort string
Playing *media.Video Playing *media.Video
Playlist media.Playlist Playlist media.Playlist
}{ }{
Sort: "", Sort: sort,
Playing: &media.Video{ID: ""}, Playing: &media.Video{ID: ""},
Playlist: a.Library.Playlist(), Playlist: a.Library.Playlist(),
} }

View file

@ -23,9 +23,9 @@ func init() {
} }
file4 := &embedded.EmbeddedFile{ file4 := &embedded.EmbeddedFile{
Filename: "index.html", Filename: "index.html",
FileModTime: time.Unix(1585303713, 0), FileModTime: time.Unix(1585309729, 0),
Content: string("{{ define \"content\" }}\r\n{{ $playing := .Playing }}\r\n<div id=\"player\">\r\n {{ if $playing.ID }}\r\n <video id=\"video\" controls poster=\"/t/{{ $playing.ID}}\" src=\"/v/{{ $playing.ID }}.mp4\"></video>\r\n <h1>{{ $playing.Title }}</h1>\r\n <h2>{{ $playing.Views }} views • {{ $playing.Modified }}<br />{{ $playing.Size | bytes }}</h2>\r\n <p>{{ $playing.Description }}</p>\r\n {{ else }}\r\n <video id=\"video\" controls></video>\r\n {{ end }}\r\n</div>\r\n<div id=\"playlist\">\r\n <div class=\"nav\">\r\n <ul>\r\n <li><a {{ if eq $.Sort \"views\" }}class=\"active\"{{ end }}href=\"?sort=views\">Trending</a></li>\r\n <li><a {{ if eq $.Sort \"timestamp\" }}class=\"active\"{{ end }}href=\"?sort=timestamp\">Recent</a></li>\r\n </ul>\r\n </div>\r\n {{ range $m := .Playlist }}\r\n {{ if eq $m.ID $playing.ID }}\r\n <a href=\"/v/{{ $m.ID }}\" class=\"playing\">\r\n {{ else }}\r\n <a href=\"/v/{{ $m.ID }}\">\r\n {{ end }}\r\n <img src=\"/t/{{ $m.ID }}\">\r\n <div>\r\n <h1>{{ $m.Title }}</h1>\r\n <h2>{{ $m.Views }} views • {{ $m.Modified }}<br />{{ $m.Size | bytes }}</h2>\r\n </div>\r\n </a>\r\n {{ end }}\r\n</div>\r\n{{end}}\r\n"), Content: string("{{ define \"content\" }}\r\n{{ $playing := .Playing }}\r\n<div id=\"player\">\r\n {{ if $playing.ID }}\r\n <video id=\"video\" controls poster=\"/t/{{ $playing.ID}}\" src=\"/v/{{ $playing.ID }}.mp4\"></video>\r\n <h1>{{ $playing.Title }}</h1>\r\n <h2>{{ $playing.Views }} views • {{ $playing.Modified }}<br />{{ $playing.Size | bytes }}</h2>\r\n <p>{{ $playing.Description }}</p>\r\n {{ else }}\r\n <video id=\"video\" controls></video>\r\n {{ end }}\r\n</div>\r\n<div id=\"playlist\">\r\n <div class=\"nav\">\r\n <p>{{ $.Sort }}</p>\r\n <ul>\r\n <li><a {{ if or (eq $.Sort \"timestamp\") (eq $.Sort \"\") }}class=\"active\"{{ end }} href=\"?sort=timestamp\">Recent</a></li>\r\n <li><a {{ if eq $.Sort \"views\" }}class=\"active\"{{ end }} href=\"?sort=views\">Views</a></li>\r\n </ul>\r\n </div>\r\n {{ range $m := .Playlist }}\r\n {{ if eq $m.ID $playing.ID }}\r\n <a href=\"/v/{{ $m.ID }}\" class=\"playing\">\r\n {{ else }}\r\n <a href=\"/v/{{ $m.ID }}\">\r\n {{ end }}\r\n <img src=\"/t/{{ $m.ID }}\">\r\n <div>\r\n <h1>{{ $m.Title }}</h1>\r\n <h2>{{ $m.Views }} views • {{ $m.Modified }}<br />{{ $m.Size | bytes }}</h2>\r\n </div>\r\n </a>\r\n {{ end }}\r\n</div>\r\n{{end}}\r\n"),
} }
file5 := &embedded.EmbeddedFile{ file5 := &embedded.EmbeddedFile{
Filename: "upload.html", Filename: "upload.html",
@ -37,7 +37,7 @@ func init() {
// define dirs // define dirs
dir1 := &embedded.EmbeddedDir{ dir1 := &embedded.EmbeddedDir{
Filename: "", Filename: "",
DirModTime: time.Unix(1585307937, 0), DirModTime: time.Unix(1585309730, 0),
ChildFiles: []*embedded.EmbeddedFile{ ChildFiles: []*embedded.EmbeddedFile{
file2, // "base.html" file2, // "base.html"
file3, // "import.html" file3, // "import.html"
@ -53,7 +53,7 @@ func init() {
// register embeddedBox // register embeddedBox
embedded.RegisterEmbeddedBox(`../templates`, &embedded.EmbeddedBox{ embedded.RegisterEmbeddedBox(`../templates`, &embedded.EmbeddedBox{
Name: `../templates`, Name: `../templates`,
Time: time.Unix(1585307937, 0), Time: time.Unix(1585309730, 0),
Dirs: map[string]*embedded.EmbeddedDir{ Dirs: map[string]*embedded.EmbeddedDir{
"": dir1, "": dir1,
}, },

View file

@ -13,8 +13,8 @@
<div id="playlist"> <div id="playlist">
<div class="nav"> <div class="nav">
<ul> <ul>
<li><a {{ if eq $.Sort "views" }}class="active"{{ end }}href="?sort=views">Trending</a></li> <li><a {{ if or (eq $.Sort "timestamp") (eq $.Sort "") }}class="active"{{ end }} href="?sort=timestamp">Recent</a></li>
<li><a {{ if eq $.Sort "timestamp" }}class="active"{{ end }}href="?sort=timestamp">Recent</a></li> <li><a {{ if eq $.Sort "views" }}class="active"{{ end }} href="?sort=views">Views</a></li>
</ul> </ul>
</div> </div>
{{ range $m := .Playlist }} {{ range $m := .Playlist }}