diff --git a/pages/animelist/delete.go b/pages/animelist/delete.go new file mode 100644 index 00000000..602c95bc --- /dev/null +++ b/pages/animelist/delete.go @@ -0,0 +1,36 @@ +package animelist + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// DeleteConfirmation shows the confirmation page before deleting an anime list. +func DeleteConfirmation(ctx aero.Context) error { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusUnauthorized, "Not logged in") + } + + return ctx.HTML(components.DeleteAnimeList(user)) +} + +// Delete deletes your entire anime list. +func Delete(ctx aero.Context) error { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusUnauthorized, "Not logged in") + } + + animeList := user.AnimeList() + animeList.Lock() + animeList.Items = nil + animeList.Unlock() + + return ctx.String("ok") +} diff --git a/pages/animelist/delete.pixy b/pages/animelist/delete.pixy new file mode 100644 index 00000000..46c8a408 --- /dev/null +++ b/pages/animelist/delete.pixy @@ -0,0 +1,9 @@ +component DeleteAnimeList(user *arn.User) + h1.mountable Delete your anime list + + p.text-center.mountable This will delete your entire anime list. Are you sure you want to proceed? + + .buttons + button.action.mountable(data-action="deleteAnimeList", data-trigger="click", data-return-path="/+" + user.Nick + "/animelist/watching") + Icon("trash") + span Yes, delete my anime list. \ No newline at end of file diff --git a/pages/index/apiroutes/apiroutes.go b/pages/index/apiroutes/apiroutes.go index 0b9f40cb..530ca496 100644 --- a/pages/index/apiroutes/apiroutes.go +++ b/pages/index/apiroutes/apiroutes.go @@ -6,6 +6,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/pages/animeimport" + "github.com/animenotifier/notify.moe/pages/animelist" "github.com/animenotifier/notify.moe/pages/apiview" "github.com/animenotifier/notify.moe/pages/apiview/apidocs" "github.com/animenotifier/notify.moe/pages/character" @@ -57,6 +58,9 @@ func Register(app *aero.Application) { // SoundTrack app.Post("/api/soundtrack/:id/download", soundtrack.Download) + // AnimeList + app.Post("/api/delete/animelist", animelist.Delete) + // Upload app.Post("/api/upload/user/image", upload.UserImage) app.Post("/api/upload/user/cover", upload.UserCover) diff --git a/pages/index/userroutes/userroutes.go b/pages/index/userroutes/userroutes.go index e46d9095..2b2ab28b 100644 --- a/pages/index/userroutes/userroutes.go +++ b/pages/index/userroutes/userroutes.go @@ -49,6 +49,9 @@ func Register(app *aero.Application) { page.Get(app, "/animelist/hold", animelist.Redirect) page.Get(app, "/animelist/dropped", animelist.Redirect) + // Delete + page.Get(app, "/animelist/delete", animelist.DeleteConfirmation) + // Compare page.Get(app, "/compare/animelist/:nick-1/:nick-2", compare.AnimeList) diff --git a/pages/settings/style.pixy b/pages/settings/style.pixy index 7f366fda..8e551e74 100644 --- a/pages/settings/style.pixy +++ b/pages/settings/style.pixy @@ -36,6 +36,12 @@ component SettingsStyle(user *arn.User) option(value="airing date") Airing date ⮞ Rating ⮞ Title option(value="rating") Rating ⮞ Title option(value="title") Title + + .widget-section + label Delete: + a.button(href="/animelist/delete") + Icon("trash") + span Delete my anime list if arn.IsDevelopment() .widget.mountable(data-api="/api/settings/" + user.ID) diff --git a/scripts/Actions/AnimeList.ts b/scripts/Actions/AnimeList.ts index fb65d82e..ba879ffe 100644 --- a/scripts/Actions/AnimeList.ts +++ b/scripts/Actions/AnimeList.ts @@ -33,7 +33,6 @@ export async function removeAnimeFromCollection(arn: AnimeNotifier, button: HTML } button.textContent = "Removing..." - let {animeId, nick} = button.dataset if(!animeId || !nick) { @@ -50,4 +49,27 @@ export async function removeAnimeFromCollection(arn: AnimeNotifier, button: HTML } catch(err) { arn.statusMessage.showError(err) } -} \ No newline at end of file +} + +// Delete anime list +export async function deleteAnimeList(arn: AnimeNotifier, button: HTMLElement) { + if(!confirm("Last confirmation: Are you sure you want to delete your entire anime list?")) { + return + } + + button.textContent = "Deleting..." + let {returnPath} = button.dataset + + if(!returnPath) { + console.error("Button without data-return-path:", button) + return + } + + try { + await arn.post("/api/delete/animelist") + await arn.app.load(returnPath) + arn.statusMessage.showInfo("Your anime list has been deleted.") + } catch(err) { + arn.statusMessage.showError(err) + } +}