Compare commits

...

3 Commits

10 changed files with 157 additions and 67 deletions

View File

@ -160,3 +160,35 @@ func (a *App) SimklSyncRating(anime Anime, rating int) interface{} {
return success 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
}

View File

@ -99,3 +99,9 @@ type ShowWithoutRating struct {
Title string `json:"title" ts_type:"title"` Title string `json:"title" ts_type:"title"`
Ids `json:"ids" ts_type:"ids"` 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"`
}

2
app.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"github.com/wailsapp/wails/v2/pkg/runtime"
) )
// App struct // App struct
@ -18,4 +19,5 @@ func NewApp() *App {
// so we can call the runtime methods // so we can call the runtime methods
func (a *App) startup(ctx context.Context) { func (a *App) startup(ctx context.Context) {
a.ctx = ctx a.ctx = ctx
runtime.WindowMaximise(ctx)
} }

View File

@ -1,11 +1,17 @@
<script lang="ts"> <script lang="ts">
import { import {
anilistModal, anilistModal,
GetAniListSingleItemAndOpenModal,
title, title,
simklWatchList, simklWatchList,
aniListLoggedIn, aniListLoggedIn,
simklLoggedIn simklLoggedIn,
simklUser,
aniListUser,
aniListPrimary,
aniListWatchlist,
loginToAniList,
GetAniListSingleItemAndOpenModal,
loginToSimkl
} from "./GlobalVariablesAndHelperFunctions.svelte"; } from "./GlobalVariablesAndHelperFunctions.svelte";
import { import {
CheckIfAniListLoggedIn, CheckIfAniListLoggedIn,
@ -24,15 +30,22 @@
import {onMount} from "svelte"; import {onMount} from "svelte";
import type {SimklUser} from "./simkl/types/simklTypes"; import type {SimklUser} from "./simkl/types/simklTypes";
let aniListPrimary = true
let simklUser: SimklUser
let aniListUser: AniListUser
let aniListWatchlist: AniListCurrentUserWatchList
let isAniListLoggedIn: boolean let isAniListLoggedIn: boolean
let isSimklLoggedIn: boolean let isSimklLoggedIn: boolean
let currentSimklUser: SimklUser
let currentAniListUser: AniListUser
let isAniListPrimary: boolean
let aniListWatchListLoaded: AniListCurrentUserWatchList
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value) aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value) simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
simklUser.subscribe((value) => currentSimklUser = value)
aniListUser.subscribe((value) => currentAniListUser = value)
aniListPrimary.subscribe((value) => isAniListPrimary = value)
aniListWatchlist.subscribe((value) => aniListWatchListLoaded = value)
let page = 1 let page = 1
let perPage = 20 let perPage = 20
@ -42,10 +55,10 @@
await CheckIfAniListLoggedIn().then(result => { await CheckIfAniListLoggedIn().then(result => {
if (result) { if (result) {
GetAniListLoggedInUser().then(result => { GetAniListLoggedInUser().then(result => {
aniListUser = result aniListUser.set(result)
if (aniListPrimary) { if (isAniListPrimary) {
GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((result) => { GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((result) => {
aniListWatchlist = result aniListWatchlist.set(result)
aniListLoggedIn.set(true) aniListLoggedIn.set(true)
}) })
} else { } else {
@ -58,7 +71,7 @@
await CheckIfSimklLoggedIn().then(result => { await CheckIfSimklLoggedIn().then(result => {
if (result) { if (result) {
GetSimklLoggedInUser().then(result => { GetSimklLoggedInUser().then(result => {
simklUser = result simklUser.set(result)
SimklGetUserWatchlist().then(result => { SimklGetUserWatchlist().then(result => {
simklWatchList.set(result) simklWatchList.set(result)
simklLoggedIn.set(result) simklLoggedIn.set(result)
@ -67,57 +80,19 @@
} }
}) })
}) })
function loginToSimkl(): void {
GetSimklLoggedInUser().then(result => {
simklUser = result
simklLoggedIn.set(true)
})
}
function loginToAniList(): void {
GetAniListLoggedInUser().then(result => {
aniListUser = result
aniListLoggedIn.set(true)
if (aniListPrimary) {
GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then(result => aniListWatchlist = result)
}
})
}
// function anilistGetUserWatchlist(): void {
// GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((result) => {
// aniListWatchlist = result
// aniListLoggedIn.set(true)
// })
// }
//
// let count = 1;
//
// const decrement = () => {
// if (count > 0) {
// count--
// }
// }
//
// const increment = () => {
// count++
// }
</script> </script>
<Header/> <Header/>
<main> <main>
{#if isAniListLoggedIn} {#if isAniListLoggedIn}
<div>You are logged into AniList, {aniListUser.data.Viewer.name}!</div> <div>You are logged into AniList, {currentAniListUser.data.Viewer.name}!</div>
{:else} {:else}
<button class="btn" on:click={loginToAniList}>Login to AniList</button> <button class="btn" on:click={loginToAniList}>Login to AniList</button>
{/if} {/if}
{#if isSimklLoggedIn} {#if isSimklLoggedIn}
<div>You are logged into Simkl, {simklUser.user.name}</div> <div>You are logged into Simkl, {currentSimklUser.user.name}</div>
{:else} {:else}
<Button class="btn" on:click={loginToSimkl}>Login to Simkl</Button> <Button class="btn" on:click={loginToSimkl}>Login to Simkl</Button>
{/if} {/if}
@ -127,7 +102,7 @@
<h1 class="text-left text-xl font-bold mb-4">Your Watching List</h1> <h1 class="text-left text-xl font-bold mb-4">Your Watching List</h1>
<div class="grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8"> <div class="grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
{#each aniListWatchlist.data.Page.mediaList as media} {#each aniListWatchListLoaded.data.Page.mediaList as media}
<div class="aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-lg xl:aspect-h-8 xl:aspect-w-7"> <div class="aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-lg xl:aspect-h-8 xl:aspect-w-7">
<div class="flex flex-col items-center group"> <div class="flex flex-col items-center group">
<button on:click={() => GetAniListSingleItemAndOpenModal(media.media.id, true)}> <button on:click={() => GetAniListSingleItemAndOpenModal(media.media.id, true)}>

View File

@ -14,7 +14,7 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type {SimklAnime} from "./simkl/types/simklTypes"; import type {SimklAnime} from "./simkl/types/simklTypes";
import { get } from 'svelte/store'; 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); const simklWatch = get(simklWatchList);
let isAniListLoggedIn: boolean 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 = []; let items = [];
if(isAniListLoggedIn) { if(isAniListLoggedIn) {
@ -141,7 +160,7 @@
let values = { let values = {
progress: aniListAnime.data.MediaList.progress, progress: aniListAnime.data.MediaList.progress,
status: aniListAnime.data.MediaList.status, status: startingAnilistStatusOption,
startedAt: { startedAt: {
year: aniListAnime.data.MediaList.startedAt.year, year: aniListAnime.data.MediaList.startedAt.year,
month: aniListAnime.data.MediaList.startedAt.month, month: aniListAnime.data.MediaList.startedAt.month,
@ -197,7 +216,7 @@
await AniListUpdateEntry( await AniListUpdateEntry(
aniListAnime.data.MediaList.mediaId, aniListAnime.data.MediaList.mediaId,
values.progress, values.progress,
values.status, values.status.aniList,
values.score, values.score,
values.repeat, values.repeat,
values.notes, values.notes,
@ -227,6 +246,14 @@
simklWatch.anime[simklAnimeIndex].user_rating = values.score 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
})
}
} }
} }
</script> </script>
@ -267,13 +294,9 @@
dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
bind:value={values.status} bind:value={values.status}
> >
{#each statusOptions as option}
<option>CURRENT</option> <option value={option}>{option.aniList}</option>
<option>PLANNING</option> {/each}
<option>COMPLETED</option>
<option>DROPPED</option>
<option>PAUSED</option>
<option>REPEATING</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -1,8 +1,16 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import {GetAniListItem} from "../wailsjs/go/main/App"; import {
import type {AniListGetSingleAnime} from "./anilist/types/AniListCurrentUserWatchListType.js"; GetAniListItem,
GetAniListLoggedInUser,
GetSimklLoggedInUser
} from "../wailsjs/go/main/App";
import type {
AniListCurrentUserWatchList,
AniListGetSingleAnime
} from "./anilist/types/AniListCurrentUserWatchListType.js";
import {writable} from 'svelte/store' import {writable} from 'svelte/store'
import type {SimklWatchList} from "./simkl/types/simklTypes"; import type {SimklUser, SimklWatchList} from "./simkl/types/simklTypes";
import {type AniListUser} from "./anilist/types/AniListTypes";
export let aniListAnime: AniListGetSingleAnime export let aniListAnime: AniListGetSingleAnime
export let title = writable("") export let title = writable("")
@ -10,6 +18,10 @@
export let aniListLoggedIn = writable(false) export let aniListLoggedIn = writable(false)
export let simklLoggedIn = writable(false) export let simklLoggedIn = writable(false)
export let simklWatchList = writable({} as SimklWatchList) export let simklWatchList = writable({} as SimklWatchList)
export let aniListPrimary = writable(true)
export let simklUser = writable({} as SimklUser)
export let aniListUser = writable({} as AniListUser)
export let aniListWatchlist = writable({} as AniListCurrentUserWatchList)
export function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): void { export function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): void {
GetAniListItem(aniId, login).then(result => { GetAniListItem(aniId, login).then(result => {
@ -20,4 +32,18 @@
anilistModal.set(true) anilistModal.set(true)
}) })
} }
export function loginToSimkl(): void {
GetSimklLoggedInUser().then(result => {
simklUser = result
simklLoggedIn.set(true)
})
}
export function loginToAniList(): void {
GetAniListLoggedInUser().then(result => {
aniListUser = result
aniListLoggedIn.set(true)
})
}
</script> </script>

View File

@ -2,6 +2,16 @@
import logo from "./assets/images/AniTrackLogo.svg" import logo from "./assets/images/AniTrackLogo.svg"
import Search from "./Search.svelte" import Search from "./Search.svelte"
import UserDialogue from "./UserHeaderDialogue.svelte"; import UserDialogue from "./UserHeaderDialogue.svelte";
import {
aniListLoggedIn,
simklLoggedIn
} from "./GlobalVariablesAndHelperFunctions.svelte";
let isAniListLoggedIn: boolean
let isSimklLoggedIn: boolean
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
</script> </script>
@ -11,6 +21,16 @@
<a href="#" class="flex items-center"> <a href="#" class="flex items-center">
<img src={logo} class="mr-3 h-6 sm:h-9" alt="AniTrack Logo" /> <img src={logo} class="mr-3 h-6 sm:h-9" alt="AniTrack Logo" />
</a> </a>
<div class="flex space-x-2 items-center">
<div>
<a href="#" class="bg-blue-100 hover:bg-blue-200 text-blue-800 text-sm font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-blue-400 border border-blue-400 inline-flex items-center justify-center">AniList</a>
</div>
<div>
<a href="#" class="bg-blue-100 hover:bg-blue-200 text-blue-800 text-sm font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-blue-400 border border-blue-400 inline-flex items-center justify-center">Simkl</a>
</div>
</div>
<div class="flex space-x-4 items-center lg:order-2"> <div class="flex space-x-4 items-center lg:order-2">
<Search /> <Search />

View File

@ -27,3 +27,5 @@ export function SimklLogin():Promise<void>;
export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise<any>; export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise<any>;
export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise<any>; export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise<any>;
export function SimklSyncStatus(arg1:main.Anime,arg2:string):Promise<any>;

View File

@ -53,3 +53,7 @@ export function SimklSyncEpisodes(arg1, arg2) {
export function SimklSyncRating(arg1, arg2) { export function SimklSyncRating(arg1, arg2) {
return window['go']['main']['App']['SimklSyncRating'](arg1, arg2); return window['go']['main']['App']['SimklSyncRating'](arg1, arg2);
} }
export function SimklSyncStatus(arg1, arg2) {
return window['go']['main']['App']['SimklSyncStatus'](arg1, arg2);
}

View File

@ -25,9 +25,9 @@ func main() {
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
Title: "AniTrack", Title: "AniTrack",
Width: 1024, //Width: 1600,
Height: 768, //Height: 900,
AssetServer: &assetserver.Options{ AssetServer: &assetserver.Options{
Assets: assets, Assets: assets,
}, },