From 572366eb91015eb9b0c2f3429ec55a367164503d Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 18 Sep 2024 15:06:35 -0400 Subject: [PATCH] updated table when entries are deleted and fixed simkl watchlist --- SimklFunctions.go | 38 ++++++++++++++++- frontend/src/helperComponents/Anime.svelte | 48 ++++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/SimklFunctions.go b/SimklFunctions.go index 1759ab6..ef5009e 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -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 +} diff --git a/frontend/src/helperComponents/Anime.svelte b/frontend/src/helperComponents/Anime.svelte index d1d81dd..edb85e6 100644 --- a/frontend/src/helperComponents/Anime.svelte +++ b/frontend/src/helperComponents/Anime.svelte @@ -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)