diff --git a/MALFunctions.go b/MALFunctions.go index 140a838..f19ea1e 100644 --- a/MALFunctions.go +++ b/MALFunctions.go @@ -55,10 +55,29 @@ func (a *App) GetMyAnimeList(count int) MALWatchlist { return malList } -func (a *App) MyAnimeListUpdate(anime MALAnime, update interface{}) MyListStatus { - //var body url.Values +func (a *App) MyAnimeListUpdate(anime MALAnime, update MALUploadStatus) MyListStatus { + if update.NumTimesRewatched >= 1 { + update.IsRewatching = true + } else { + update.IsRewatching = false + } + body := url.Values{} + body.Set("status", update.Status) + body.Set("is_rewatching", strconv.FormatBool(update.IsRewatching)) + body.Set("score", strconv.Itoa(update.Score)) + body.Set("num_watched_episodes", strconv.Itoa(update.NumWatchedEpisodes)) + body.Set("num_times_rewatched", strconv.Itoa(update.NumTimesRewatched)) + body.Set("comments", update.Comments) - return MyListStatus{} + malUrl := "https://api.myanimelist.net/v2/anime/" + strconv.Itoa(anime.Id) + "/my_list_status" + var status MyListStatus + respBody := MALHelper("PATCH", malUrl, body) + err := json.Unmarshal(respBody, &status) + if err != nil { + log.Printf("Failed to unmarshal json response, %s\n", err) + } + + return status } func (a *App) GetMyAnimeListAnime(id int) MALAnime { diff --git a/MALTypes.go b/MALTypes.go index 940676b..e5fb078 100644 --- a/MALTypes.go +++ b/MALTypes.go @@ -152,3 +152,12 @@ type MyListStatus struct { Comments string `json:"comments" ts_type:"comments"` UpdatedAt string `json:"updated_at" ts_type:"updatedAt"` } + +type MALUploadStatus struct { + Status string `json:"status"` + IsRewatching bool `json:"is_rewatching"` + Score int `json:"score"` + NumWatchedEpisodes int `json:"num_watched_episodes"` + NumTimesRewatched int `json:"num_times_rewatched"` + Comments string `json:"comments"` +} diff --git a/frontend/src/ChangeDataDialogue.svelte b/frontend/src/ChangeDataDialogue.svelte index e031604..3bae637 100644 --- a/frontend/src/ChangeDataDialogue.svelte +++ b/frontend/src/ChangeDataDialogue.svelte @@ -17,12 +17,12 @@ import type {SimklAnime} from "./simkl/types/simklTypes"; import { get } from 'svelte/store'; import { - AniListUpdateEntry, + AniListUpdateEntry, MyAnimeListUpdate, SimklSyncEpisodes, SimklSyncRating, SimklSyncStatus } from "../wailsjs/go/main/App"; - import type {MALAnime} from "./mal/types/MALTypes"; + import type {MALAnime, MALUploadStatus, MyListStatus} from "./mal/types/MALTypes"; import type {AniListUpdateVariables} from "./anilist/types/AniListTypes"; const simklWatch = get(simklWatchList); @@ -32,12 +32,14 @@ let simklAnimeIndex: number let currentMalAnime: MALAnime let simklAnime: SimklAnime | undefined = undefined + let submitting = writable(false) + let isSubmitting: boolean aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value) malLoggedIn.subscribe((value) => isMalLoggedIn = value) simklLoggedIn.subscribe((value) => isSimklLoggedIn = value) malAnime.subscribe((value) => currentMalAnime = value) - + submitting.subscribe((value) => isSubmitting = value) for (let i = 0; i < simklWatch.anime.length; i++) { if (Number(simklWatch.anime[i].show.ids.mal) === aniListAnime.data.MediaList.media.idMal) { @@ -252,6 +254,7 @@ } const submitData = async () => { + submitting.set(true) let body: AniListUpdateVariables = { mediaId: aniListAnime.data.MediaList.mediaId, progress: values.progress, @@ -274,6 +277,27 @@ console.log(value) }) + if(malLoggedIn) { + let body: MALUploadStatus = { + status: values.status.mal, + is_rewatching: false, + score: values.score, + num_watched_episodes: values.progress, + num_times_rewatched: values.repeat, + comments: values.notes + } + + await MyAnimeListUpdate(currentMalAnime, body).then((value: MyListStatus) => { + currentMalAnime.my_list_status.status = value.status + currentMalAnime.my_list_status.is_rewatching = value.is_rewatching + currentMalAnime.my_list_status.score = value.score + currentMalAnime.my_list_status.num_episodes_watched = value.num_episodes_watched + currentMalAnime.my_list_status.num_times_rewatched = value.num_times_rewatched + currentMalAnime.my_list_status.comments = value.comments + + }) + } + if (simklLoggedIn) { if (simklAnime.watched_episodes_count !== values.progress) { await SimklSyncEpisodes(simklAnime, values.progress).then(() => { @@ -290,12 +314,13 @@ } if (simklAnime.status !== values.status.simkl) { - SimklSyncStatus(simklAnime, values.status.simkl).then(() => { + await SimklSyncStatus(simklAnime, values.status.simkl).then(() => { simklAnime.status = values.status.simkl simklWatch.anime[simklAnimeIndex].status = values.status.simkl }) } } + submitting.set(false) } @@ -456,11 +481,21 @@
-