From 1b08918d8e7164a1b10b00f944b46078e3df8ed5 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 11 Aug 2024 19:42:52 -0400 Subject: [PATCH] added ability to change simkl status --- SimklFunctions.go | 32 +++++++++++++++++++ SimklTypes.go | 6 ++++ frontend/src/ChangeDataDialogue.svelte | 43 ++++++++++++++++++++------ frontend/wailsjs/go/main/App.d.ts | 2 ++ frontend/wailsjs/go/main/App.js | 4 +++ 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/SimklFunctions.go b/SimklFunctions.go index 75d6ec9..b43721b 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -160,3 +160,35 @@ func (a *App) SimklSyncRating(anime Anime, rating int) interface{} { return success } + +func (a *App) SimklSyncStatus(anime Anime, status string) interface{} { + url := "https://api.simkl.com/sync/add-to-list" + var show = SimklShowStatus{ + Title: anime.Show.Title, + Ids: Ids{ + Simkl: anime.Show.Ids.Simkl, + Mal: anime.Show.Ids.Mal, + Anilist: anime.Show.Ids.AniList, + }, + To: status, + } + + var shows []SimklShowStatus + + shows = append(shows, show) + + simklSync := struct { + Shows []SimklShowStatus `json:"shows" ts_type:"shows"` + }{shows} + + respBody := SimklPostHelper(url, simklSync) + + var success interface{} + + err := json.Unmarshal(respBody, &success) + if err != nil { + log.Printf("Failed at unmarshal, %s\n", err) + } + + return success +} diff --git a/SimklTypes.go b/SimklTypes.go index c5ab0a5..25a549e 100644 --- a/SimklTypes.go +++ b/SimklTypes.go @@ -99,3 +99,9 @@ type ShowWithoutRating struct { Title string `json:"title" ts_type:"title"` Ids `json:"ids" ts_type:"ids"` } + +type SimklShowStatus struct { + Title string `json:"title" ts_type:"title"` + Ids `json:"ids" ts_type:"ids"` + To string `json:"to" ts_type:"to"` +} diff --git a/frontend/src/ChangeDataDialogue.svelte b/frontend/src/ChangeDataDialogue.svelte index e2d9aee..bf0fc1b 100644 --- a/frontend/src/ChangeDataDialogue.svelte +++ b/frontend/src/ChangeDataDialogue.svelte @@ -14,7 +14,7 @@ import { writable } from 'svelte/store'; import type {SimklAnime} from "./simkl/types/simklTypes"; import { get } from 'svelte/store'; - import {AniListUpdateEntry, SimklSyncEpisodes, SimklSyncRating} from "../wailsjs/go/main/App"; + import {AniListUpdateEntry, SimklSyncEpisodes, SimklSyncRating, SimklSyncStatus} from "../wailsjs/go/main/App"; const simklWatch = get(simklWatchList); let isAniListLoggedIn: boolean @@ -32,6 +32,25 @@ } } + type statusOption = { + id: number, + aniList: string, + simkl: string, + } + + const statusOptions: statusOption[] = [ + { id: 0, aniList: "CURRENT", simkl: "watching"}, + { id: 1, aniList: "PLANNING", simkl: "plantowatch"}, + { id: 2, aniList: "COMPLETED", simkl: "completed"}, + { id: 3, aniList: "DROPPED", simkl: "dropped"}, + { id: 4, aniList: "PAUSED", simkl: "hold"}, + { id: 5, aniList: "REPEATING", simkl: "watching"} + ] + + let startingAnilistStatusOption: statusOption + + startingAnilistStatusOption = statusOptions.filter(option => aniListAnime.data.MediaList.status === option.aniList)[0] + let items = []; if(isAniListLoggedIn) { @@ -141,7 +160,7 @@ let values = { progress: aniListAnime.data.MediaList.progress, - status: aniListAnime.data.MediaList.status, + status: startingAnilistStatusOption, startedAt: { year: aniListAnime.data.MediaList.startedAt.year, month: aniListAnime.data.MediaList.startedAt.month, @@ -197,7 +216,7 @@ await AniListUpdateEntry( aniListAnime.data.MediaList.mediaId, values.progress, - values.status, + values.status.aniList, values.score, values.repeat, values.notes, @@ -227,6 +246,14 @@ simklWatch.anime[simklAnimeIndex].user_rating = values.score }) } + + if (simklAnime.status !== values.status.simkl) { + SimklSyncStatus(simklAnime, values.status.simkl).then(value => { + console.log(value) + simklAnime.status = values.status.simkl + simklWatch.anime[simklAnimeIndex].status = values.status.simkl + }) + } } } @@ -267,13 +294,9 @@ dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" bind:value={values.status} > - - - - - - - + {#each statusOptions as option} + + {/each} diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index a20be4f..aaf54fa 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -27,3 +27,5 @@ export function SimklLogin():Promise; export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise; export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise; + +export function SimklSyncStatus(arg1:main.Anime,arg2:string):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 7aed297..d4a0566 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -53,3 +53,7 @@ export function SimklSyncEpisodes(arg1, arg2) { export function SimklSyncRating(arg1, arg2) { return window['go']['main']['App']['SimklSyncRating'](arg1, arg2); } + +export function SimklSyncStatus(arg1, arg2) { + return window['go']['main']['App']['SimklSyncStatus'](arg1, arg2); +}