Added anime list deletion

This commit is contained in:
Eduard Urbach 2019-08-29 14:08:32 +09:00
parent 1d6cdd3c9f
commit ede2c5dc75
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 82 additions and 2 deletions

36
pages/animelist/delete.go Normal file
View File

@ -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")
}

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)
}
}
}
// 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)
}
}