Added list import preview
This commit is contained in:
parent
4f6ffd969d
commit
7262f4db7b
4
main.go
4
main.go
@ -20,6 +20,8 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/pages/explore"
|
"github.com/animenotifier/notify.moe/pages/explore"
|
||||||
"github.com/animenotifier/notify.moe/pages/forum"
|
"github.com/animenotifier/notify.moe/pages/forum"
|
||||||
"github.com/animenotifier/notify.moe/pages/forums"
|
"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/login"
|
||||||
"github.com/animenotifier/notify.moe/pages/music"
|
"github.com/animenotifier/notify.moe/pages/music"
|
||||||
"github.com/animenotifier/notify.moe/pages/newsoundtrack"
|
"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("/new/soundtrack", newsoundtrack.Get)
|
||||||
app.Ajax("/settings", settings.Get)
|
app.Ajax("/settings", settings.Get)
|
||||||
app.Ajax("/music", music.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("/admin", admin.Get)
|
||||||
app.Ajax("/search", search.Get)
|
app.Ajax("/search", search.Get)
|
||||||
app.Ajax("/search/:term", search.Get)
|
app.Ajax("/search/:term", search.Get)
|
||||||
|
20
pages/listimport/listimport.go
Normal file
20
pages/listimport/listimport.go
Normal file
@ -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))
|
||||||
|
}
|
8
pages/listimport/listimport.pixy
Normal file
8
pages/listimport/listimport.pixy
Normal file
@ -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.
|
62
pages/listimport/listimportanilist/anilist.go
Normal file
62
pages/listimport/listimportanilist/anilist.go
Normal file
@ -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
|
||||||
|
}
|
23
pages/listimport/listimportanilist/anilist.pixy
Normal file
23
pages/listimport/listimportanilist/anilist.pixy
Normal file
@ -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
|
@ -48,6 +48,13 @@ component Settings(user *arn.User)
|
|||||||
|
|
||||||
Icon("circle-o")
|
Icon("circle-o")
|
||||||
span Not connected
|
span Not connected
|
||||||
|
|
||||||
|
.widget.mountable
|
||||||
|
h3.widget-title
|
||||||
|
Icon("refresh")
|
||||||
|
span Import
|
||||||
|
|
||||||
|
ImportLists(user)
|
||||||
|
|
||||||
//- .widget.mountable(data-api="/api/settings/" + user.ID)
|
//- .widget.mountable(data-api="/api/settings/" + user.ID)
|
||||||
//- h3.widget-title
|
//- h3.widget-title
|
||||||
|
@ -73,6 +73,11 @@ export function load(arn: AnimeNotifier, element: HTMLElement) {
|
|||||||
arn.app.load(url)
|
arn.app.load(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Soon
|
||||||
|
export function soon() {
|
||||||
|
alert("Coming Soon™")
|
||||||
|
}
|
||||||
|
|
||||||
// Diff
|
// Diff
|
||||||
export function diff(arn: AnimeNotifier, element: HTMLElement) {
|
export function diff(arn: AnimeNotifier, element: HTMLElement) {
|
||||||
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
||||||
|
Loading…
Reference in New Issue
Block a user