From bcd79ba2c55de3202f1e9b4b9b6070b36cfdb7db Mon Sep 17 00:00:00 2001 From: James Mills Date: Wed, 25 Mar 2020 23:02:04 +1000 Subject: Refactor UX of Trending vs. Recent video sorting --- app/app.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 6c56540..902b932 100644 --- a/app/app.go +++ b/app/app.go @@ -12,6 +12,7 @@ import ( "path" "path/filepath" "sort" + "strings" rice "github.com/GeertJohan/go.rice" "github.com/fsnotify/fsnotify" @@ -312,18 +313,24 @@ func (a *App) pageHandler(w http.ResponseWriter, r *http.Request) { video.Views = views } - if r.URL.Query().Get("trending") != "" { - log.Info("sorting by trending") + sort := strings.ToLower(r.URL.Query().Get("sort")) + switch sort { + case "views": media.By(media.SortByViews).Sort(playlist) - } else { + case "timestamp": media.By(media.SortByTimestamp).Sort(playlist) + default: + // By default the playlist is sorted by Timestamp + log.Warnf("invalid sort critiera: %s", sort) } w.Header().Set("Content-Type", "text/html; charset=utf-8") ctx := &struct { + Sort string Playing *media.Video Playlist media.Playlist }{ + Sort: sort, Playing: playing, Playlist: playlist, } -- cgit v1.2.3