updated table when entries are deleted and fixed simkl watchlist

This commit is contained in:
John O'Keefe 2024-09-18 15:06:35 -04:00
parent 77dc48fcf2
commit 572366eb91
2 changed files with 82 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"log"
"net/http"
"reflect"
"slices"
"strconv"
)
@ -132,6 +133,8 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime {
anime.WatchedEpisodesCount = progress
WatchListUpdate(anime)
return anime
}
@ -187,6 +190,8 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
anime.UserRating = rating
WatchListUpdate(anime)
return anime
}
@ -227,6 +232,8 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime {
anime.Status = status
WatchListUpdate(anime)
return anime
}
@ -291,7 +298,9 @@ func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime {
func (a *App) SimklSyncRemove(anime SimklAnime) bool {
url := "https://api.simkl.com/sync/history/remove"
var show = SimklShowStatus{
var showArray []SimklShowStatus
var singleShow = SimklShowStatus{
Title: anime.Show.Title,
Ids: Ids{
Simkl: anime.Show.Ids.Simkl,
@ -300,6 +309,14 @@ func (a *App) SimklSyncRemove(anime SimklAnime) bool {
},
}
showArray = append(showArray, singleShow)
show := struct {
Shows []SimklShowStatus `json:"shows"`
}{
Shows: showArray,
}
respBody := SimklHelper("POST", url, show)
var success SimklDeleteType
@ -310,8 +327,27 @@ func (a *App) SimklSyncRemove(anime SimklAnime) bool {
}
if success.Deleted.Shows >= 1 {
for i, simklAnime := range SimklWatchList.Anime {
if simklAnime.Show.Ids.Simkl == anime.Show.Ids.Simkl {
SimklWatchList.Anime = slices.Delete(SimklWatchList.Anime, i, i+1)
}
}
return true
} else {
return false
}
}
func WatchListUpdate(anime SimklAnime) {
updated := false
for i, simklAnime := range SimklWatchList.Anime {
if simklAnime.Show.Ids.Simkl == anime.Show.Ids.Simkl {
SimklWatchList.Anime[i] = anime
updated = true
}
}
if !updated {
SimklWatchList.Anime = append(SimklWatchList.Anime, anime)
}
return
}

View File

@ -290,9 +290,51 @@
const deleteEntries = async () => {
submitting.set(true)
if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) await AniListDeleteEntry(currentAniListAnime.data.MediaList.id)
if (malLoggedIn && currentMalAnime.id !== 0) await DeleteMyAnimeListEntry(currentMalAnime.id)
if (simklLoggedIn && currentSimklAnime.show.ids.simkl !== 0) await SimklSyncRemove(currentSimklAnime)
if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) {
await AniListDeleteEntry(currentAniListAnime.data.MediaList.id)
AddAnimeServiceToTable({
id: currentAniListAnime.data.MediaList.mediaId,
title,
service: "AniList",
progress: 0,
status: "",
startedAt: "",
completedAt: "",
score: 0,
repeat: 0,
notes: "",
})
}
if (malLoggedIn && currentMalAnime.id !== 0) {
await DeleteMyAnimeListEntry(currentMalAnime.id)
AddAnimeServiceToTable({
id: currentMalAnime.id,
title: currentMalAnime.title,
service: "MyAnimeList",
progress: 0,
status: "",
startedAt: "",
completedAt: "",
score: 0,
repeat: 0,
notes: "",
})
}
if (simklLoggedIn && currentSimklAnime.show.ids.simkl !== 0) {
await SimklSyncRemove(currentSimklAnime)
AddAnimeServiceToTable({
id: currentSimklAnime.show.ids.simkl,
title: currentSimklAnime.show.title,
service: "Simkl",
progress: 0,
status: "",
startedAt: "",
completedAt: "",
score: 0,
repeat: 0,
notes: "",
})
}
submitting.set(false)
submitSuccess.set(true)
setTimeout(() => submitSuccess.set(false), 2000)