Skip to content

Commit

Permalink
Adding a Favorites list section
Browse files Browse the repository at this point in the history
  • Loading branch information
boggydigital committed Jul 1, 2024
1 parent 5efefbd commit f960f19
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 60 deletions.
132 changes: 72 additions & 60 deletions rest/templates/list.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -47,66 +47,78 @@

<section class="watchlist_container">

{{if .Continue}}
<details open>
<summary>{{template "plus_icon"}}<h1>Continue</h1></summary>
<ul class="videos resp-grid">
{{range .Continue}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .Videos}}
<details>
<summary>{{template "plus_icon"}}<h1>Videos</h1></summary>
<ul class="videos resp-grid">
{{range .Videos}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .Playlists}}
<details>
<summary>{{template "plus_icon"}}<h1>Playlists</h1></summary>
<section class="playlists_container">
{{$playlists := .Playlists}}
{{range $ii, $playlistSection := .PlaylistsOrder}}
<details {{if eq $ii 0}}open{{end}}>
<summary class="h2 {{$playlistSection}}">{{template "plus_icon"}}<h2>{{$playlistSection}}</h2></summary>
<ul class='playlists resp-grid'>
{{$playlist := index $playlists $playlistSection}}
{{range $playlist}}
{{template "playlist" .}}
{{end}}
</ul>
</details>
{{end}}
</section>
</details>

{{end}}

{{if .Downloads}}
<details>
<summary>{{template "plus_icon"}}<h1>Downloads</h1></summary>
<ul class="videos resp-grid">
{{range .Downloads}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .HasHistory}}
<details open>
<summary>{{template "plus_icon"}}<h1>History</h1></summary>
<a class='link' href='/history'>Check out your watch history</a>
</details>
{{end}}
{{if .Continue}}
<details open>
<summary>{{template "plus_icon"}}<h1>Continue</h1></summary>
<ul class="videos resp-grid">
{{range .Continue}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .Videos}}
<details>
<summary>{{template "plus_icon"}}<h1>Videos</h1></summary>
<ul class="videos resp-grid">
{{range .Videos}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .Playlists}}
<details>
<summary>{{template "plus_icon"}}<h1>Playlists</h1></summary>
<section class="playlists_container">
{{$playlists := .Playlists}}
{{range $ii, $playlistSection := .PlaylistsOrder}}
<details {{if eq $ii 0}}open{{end}}>
<summary class="h2 {{$playlistSection}}">{{template "plus_icon"}}
<h2>{{$playlistSection}}</h2></summary>
<ul class='playlists resp-grid'>
{{$playlist := index $playlists $playlistSection}}
{{range $playlist}}
{{template "playlist" .}}
{{end}}
</ul>
</details>
{{end}}
</section>
</details>

{{end}}

{{if .Downloads}}
<details>
<summary>{{template "plus_icon"}}<h1>Downloads</h1></summary>
<ul class="videos resp-grid">
{{range .Downloads}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .Favorites}}
<details>
<summary>{{template "plus_icon"}}<h1>Favorites</h1></summary>
<ul class="videos resp-grid">
{{range .Favorites}}
<li>{{template "video" .}}</li>
{{end}}
</ul>
</details>
{{end}}

{{if .HasHistory}}
<details open>
<summary>{{template "plus_icon"}}<h1>History</h1></summary>
<a class='link' href='/history'>Check out your watch history</a>
</details>
{{end}}

</section>

Expand Down
18 changes: 18 additions & 0 deletions rest/view_models/list_view_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ListViewModel struct {
Downloads []*VideoViewModel
PlaylistsOrder []string
Playlists map[string][]*PlaylistViewModel
Favorites []*VideoViewModel
HasHistory bool
}

Expand Down Expand Up @@ -52,6 +53,7 @@ func GetListViewModel(rdx kvas.ReadableRedux) (*ListViewModel, error) {
// videos is all downloaded videos that are not:
// - in history (ended)
// - in continue (have progress)
// - is favorite
// - in any auto-refreshing playlist
dcKeys := rdx.Keys(data.VideoDownloadCompletedProperty)
if len(dcKeys) > 0 {
Expand All @@ -66,6 +68,9 @@ func GetListViewModel(rdx kvas.ReadableRedux) (*ListViewModel, error) {
if rdx.HasKey(data.VideoProgressProperty, id) {
continue
}
if rdx.HasKey(data.VideoFavoriteProperty, id) {
continue
}

skip := false
for _, playlistId := range rdx.Keys(data.PlaylistAutoRefreshProperty) {
Expand Down Expand Up @@ -159,6 +164,19 @@ func GetListViewModel(rdx kvas.ReadableRedux) (*ListViewModel, error) {
}
}

fvKeys := rdx.Keys(data.VideoFavoriteProperty)
fvKeys, err = rdx.Sort(fvKeys, false, data.VideoTitleProperty)
if err != nil {
return nil, err
}

for _, id := range fvKeys {
lvm.Favorites = append(lvm.Favorites, GetVideoViewModel(id, rdx,
ShowPoster,
ShowDuration,
ShowPublishedDate))
}

lvm.HasHistory = len(rdx.Keys(data.VideoEndedDateProperty)) > 0

return lvm, nil
Expand Down

0 comments on commit f960f19

Please sign in to comment.