From bd65be8ee66e78b9bdb6c54fc26b34625a6aeb30 Mon Sep 17 00:00:00 2001 From: Jarmo Riikonen Date: Fri, 6 Jul 2018 21:24:11 +0300 Subject: [PATCH] Previous and Next episode number is taken from array If there is episode "skips" in database now should work with them too. --- pages/episode/episode.go | 7 +++++-- pages/episode/episode.pixy | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pages/episode/episode.go b/pages/episode/episode.go index afb6094c..aacc4001 100644 --- a/pages/episode/episode.go +++ b/pages/episode/episode.go @@ -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)) } diff --git a/pages/episode/episode.pixy b/pages/episode/episode.pixy index fdfc3055..3a7bf544 100644 --- a/pages/episode/episode.pixy +++ b/pages/episode/episode.pixy @@ -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