Previous and Next episode number is taken from array

If there is episode "skips" in database now should work with them too.
This commit is contained in:
Jarmo Riikonen 2018-07-06 21:24:11 +03:00
parent 7d2f93f344
commit bd65be8ee6
2 changed files with 12 additions and 9 deletions

View File

@ -33,11 +33,14 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
}
episode := animeEpisodes.Find(episodeNumber)
episode, _ := animeEpisodes.Find(episodeNumber)
if episode == nil {
return ctx.Error(http.StatusNotFound, "Anime episode not found", nil)
}
return ctx.HTML(components.AnimeEpisode(anime, episode, user))
_, previousIndex := animeEpisodes.Find(episodeNumber - 1)
_, nextIndex := animeEpisodes.Find(episodeNumber + 1)
return ctx.HTML(components.AnimeEpisode(anime, episode, user, previousIndex, nextIndex))
}

View File

@ -1,4 +1,4 @@
component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, user *arn.User)
component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, user *arn.User, previousIndex int, nextIndex int)
h1
a(href=anime.Link())= anime.Title.ByUser(user)
@ -8,13 +8,13 @@ component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, user *arn.Us
h3.episode-view-number= "Episode " + strconv.Itoa(episode.Number)
if episode.Number > anime.Episodes().Items[0].Number
a.button(href=anime.Link() + "/episode/" + strconv.Itoa(episode.Number - 1))
Icon("chevron-left")
//- if (previousIndex != -1)
//- a.button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[previousIndex].Number))
//- Icon("chevron-left")
if episode.Number < anime.Episodes().Items[len(anime.Episodes().Items) - 1].Number
a.button(href=anime.Link() + "/episode/" + strconv.Itoa(episode.Number + 1))
Icon("chevron-right")
//- if (nextIndex != -1)
//- a.button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[nextIndex].Number))
//- Icon("chevron-right")
if episode.Title.Japanese != ""
.episode-view-title