diff --git a/main.go b/main.go index d519efce..83e5dd83 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,8 @@ import ( "github.com/animenotifier/notify.moe/pages/explore" "github.com/animenotifier/notify.moe/pages/forum" "github.com/animenotifier/notify.moe/pages/forums" + "github.com/animenotifier/notify.moe/pages/listimport" + "github.com/animenotifier/notify.moe/pages/listimport/listimportanilist" "github.com/animenotifier/notify.moe/pages/login" "github.com/animenotifier/notify.moe/pages/music" "github.com/animenotifier/notify.moe/pages/newsoundtrack" @@ -79,6 +81,8 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/new/soundtrack", newsoundtrack.Get) app.Ajax("/settings", settings.Get) app.Ajax("/music", music.Get) + app.Ajax("/import", listimport.Get) + app.Ajax("/import/anilist/animelist", listimportanilist.Get) app.Ajax("/admin", admin.Get) app.Ajax("/search", search.Get) app.Ajax("/search/:term", search.Get) diff --git a/pages/listimport/listimport.go b/pages/listimport/listimport.go new file mode 100644 index 00000000..8956baf7 --- /dev/null +++ b/pages/listimport/listimport.go @@ -0,0 +1,20 @@ +package listimport + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get ... +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusBadRequest, "Not logged in", nil) + } + + return ctx.HTML(components.ImportLists(user)) +} diff --git a/pages/listimport/listimport.pixy b/pages/listimport/listimport.pixy new file mode 100644 index 00000000..3a8e7d57 --- /dev/null +++ b/pages/listimport/listimport.pixy @@ -0,0 +1,8 @@ +component ImportLists(user *arn.User) + .buttons + if user.Accounts.AniList.Nick != "" + a.button.mountable.ajax(href="/import/anilist/animelist") + Icon("refresh") + span Import AniList Anime List + else + p No imports available. \ No newline at end of file diff --git a/pages/listimport/listimportanilist/anilist.go b/pages/listimport/listimportanilist/anilist.go new file mode 100644 index 00000000..b1601214 --- /dev/null +++ b/pages/listimport/listimportanilist/anilist.go @@ -0,0 +1,62 @@ +package listimportanilist + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get ... +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusBadRequest, "Not logged in", nil) + } + + authErr := arn.AniList.Authorize() + + if authErr != nil { + return ctx.Error(http.StatusBadRequest, "Couldn't authorize the Anime Notifier app on AniList", authErr) + } + + allAnime, allErr := arn.AllAnime() + + if allErr != nil { + return ctx.Error(http.StatusBadRequest, "Couldn't load notify.moe list of all anime", allErr) + } + + animeList, err := arn.AniList.GetAnimeList(user) + + if err != nil { + return ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from AniList", err) + } + + matches := []*arn.AniListMatch{} + + matches = importList(matches, allAnime, animeList.Lists.Watching) + matches = importList(matches, allAnime, animeList.Lists.Completed) + matches = importList(matches, allAnime, animeList.Lists.PlanToWatch) + matches = importList(matches, allAnime, animeList.Lists.OnHold) + matches = importList(matches, allAnime, animeList.Lists.Dropped) + + for _, list := range animeList.CustomLists { + matches = importList(matches, allAnime, list) + } + + return ctx.HTML(components.ImportAnilist(user, matches)) +} + +func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, animeListItems []*arn.AniListAnimeListItem) []*arn.AniListMatch { + for _, item := range animeListItems { + matches = append(matches, &arn.AniListMatch{ + AniListAnime: item.Anime, + ARNAnime: arn.FindAniListAnime(item.Anime, allAnime), + }) + } + + return matches +} diff --git a/pages/listimport/listimportanilist/anilist.pixy b/pages/listimport/listimportanilist/anilist.pixy new file mode 100644 index 00000000..b9b57834 --- /dev/null +++ b/pages/listimport/listimportanilist/anilist.pixy @@ -0,0 +1,23 @@ +component ImportAnilist(user *arn.User, matches []*arn.AniListMatch) + h2= "Import: anilist.co" + + table + thead + tr + th anilist.co + th notify.moe + tbody + each match in matches + tr + td + a(href=match.AniListAnime.Link(), target="_blank", rel="noopener")= match.AniListAnime.TitleRomaji + td + if match.ARNAnime == nil + span.import-error Not found on notify.moe + else + a(href=match.ARNAnime.Link(), target="_blank", rel="noopener")= match.ARNAnime.Title.Canonical + + .buttons + .button.mountable.action(data-action="soon", data-trigger="click") + Icon("refresh") + span Import \ No newline at end of file diff --git a/pages/settings/settings.pixy b/pages/settings/settings.pixy index 5897ec3b..42a6b118 100644 --- a/pages/settings/settings.pixy +++ b/pages/settings/settings.pixy @@ -48,6 +48,13 @@ component Settings(user *arn.User) Icon("circle-o") span Not connected + + .widget.mountable + h3.widget-title + Icon("refresh") + span Import + + ImportLists(user) //- .widget.mountable(data-api="/api/settings/" + user.ID) //- h3.widget-title diff --git a/scripts/Actions.ts b/scripts/Actions.ts index f56e96e3..eaf3e908 100644 --- a/scripts/Actions.ts +++ b/scripts/Actions.ts @@ -73,6 +73,11 @@ export function load(arn: AnimeNotifier, element: HTMLElement) { arn.app.load(url) } +// Soon +export function soon() { + alert("Coming Soon™") +} + // Diff export function diff(arn: AnimeNotifier, element: HTMLElement) { let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")