diff --git a/api/stream.go b/api/stream.go index 9058a25cf..6f2ee9cb0 100644 --- a/api/stream.go +++ b/api/stream.go @@ -359,26 +359,44 @@ func (r streamRoutes) getStream(c *gin.Context) { func (r streamRoutes) getStreamPlaylist(c *gin.Context) { type StreamPlaylistEntry struct { - StreamID uint `json:"streamId"` - CourseSlug string `json:"courseSlug"` - StreamName string `json:"streamName"` - LiveNow bool `json:"liveNow"` - Watched bool `json:"watched"` - Start time.Time `json:"start"` - CreatedAt time.Time `json:"createdAt"` + StreamID uint `json:"streamId"` + CourseSlug string `json:"courseSlug"` + StreamName string `json:"streamName"` + LiveNow bool `json:"liveNow"` + Watched bool `json:"watched"` + Start time.Time `json:"start"` + StreamProgress model.StreamProgress `json:"streamProgress"` + CreatedAt time.Time `json:"createdAt"` } tumLiveContext := c.MustGet("TUMLiveContext").(tools.TUMLiveContext) + + // Create mapping of stream id to progress for all progresses of user + var streamIDs []uint + for _, stream := range tumLiveContext.Course.Streams { + streamIDs = append(streamIDs, stream.ID) + } + streamProgresses := make(map[uint]model.StreamProgress) + res, err := r.LoadProgress(tumLiveContext.User.ID, streamIDs) + if err != nil { + logger.Error("Couldn't load progresses", "err", err) + } else { + for _, progress := range res { + streamProgresses[progress.StreamID] = progress + } + } + var result []StreamPlaylistEntry for _, stream := range tumLiveContext.Course.Streams { result = append(result, StreamPlaylistEntry{ - StreamID: stream.ID, - CourseSlug: tumLiveContext.Course.Slug, - StreamName: stream.GetName(), - LiveNow: stream.LiveNow, - Watched: stream.Watched, - Start: stream.Start, - CreatedAt: stream.CreatedAt, + StreamID: stream.ID, + CourseSlug: tumLiveContext.Course.Slug, + StreamName: stream.GetName(), + LiveNow: stream.LiveNow, + Watched: stream.Watched, + Start: stream.Start, + StreamProgress: streamProgresses[stream.ID], + CreatedAt: stream.CreatedAt, }) } diff --git a/web/assets/css/watch.css b/web/assets/css/watch.css index 05b7ee1de..1e94242f0 100644 --- a/web/assets/css/watch.css +++ b/web/assets/css/watch.css @@ -1,5 +1,5 @@ .playlist-thumbnail { - @apply bg-gray-100 dark:bg-gray-800 rounded-lg mr-4 bg-cover transition-all duration-500 hover:shadow-xl dark:shadow-gray-900/75; + @apply relative bg-gray-100 dark:bg-gray-800 rounded-lg mr-4 bg-cover transition-all duration-500 hover:shadow-xl dark:shadow-gray-900/75; } /* Rendered, but not visible on the screen. Enables layout calculations. */ @@ -10,4 +10,4 @@ width: 100%; height: auto; overflow: visible; -} +} \ No newline at end of file diff --git a/web/template/partial/stream/playlist.gohtml b/web/template/partial/stream/playlist.gohtml index 065bd4d8e..001114dac 100644 --- a/web/template/partial/stream/playlist.gohtml +++ b/web/template/partial/stream/playlist.gohtml @@ -32,6 +32,15 @@
+
+
+ +
+

diff --git a/web/ts/data-store/stream-playlist.ts b/web/ts/data-store/stream-playlist.ts index 493744971..668715f33 100644 --- a/web/ts/data-store/stream-playlist.ts +++ b/web/ts/data-store/stream-playlist.ts @@ -1,15 +1,23 @@ import { Delete, getData, postData, putData, Time } from "../global"; import { StreamableMapProvider } from "./provider"; +import { Progress } from "../api/progress"; export class StreamPlaylistProvider extends StreamableMapProvider { protected async fetcher(streamId: number): Promise { const result = await StreamPlaylist.get(streamId); - return result - .map((e) => { - e.startDate = new Date(e.start); - return e; - }) - .sort((a, b) => (a.startDate < b.startDate ? -1 : 1)); + return ( + result + .map((e) => { + e.startDate = new Date(e.start); + return e; + }) + // Convert stream progress to Typescript object + .map((e) => { + e.progress = new Progress(JSON.parse(JSON.stringify(e.streamProgress))); + return e; + }) + .sort((a, b) => (a.startDate < b.startDate ? -1 : 1)) + ); } } @@ -20,10 +28,12 @@ export type StreamPlaylistEntry = { liveNow: boolean; watched: boolean; start: string; + streamProgress: string; createdAt: string; - // Client Generated + // Client generated to package data with Typescript constructors startDate: Date; + progress: Progress; }; const StreamPlaylist = {