diff --git a/api.go b/api.go index e72f4438..8e47506a 100644 --- a/api.go +++ b/api.go @@ -1,8 +1,12 @@ package main import ( + "errors" + "net/http" + "github.com/aerogo/aero" "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/utils" ) func init() { @@ -52,4 +56,34 @@ func init() { return ctx.JSON(thread) }) + + app.Get("/api/anime/:id/add", func(ctx *aero.Context) string { + animeID := ctx.Get("id") + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusBadRequest, "Not logged in", errors.New("User not logged in")) + } + + animeList := user.AnimeList() + + if animeList.Contains(animeID) { + return ctx.Error(http.StatusBadRequest, "Anime already added", errors.New("Anime has already been added")) + } + + newItem := arn.AnimeListItem{ + AnimeID: animeID, + Status: arn.AnimeListStatusPlanned, + } + + animeList.Items = append(animeList.Items, newItem) + + saveError := animeList.Save() + + if saveError != nil { + return ctx.Error(http.StatusInternalServerError, "Could not save anime list in database", saveError) + } + + return ctx.JSON(animeList) + }) } diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 98e403bf..6e43520f 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -18,6 +18,9 @@ component Anime(anime *arn.Anime) //- h3.anime-section-name.anime-summary-header Summary p.anime-summary= anime.Summary + .anime-actions + a.light-button.action-button(href="#") Add to collection + h3.anime-section-name Ratings .anime-rating-categories .anime-rating-category(title=toString(anime.Rating.Overall)) diff --git a/pages/anime/anime.scarlet b/pages/anime/anime.scarlet index 94fdbd7c..6870f9ec 100644 --- a/pages/anime/anime.scarlet +++ b/pages/anime/anime.scarlet @@ -41,6 +41,17 @@ margin-bottom 0.5rem color rgba(60, 60, 60, 0.5) !important +.anime-actions + horizontal + justify-content center + margin content-padding 0 + +> 900px + .anime-actions + position absolute + top 0 + right content-padding + .anime-rating-categories horizontal width 100% diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go index 2bb2cc2f..eb3914c7 100644 --- a/pages/dashboard/dashboard.go +++ b/pages/dashboard/dashboard.go @@ -29,5 +29,5 @@ func Get(ctx *aero.Context) string { return ctx.HTML(components.Dashboard(posts)) } - return ctx.HTML("ARN 4.0 is currently under construction.
Support the development") + return ctx.HTML("ARN 4.0 is currently under construction.
Support the development
Login via Google") } diff --git a/pages/profile/anime-list.scarlet b/pages/profile/anime-list.scarlet new file mode 100644 index 00000000..51d2591f --- /dev/null +++ b/pages/profile/anime-list.scarlet @@ -0,0 +1,15 @@ +.anime-list + horizontal + +.anime-list-item + padding 0.25rem + // padding calc(content-padding / 4) calc(content-padding / 2) + // margin 0.25rem 0 + // position relative + +.anime-list-item-image + width 55px !important + border-radius 2px + // position absolute + // left 0 + // top 0 \ No newline at end of file diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 19d0c4b4..d55977f1 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -27,5 +27,7 @@ func Get(ctx *aero.Context) string { threads = threads[:maxPosts] } - return ctx.HTML(components.Profile(viewUser, user, threads)) + animeList := viewUser.AnimeList() + + return ctx.HTML(components.Profile(viewUser, user, animeList, threads)) } diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 2ed5a69e..0b004b5a 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -1,4 +1,4 @@ -component Profile(viewUser *arn.User, user *arn.User, threads []*arn.Thread) +component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, threads []*arn.Thread) .profile img.profile-cover(src=viewUser.CoverImageURL()) @@ -49,6 +49,14 @@ component Profile(viewUser *arn.User, user *arn.User, threads []*arn.Thread) //- a.light-button(href="#") Anime //- a.light-button(href="#") Forum + .profile-category + h3 Anime + + .anime-list + each item in animeList.Items + a.anime-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.Canonical + " (" + toString(item.Episode) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")") + img.anime-cover-image.anime-list-item-image(src=item.Anime().Image.Tiny, alt=item.Anime().Title.Canonical) + .profile-category h3 Forum diff --git a/pages/profile/profile.scarlet b/pages/profile/profile.scarlet index dc3c550f..bea4d019 100644 --- a/pages/profile/profile.scarlet +++ b/pages/profile/profile.scarlet @@ -80,4 +80,4 @@ animation cover-animation // Categories .profile-category - // padding content-padding \ No newline at end of file + margin-bottom content-padding \ No newline at end of file diff --git a/styles/content.scarlet b/styles/content.scarlet index 2062384e..b881cd03 100644 --- a/styles/content.scarlet +++ b/styles/content.scarlet @@ -2,4 +2,5 @@ vertical padding content-padding padding-top content-padding-top - line-height 1.7em \ No newline at end of file + line-height 1.7em + position relative \ No newline at end of file diff --git a/styles/light-button.scarlet b/styles/light-button.scarlet index dc5e46d7..d6c5fc92 100644 --- a/styles/light-button.scarlet +++ b/styles/light-button.scarlet @@ -1,13 +1,18 @@ .light-button-group horizontal-wrap justify-content flex-start - font-size 0.9rem .light-button display inline-block padding 0.5rem 1rem border-radius 3px + font-size 0.9rem :hover color white !important - background-color link-hover-color \ No newline at end of file + background-color link-hover-color + +.action-button + ui-element + font-size 1rem + text-align center \ No newline at end of file