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" "log"
"net/http" "net/http"
"reflect" "reflect"
"slices"
"strconv" "strconv"
) )
@ -132,6 +133,8 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime {
anime.WatchedEpisodesCount = progress anime.WatchedEpisodesCount = progress
WatchListUpdate(anime)
return anime return anime
} }
@ -187,6 +190,8 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
anime.UserRating = rating anime.UserRating = rating
WatchListUpdate(anime)
return anime return anime
} }
@ -227,6 +232,8 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime {
anime.Status = status anime.Status = status
WatchListUpdate(anime)
return anime return anime
} }
@ -291,7 +298,9 @@ func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime {
func (a *App) SimklSyncRemove(anime SimklAnime) bool { func (a *App) SimklSyncRemove(anime SimklAnime) bool {
url := "https://api.simkl.com/sync/history/remove" url := "https://api.simkl.com/sync/history/remove"
var show = SimklShowStatus{ var showArray []SimklShowStatus
var singleShow = SimklShowStatus{
Title: anime.Show.Title, Title: anime.Show.Title,
Ids: Ids{ Ids: Ids{
Simkl: anime.Show.Ids.Simkl, 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) respBody := SimklHelper("POST", url, show)
var success SimklDeleteType var success SimklDeleteType
@ -310,8 +327,27 @@ func (a *App) SimklSyncRemove(anime SimklAnime) bool {
} }
if success.Deleted.Shows >= 1 { 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 return true
} else { } else {
return false 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 () => { const deleteEntries = async () => {
submitting.set(true) submitting.set(true)
if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) await AniListDeleteEntry(currentAniListAnime.data.MediaList.id) if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) {
if (malLoggedIn && currentMalAnime.id !== 0) await DeleteMyAnimeListEntry(currentMalAnime.id) await AniListDeleteEntry(currentAniListAnime.data.MediaList.id)
if (simklLoggedIn && currentSimklAnime.show.ids.simkl !== 0) await SimklSyncRemove(currentSimklAnime) 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) submitting.set(false)
submitSuccess.set(true) submitSuccess.set(true)
setTimeout(() => submitSuccess.set(false), 2000) setTimeout(() => submitSuccess.set(false), 2000)