rewrote the Anime.svelte to move out helper functions and clean up code

This commit is contained in:
John O'Keefe 2024-09-05 15:29:42 -04:00
parent aeec8f79b2
commit 77e361b5b2
20 changed files with 616 additions and 473 deletions

View File

@ -355,7 +355,7 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
return post return post
} }
func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) interface{} { func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) AniListGetSingleAnime {
body := struct { body := struct {
Query string `json:"query"` Query string `json:"query"`
Variables AniListUpdateVariables `json:"variables"` Variables AniListUpdateVariables `json:"variables"`
@ -381,12 +381,33 @@ func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) interface{}
startedAt:$startedAt startedAt:$startedAt
completedAt:$completedAt completedAt:$completedAt
){ ){
id
mediaId mediaId
progress userId
media {
id
idMal
title {
romaji
english
native
}
description
coverImage {
large
}
season
seasonYear
status
episodes
nextAiringEpisode {
airingAt
timeUntilAiring
episode
}
isAdult
}
status status
score
repeat
notes
startedAt{ startedAt{
year year
month month
@ -397,6 +418,27 @@ func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) interface{}
month month
day day
} }
notes
progress
score
repeat
user {
id
name
avatar{
large
medium
}
statistics{
anime{
count
statuses{
status
count
}
}
}
}
} }
} }
`, `,
@ -405,11 +447,15 @@ func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) interface{}
returnedBody, _ := AniListQuery(body, true) returnedBody, _ := AniListQuery(body, true)
var post interface{} var returnedJson AniListUpdateReturn
err := json.Unmarshal(returnedBody, &post) err := json.Unmarshal(returnedBody, &returnedJson)
if err != nil { if err != nil {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)
} }
var post AniListGetSingleAnime
post.Data.MediaList = returnedJson.Data.SaveMediaListEntry
return post return post
} }

View File

@ -43,6 +43,12 @@ type AniListGetSingleAnime struct {
} `json:"data"` } `json:"data"`
} }
type AniListUpdateReturn struct {
Data struct {
SaveMediaListEntry MediaList `json:"SaveMediaListEntry"`
}
}
type MediaList struct { type MediaList struct {
ID int `json:"id"` ID int `json:"id"`
MediaID int `json:"mediaId"` MediaID int `json:"mediaId"`

View File

@ -55,7 +55,7 @@ func (a *App) GetMyAnimeList(count int) MALWatchlist {
return malList return malList
} }
func (a *App) MyAnimeListUpdate(anime MALAnime, update MALUploadStatus) MyListStatus { func (a *App) MyAnimeListUpdate(anime MALAnime, update MALUploadStatus) MalListStatus {
if update.NumTimesRewatched >= 1 { if update.NumTimesRewatched >= 1 {
update.IsRewatching = true update.IsRewatching = true
} else { } else {
@ -70,7 +70,7 @@ func (a *App) MyAnimeListUpdate(anime MALAnime, update MALUploadStatus) MyListSt
body.Set("comments", update.Comments) body.Set("comments", update.Comments)
malUrl := "https://api.myanimelist.net/v2/anime/" + strconv.Itoa(anime.Id) + "/my_list_status" malUrl := "https://api.myanimelist.net/v2/anime/" + strconv.Itoa(anime.Id) + "/my_list_status"
var status MyListStatus var status MalListStatus
respBody := MALHelper("PATCH", malUrl, body) respBody := MALHelper("PATCH", malUrl, body)
err := json.Unmarshal(respBody, &status) err := json.Unmarshal(respBody, &status)
if err != nil { if err != nil {

View File

@ -91,13 +91,13 @@ type MALAnime struct {
Id int `json:"id" ts_type:"id"` Id int `json:"id" ts_type:"id"`
Name string `json:"name" ts_type:"name"` Name string `json:"name" ts_type:"name"`
} `json:"genres" ts_type:"genres"` } `json:"genres" ts_type:"genres"`
CreatedAt string `json:"created_at" ts_type:"createdAt"` CreatedAt string `json:"created_at" ts_type:"createdAt"`
UpdatedAt string `json:"updated_at" ts_type:"updatedAt"` UpdatedAt string `json:"updated_at" ts_type:"updatedAt"`
MediaType string `json:"media_type" ts_type:"mediaType"` MediaType string `json:"media_type" ts_type:"mediaType"`
Status string `json:"status" ts_type:"status"` Status string `json:"status" ts_type:"status"`
MyListStatus MyListStatus `json:"my_list_status" ts_type:"myListStatus"` MalListStatus MalListStatus `json:"my_list_status" ts_type:"MalListStatus"`
NumEpisodes int `json:"num_episodes" ts_type:"numEpisodes"` NumEpisodes int `json:"num_episodes" ts_type:"numEpisodes"`
StartSeason struct { StartSeason struct {
Year int `json:"year" ts_type:"year"` Year int `json:"year" ts_type:"year"`
Season string `json:"season" ts_type:"season"` Season string `json:"season" ts_type:"season"`
} `json:"start_season" ts_type:"startSeason"` } `json:"start_season" ts_type:"startSeason"`
@ -138,7 +138,7 @@ type MALAnime struct {
} }
} }
type MyListStatus struct { type MalListStatus struct {
Status string `json:"status" ts_type:"status"` Status string `json:"status" ts_type:"status"`
Score int `json:"score" ts_type:"score"` Score int `json:"score" ts_type:"score"`
NumEpisodesWatched int `json:"num_episodes_watched" ts_type:"numEpisodesWatched"` NumEpisodesWatched int `json:"num_episodes_watched" ts_type:"numEpisodesWatched"`

View File

@ -93,7 +93,7 @@ body:graphql {
body:graphql:vars { body:graphql:vars {
{ {
"userId": 413504, "userId": 413504,
"mediaId": 110, "mediaId": 1,
"listType": "ANIME" "listType": "ANIME"
} }
} }

View File

@ -19,12 +19,33 @@ headers {
body:graphql { body:graphql {
mutation($mediaId:Int, $progress:Int, $status:MediaListStatus){ mutation($mediaId:Int, $progress:Int, $status:MediaListStatus){
SaveMediaListEntry(mediaId:$mediaId, progress:$progress, status:$status){ SaveMediaListEntry(mediaId:$mediaId, progress:$progress, status:$status){
id
mediaId mediaId
progress userId
media {
id
idMal
title {
romaji
english
native
}
description
coverImage {
large
}
season
seasonYear
status
episodes
nextAiringEpisode {
airingAt
timeUntilAiring
episode
}
isAdult
}
status status
score
repeat
notes
startedAt{ startedAt{
year year
month month
@ -35,14 +56,35 @@ body:graphql {
month month
day day
} }
notes
progress
score
repeat
user {
id
name
avatar{
large
medium
}
statistics{
anime{
count
statuses{
status
count
}
}
}
}
} }
} }
} }
body:graphql:vars { body:graphql:vars {
{ {
"mediaId": 1, "mediaId": 169417,
"progress": 26, "progress": 12,
"status":"COMPLETED" "status":"COMPLETED"
} }
} }

View File

@ -26,6 +26,7 @@
}, },
"dependencies": { "dependencies": {
"@popperjs/core": "^2.11.8", "@popperjs/core": "^2.11.8",
"@tanstack/svelte-table": "^8.20.5",
"flowbite": "^2.4.1", "flowbite": "^2.4.1",
"flowbite-svelte": "^0.46.15", "flowbite-svelte": "^0.46.15",
"moment": "^2.30.1" "moment": "^2.30.1"

View File

@ -112,6 +112,7 @@
'/anime/:id': wrap({ '/anime/:id': wrap({
asyncComponent: () => import('./routes/Anime.svelte'), asyncComponent: () => import('./routes/Anime.svelte'),
conditions: [ conditions: [
() => $aniListLoggedIn,
async (detail) => { async (detail) => {
await GetAniListSingleItem(Number(detail.params.id), true) await GetAniListSingleItem(Number(detail.params.id), true)
return Object.keys($aniListAnime).length!==0 return Object.keys($aniListAnime).length!==0

View File

@ -0,0 +1,33 @@
<script lang="ts" context="module">
import type {TableItem} from "../helperTypes/TableTypes";
import { tableItems } from "./GlobalVariablesAndHelperFunctions.svelte"
export function AddAnimeServiceToTable(tableItem: TableItem) {
let tableLoaded: TableItem[]
tableItems.subscribe(value => tableLoaded = value)
console.log(tableLoaded.length)
if(tableLoaded.length === 0) {
tableItems.update(table => {
table.push(tableItem)
return table
})
return
}
for (const [index, entry] of tableLoaded.entries()) {
console.log(entry)
if (entry.service === tableItem.service) {
tableItems.update(value => {
value[index] = tableItem
return value
})
} else {
tableItems.update(table => {
table.push(tableItem)
return table
})
}
}
return
}
</script>

View File

@ -0,0 +1,68 @@
<script lang="ts">
import {Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell} from "flowbite-svelte";
import {writable} from "svelte/store";
import type {TableItems} from "../helperTypes/TableTypes";
export let items: TableItems
// tableItems.subscribe(value => items = value)
const sortKey = writable('service'); // default sort key
const sortDirection = writable(1); // default sort direction (ascending)
const sortItems = writable(items.slice()); // make a copy of the items array
// Define a function to sort the items
const sortTable = (key: any) => {
// If the same key is clicked, reverse the sort direction
if ($sortKey === key) {
sortDirection.update((val) => -val);
} else {
sortKey.set(key);
sortDirection.set(1);
}
};
$: {
const key = $sortKey;
const direction = $sortDirection;
const sorted = [...$sortItems].sort((a, b) => {
const aVal = a[key];
const bVal = b[key];
if (aVal < bVal) {
return -direction;
} else if (aVal > bVal) {
return direction;
}
return 0;
});
sortItems.set(sorted);
}
</script>
<Table hoverable={true}>
<TableHead>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('id')}>ID</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('service')}>Service</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('progress')}>Episode Progress</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('status')}>Status</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('startedAt')}>Date Started</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('completedAt')}>Date Completed</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('score')}>Rating</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('repeat')}>Rewatches</TableHeadCell>
<TableHeadCell>Notes</TableHeadCell>
</TableHead>
<TableBody tableBodyClass="divide-y">
{#each $sortItems as item}
<TableBodyRow>
<TableBodyCell class="overflow-x-auto">{item.id}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.service}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.progress}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.status}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.startedAt}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.completedAt}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.score}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.repeat}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.notes}</TableBodyCell>
</TableBodyRow>
{/each}
</TableBody>
</Table>

View File

@ -20,6 +20,7 @@
import type {SimklAnime, SimklUser, SimklWatchList} from "../simkl/types/simklTypes"; import type {SimklAnime, SimklUser, SimklWatchList} from "../simkl/types/simklTypes";
import {type AniListUser, MediaListSort} from "../anilist/types/AniListTypes"; import {type AniListUser, MediaListSort} from "../anilist/types/AniListTypes";
import type {MALAnime, MALWatchlist, MyAnimeListUser} from "../mal/types/MALTypes"; import type {MALAnime, MALWatchlist, MyAnimeListUser} from "../mal/types/MALTypes";
import type {TableItems} from "../helperTypes/TableTypes";
export let aniListAnime = writable({} as AniListGetSingleAnime) export let aniListAnime = writable({} as AniListGetSingleAnime)
export let title = writable("") export let title = writable("")
@ -38,6 +39,7 @@
export let malAnime = writable({} as MALAnime) export let malAnime = writable({} as MALAnime)
export let simklAnime = writable({} as SimklAnime) export let simklAnime = writable({} as SimklAnime)
export let loading = writable(false) export let loading = writable(false)
export let tableItems = writable([] as TableItems)
export let watchListPage = writable(1) export let watchListPage = writable(1)
export let animePerPage = writable(20) export let animePerPage = writable(20)

View File

@ -0,0 +1,50 @@
<script lang="ts">
import StarRatting from "../star-rating/Stars.svelte";
export let score
let config = {
readOnly: false,
countStars: 5,
range: {
min: 0,
max: 5,
step: 0.5
},
score: score / 2,
showScore: false,
name: "rating",
scoreFormat: function(){ return `(${this.score.toFixed(0)}/${this.countStars})` },
starConfig: {
size: 32,
fillColor: '#F9ED4F',
strokeColor: "#e2c714",
unfilledColor: '#FFF',
strokeUnfilledColor: '#000'
}
}
const ratingInWords = {
0: "Not Reviewed",
1: "Appalling",
2: "Horrible",
3: "Very Bad",
4: "Bad",
5: "Average",
6: "Fine",
7: "Good",
8: "Very Good",
9: "Great",
10: "Masterpiece",
}
const changeRating = (e: any) => {
score = e.target.valueAsNumber * 2
}
</script>
<div>
<StarRatting bind:config on:change={changeRating}/>
<p>Rating: {config.score * 2}</p>
<p>{ratingInWords[config.score * 2]}</p>
</div>

View File

@ -0,0 +1,17 @@
import moment from "moment";
export default (date: {
year?: number,
month?: number,
day?: number,
}): string => {
if (date.year === undefined || date.year === 0
&& date.month === undefined || date.month === 0
&& date.day === undefined || date.day === 0
) {
return ""
}
const newISODate = new Date(date.year, date.month - 1, date.day)
const newMoment = moment(newISODate)
return newMoment.format('YYYY-MM-DD')
}

View File

@ -0,0 +1,22 @@
type Date = {
year: number,
month: number,
day: number,
}
export default (date: string): Date => {
if (date === "") {
return {
year: 0,
month: 0,
day: 0,
}
}
const re = /^([0-9]{4})-([0-9]{2})-([0-9]{2})/
const newDate = re.exec(date)
return {
year: Number(newDate[1]),
month: Number(newDate[2]),
day: Number(newDate[3])
}
}

View File

@ -0,0 +1,8 @@
export type StatusOptions = StatusOption[]
export type StatusOption = {
id: number,
aniList: string,
mal: string,
simkl: string,
}

View File

@ -0,0 +1,13 @@
export type TableItems = TableItem[]
export type TableItem = {
id: number
service: string
progress: number
status: string
startedAt: string
completedAt: string
score: number
repeat: number
notes: string
}

View File

@ -37,7 +37,7 @@ export interface MALWatchlist {
export interface MALAnimeFromList { export interface MALAnimeFromList {
node: Node node: Node
listStatus: ListStatus | MyListStatus listStatus: ListStatus | MalListStatus
} }
export interface Node { export interface Node {
@ -51,15 +51,6 @@ export interface MainPicture {
large: string large: string
} }
export interface ListStatus {
status: string
score: number
numEpisodesWatched: number
isRewatching: boolean
updated_at: string
startDate: string
finishDate: string
}
export interface Paging { export interface Paging {
previous: string previous: string
@ -95,7 +86,7 @@ export interface MALAnime {
updated_at: string; updated_at: string;
media_type: string; media_type: string;
status: string; status: string;
my_list_status: MyListStatus; my_list_status: MalListStatus;
num_episodes: number; num_episodes: number;
start_season: { start_season: {
year: number; year: number;
@ -138,7 +129,7 @@ export interface MALAnime {
}; };
} }
export interface MyListStatus { export interface MalListStatus {
status: string; status: string;
score: number; score: number;
num_episodes_watched: number; num_episodes_watched: number;
@ -160,4 +151,14 @@ export interface MALUploadStatus {
num_watched_episodes: number num_watched_episodes: number
num_times_rewatched: number num_times_rewatched: number
comments: string comments: string
}
export interface ListStatus {
status: string
score: number
numEpisodesWatched: number
isRewatching: boolean
updated_at: string
startDate: string
finishDate: string
} }

View File

@ -1,426 +1,282 @@
<script lang="ts"> <script lang="ts">
import { import {
aniListLoggedIn,
simklLoggedIn,
malLoggedIn,
malAnime,
simklAnime,
aniListAnime, aniListAnime,
aniListLoggedIn,
malAnime,
malLoggedIn,
simklAnime,
simklLoggedIn,
} from "../helperComponents/GlobalVariablesAndHelperFunctions.svelte"; } from "../helperComponents/GlobalVariablesAndHelperFunctions.svelte";
import {pop} from "svelte-spa-router";
import {Button} from "flowbite-svelte"; import {Button} from "flowbite-svelte";
// @ts-ignore import type {AniListGetSingleAnime} from "../anilist/types/AniListCurrentUserWatchListType";
import StarRatting from "../star-rating/Stars.svelte" import Rating from "../helperComponents/Rating.svelte";
import moment from 'moment' import convertAniListDateToString from "../helperFunctions/convertAniListDateToString";
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from 'flowbite-svelte'; import AnimeTable from "../helperComponents/AnimeTable.svelte";
import { writable } from 'svelte/store'; import type {MALAnime, MalListStatus, MALUploadStatus} from "../mal/types/MALTypes";
import type {SimklAnime} from "../simkl/types/simklTypes"; import type {SimklAnime} from "../simkl/types/simklTypes";
import {writable} from "svelte/store";
import type {StatusOption, StatusOptions} from "../helperTypes/StatusTypes";
import type {AniListUpdateVariables} from "../anilist/types/AniListTypes";
import convertDateStringToAniList from "../helperFunctions/convertDateStringToAniList";
import { import {
AniListUpdateEntry, MyAnimeListUpdate, AniListUpdateEntry,
MyAnimeListUpdate,
SimklSyncEpisodes, SimklSyncEpisodes,
SimklSyncRating, SimklSyncRating,
SimklSyncStatus SimklSyncStatus
} from "../../wailsjs/go/main/App"; } from "../../wailsjs/go/main/App";
import type {MALAnime, MALUploadStatus, MyListStatus} from "../mal/types/MALTypes"; import type {TableItems} from "../helperTypes/TableTypes";
import type {AniListUpdateVariables} from "../anilist/types/AniListTypes";
import type {AniListGetSingleAnime} from "../anilist/types/AniListCurrentUserWatchListType";
import {pop} from "svelte-spa-router";
let isAniListLoggedIn: boolean let isAniListLoggedIn: boolean
let isMalLoggedIn: boolean let isMalLoggedIn: boolean
let isSimklLoggedIn: boolean let isSimklLoggedIn: boolean
let currentAniListAnime: AniListGetSingleAnime
let currentMalAnime: MALAnime let currentMalAnime: MALAnime
let currentSimklAnime: SimklAnime let currentSimklAnime: SimklAnime
let submitting = writable(false) let submitting = writable(false)
let isSubmitting: boolean let isSubmitting: boolean
let currentAniListAnime: AniListGetSingleAnime let submitSuccess = writable(false)
let isSubmitSuccess = false
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value) aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
malLoggedIn.subscribe((value) => isMalLoggedIn = value) malLoggedIn.subscribe((value) => isMalLoggedIn = value)
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value) simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
malAnime.subscribe((value) => currentMalAnime = value)
submitting.subscribe((value) => isSubmitting = value)
simklAnime.subscribe((value) => currentSimklAnime = value)
aniListAnime.subscribe((value) => currentAniListAnime = value) aniListAnime.subscribe((value) => currentAniListAnime = value)
malAnime.subscribe((value) => currentMalAnime = value)
type statusOption = { simklAnime.subscribe((value) => currentSimklAnime = value)
id: number, submitting.subscribe((value) => isSubmitting = value)
aniList: string,
mal: string,
simkl: string,
}
const statusOptions: statusOption[] = [
{ id: 0, aniList: "CURRENT", mal: "watching", simkl: "watching"},
{ id: 1, aniList: "PLANNING", mal: "plan_to_watch", simkl: "plantowatch"},
{ id: 2, aniList: "COMPLETED", mal: "completed", simkl: "completed"},
{ id: 3, aniList: "DROPPED", mal: "dropped", simkl: "dropped"},
{ id: 4, aniList: "PAUSED", mal: "on_hold", simkl: "hold"},
{ id: 5, aniList: "REPEATING", mal: "rewatching", simkl: "watching"}
]
let startingAnilistStatusOption: statusOption
startingAnilistStatusOption = statusOptions.filter(option => currentAniListAnime.data.MediaList.status === option.aniList)[0]
type TableItems = {
id: number
service: string
progress: number
status: string
startedAt: string
completedAt: string
score: number
repeat: number
notes: string
}[]
let items = writable([] as TableItems);
let tableItems: TableItems
items.subscribe(value => tableItems = value)
if(isAniListLoggedIn) {
items.update(item => {
item.push({
id: currentAniListAnime.data.MediaList.id,
service: "AniList",
progress: currentAniListAnime.data.MediaList.progress,
status: currentAniListAnime.data.MediaList.status,
startedAt: `${currentAniListAnime.data.MediaList.startedAt.month}-${currentAniListAnime.data.MediaList.startedAt.day}-${currentAniListAnime.data.MediaList.startedAt.year}`,
completedAt: `${currentAniListAnime.data.MediaList.completedAt.month}-${currentAniListAnime.data.MediaList.completedAt.day}-${currentAniListAnime.data.MediaList.completedAt.year}`,
score: currentAniListAnime.data.MediaList.score,
repeat: currentAniListAnime.data.MediaList.repeat,
notes: currentAniListAnime.data.MediaList.notes
})
return item
})
}
if(isMalLoggedIn) {
items.update(item => {
item.push({
id: currentMalAnime.id,
service: "MyAnimeList",
progress: currentMalAnime.my_list_status.num_episodes_watched,
status: currentMalAnime.my_list_status.status,
startedAt: currentMalAnime.my_list_status.start_date,
completedAt: currentMalAnime.my_list_status.finish_date,
score: currentMalAnime.my_list_status.score,
repeat: currentMalAnime.my_list_status.num_times_rewatched,
notes: currentMalAnime.my_list_status.comments
})
return item
})
}
if(isSimklLoggedIn && Object.keys(currentSimklAnime).length > 0) {
items.update(item => {
item.push({
id: currentSimklAnime.show.ids.simkl,
service: "Simkl",
progress: currentSimklAnime.watched_episodes_count,
status: currentSimklAnime.status,
startedAt: "",
completedAt: "",
score: currentSimklAnime.user_rating,
repeat: 0,
notes: ""
})
return item
})
}
const sortKey = writable('service'); // default sort key
const sortDirection = writable(1); // default sort direction (ascending)
const sortItems = writable(tableItems.slice()); // make a copy of the items array
// Define a function to sort the items
const sortTable = (key: any) => {
// If the same key is clicked, reverse the sort direction
if ($sortKey === key) {
sortDirection.update((val) => -val);
} else {
sortKey.set(key);
sortDirection.set(1);
}
};
$: {
const key = $sortKey;
const direction = $sortDirection;
const sorted = [...$sortItems].sort((a, b) => {
const aVal = a[key];
const bVal = b[key];
if (aVal < bVal) {
return -direction;
} else if (aVal > bVal) {
return direction;
}
return 0;
});
sortItems.set(sorted);
}
const ratingInWords = {
0: "Not Reviewed",
1: "Appalling",
2: "Horrible",
3: "Very Bad",
4: "Bad",
5: "Average",
6: "Fine",
7: "Good",
8: "Very Good",
9: "Great",
10: "Masterpiece",
}
const title = currentAniListAnime.data.MediaList.media.title.english !== "" ? const title = currentAniListAnime.data.MediaList.media.title.english !== "" ?
currentAniListAnime.data.MediaList.media.title.english : currentAniListAnime.data.MediaList.media.title.english :
currentAniListAnime.data.MediaList.media.title.romaji currentAniListAnime.data.MediaList.media.title.romaji
const statusOptions: StatusOptions = [
{id: 0, aniList: "CURRENT", mal: "watching", simkl: "watching"},
{id: 1, aniList: "PLANNING", mal: "plan_to_watch", simkl: "plantowatch"},
{id: 2, aniList: "COMPLETED", mal: "completed", simkl: "completed"},
{id: 3, aniList: "DROPPED", mal: "dropped", simkl: "dropped"},
{id: 4, aniList: "PAUSED", mal: "on_hold", simkl: "hold"},
{id: 5, aniList: "REPEATING", mal: "rewatching", simkl: "watching"}
]
let startingAnilistStatusOption: StatusOption = statusOptions.filter(option => currentAniListAnime.data.MediaList.status === option.aniList)[0]
const startedAtDate = convertAniListDateToString(currentAniListAnime.data.MediaList.startedAt)
const completedAtDate = convertAniListDateToString(currentAniListAnime.data.MediaList.completedAt)
let tableItems: TableItems = []
let config = { if (isAniListLoggedIn) tableItems.push({
readOnly: false, id: currentAniListAnime.data.MediaList.id,
countStars: 5, service: "AniList",
range: {
min: 0,
max: 5,
step: 0.5
},
score: currentAniListAnime.data.MediaList.score / 2,
showScore: false,
name: "rating",
scoreFormat: function(){ return `(${this.score.toFixed(0)}/${this.countStars})` },
starConfig: {
size: 32,
fillColor: '#F9ED4F',
strokeColor: "#e2c714",
unfilledColor: '#FFF',
strokeUnfilledColor: '#000'
}
}
let values = {
progress: currentAniListAnime.data.MediaList.progress, progress: currentAniListAnime.data.MediaList.progress,
status: startingAnilistStatusOption, status: currentAniListAnime.data.MediaList.status,
startedAt: { startedAt: convertAniListDateToString(currentAniListAnime.data.MediaList.startedAt),
year: currentAniListAnime.data.MediaList.startedAt.year, completedAt: convertAniListDateToString(currentAniListAnime.data.MediaList.completedAt),
month: currentAniListAnime.data.MediaList.startedAt.month,
day: currentAniListAnime.data.MediaList.startedAt.day
},
completedAt: {
year: currentAniListAnime.data.MediaList.completedAt.year,
month: currentAniListAnime.data.MediaList.completedAt.month,
day: currentAniListAnime.data.MediaList.completedAt.day
},
repeat: currentAniListAnime.data.MediaList.repeat,
score: currentAniListAnime.data.MediaList.score, score: currentAniListAnime.data.MediaList.score,
repeat: currentAniListAnime.data.MediaList.repeat,
notes: currentAniListAnime.data.MediaList.notes notes: currentAniListAnime.data.MediaList.notes
} })
let startedAtDate: string
let completedAtDate: string
const changeRating = (e: any) => {
config.score = e.target.valueAsNumber
values.score = e.target.valueAsNumber * 2
}
if (values.startedAt.year > 0) { if (isMalLoggedIn) tableItems.push({
let startedAtISODate = new Date(values.startedAt.year, values.startedAt.month - 1, values.startedAt.day) id: currentMalAnime.id,
let startedAtMoment = moment(startedAtISODate) service: "MyAnimeList",
startedAtDate = startedAtMoment.format('YYYY-MM-DD') progress: currentMalAnime.my_list_status.num_episodes_watched,
} status: currentMalAnime.my_list_status.status,
startedAt: currentMalAnime.my_list_status.start_date,
completedAt: currentMalAnime.my_list_status.finish_date,
score: currentMalAnime.my_list_status.score,
repeat: currentMalAnime.my_list_status.num_times_rewatched,
notes: currentMalAnime.my_list_status.comments
})
const transformStartedAtDate = (e: any) => { if (isSimklLoggedIn && Object.keys(currentSimklAnime).length > 0) tableItems.push({
const re = /^([0-9]{4})-([0-9]{2})-([0-9]{2})/ id: currentSimklAnime.show.ids.simkl,
const date = re.exec(e.target.value) service: "Simkl",
values.startedAt.year = Number(date[1]) progress: currentSimklAnime.watched_episodes_count,
values.startedAt.month = Number(date[2]) status: currentSimklAnime.status,
values.startedAt.day = Number(date[3]) startedAt: "",
} completedAt: "",
score: currentSimklAnime.user_rating,
repeat: 0,
notes: ""
})
if (values.completedAt.year > 0) {
let completedAtISODate = new Date(values.completedAt.year, values.completedAt.month - 1, values.completedAt.day)
let completedAtMoment = moment(completedAtISODate)
completedAtDate = completedAtMoment.format('YYYY-MM-DD')
}
const transformCompletedAtDate = (e: any) => { const handleSubmit = async (e: any) => {
const re = /^([0-9]{4})-([0-9]{2})-([0-9]{2})/
const date = re.exec(e.target.value)
values.completedAt.year = Number(date[1])
values.completedAt.month = Number(date[2])
values.completedAt.day = Number(date[3])
}
const submitData = async () => {
submitting.set(true) submitting.set(true)
let body: AniListUpdateVariables = { let submitData: {
mediaId: currentAniListAnime.data.MediaList.mediaId, rating: number,
progress: values.progress, episodes: number,
status: values.status.aniList, status: StatusOption,
score: values.score, startedAt: string,
repeat: values.repeat, completedAt: string,
notes: values.notes, repeat: number,
startedAt: { notes: string,
year: values.startedAt.year, } = {
month: values.startedAt.month, rating: 0,
day: values.startedAt.day episodes: 0,
status: {
id: 0,
aniList: "",
mal: "",
simkl: "",
}, },
completedAt: { startedAt: "",
year: values.completedAt.year, completedAt: "",
month: values.completedAt.month, repeat: 0,
day: values.completedAt.day notes: "",
} }
const formData = new FormData(e.target)
for (let field of formData) {
const [key, value] = field
if (key === "rating") {
submitData.rating = (Number(value) * 2)
continue
}
if (key === "episodes") {
submitData.episodes = Number(value)
continue
}
if (key === "repeat") {
submitData.repeat = Number(value)
continue
}
if (key === "status") {
submitData.status = startingAnilistStatusOption
continue
}
submitData[key] = value
} }
await AniListUpdateEntry(body).then((value) => {
aniListAnime.update(anime => {
anime.data.MediaList.status = value.data.SaveMediaListEntry.status
anime.data.MediaList.progress = value.data.SaveMediaListEntry.progress
anime.data.MediaList.repeat = value.data.SaveMediaListEntry.repeat
anime.data.MediaList.score = value.data.SaveMediaListEntry.score
anime.data.MediaList.startedAt.day = value.data.SaveMediaListEntry.startedAt.day
anime.data.MediaList.startedAt.month = value.data.SaveMediaListEntry.startedAt.month
anime.data.MediaList.startedAt.year = value.data.SaveMediaListEntry.startedAt.year
if (value.data.SaveMediaListEntry.notes === null) {
anime.data.MediaList.notes = ""
} else {
anime.data.MediaList.notes = value.data.SaveMediaListEntry.notes
}
if (value.data.SaveMediaListEntry.completedAt.year === null) {
anime.data.MediaList.completedAt.year = 0
} else {
anime.data.MediaList.completedAt.year = value.data.SaveMediaListEntry.completedAt.year
}
if (value.data.SaveMediaListEntry.completedAt.month === null) {
anime.data.MediaList.completedAt.month = 0
} else {
anime.data.MediaList.completedAt.month = value.data.SaveMediaListEntry.completedAt.month
}
if (value.data.SaveMediaListEntry.completedAt.day === null) {
anime.data.MediaList.completedAt.day = 0
} else {
anime.data.MediaList.completedAt.day = value.data.SaveMediaListEntry.completedAt.day
}
for (let [index, item] of tableItems.entries()) { if (isAniListLoggedIn) {
if (item.service === "AniList") { let body: AniListUpdateVariables = {
items.update(value => { mediaId: currentAniListAnime.data.MediaList.mediaId,
value[index].id = anime.data.MediaList.id progress: submitData.episodes,
value[index].progress = anime.data.MediaList.progress status: submitData.status.aniList,
value[index].status = anime.data.MediaList.status score: submitData.rating,
value[index].startedAt = `${anime.data.MediaList.startedAt.month}-${anime.data.MediaList.startedAt.day}-${anime.data.MediaList.startedAt.year}` repeat: submitData.repeat,
value[index].completedAt = `${anime.data.MediaList.completedAt.month}-${anime.data.MediaList.completedAt.day}-${anime.data.MediaList.completedAt.year}` notes: submitData.notes,
value[index].score = anime.data.MediaList.score startedAt: convertDateStringToAniList(submitData.startedAt),
value[index].repeat = anime.data.MediaList.repeat completedAt: convertDateStringToAniList(submitData.completedAt)
value[index].notes = anime.data.MediaList.notes }
return value await AniListUpdateEntry(body).then((value: AniListGetSingleAnime) => {
}) // in future when you inevitably add tags to typescript, until Anilist fixes the api bug
} // where tags break the SaveMediaListEntry return, you'll want to use this delete line
} // delete value.data.MediaList.media.tags
return anime aniListAnime.update(newValue => {
}) newValue = value
}) return newValue
})
for (const [index, tableItem] of tableItems.entries()) {
if (tableItem.service === "AniList") {
tableItems[index].id = currentAniListAnime.data.MediaList.id
tableItems[index].service = "AniList"
tableItems[index].progress = currentAniListAnime.data.MediaList.progress
tableItems[index].status = currentAniListAnime.data.MediaList.status
tableItems[index].startedAt = convertAniListDateToString(currentAniListAnime.data.MediaList.startedAt)
tableItems[index].completedAt = convertAniListDateToString(currentAniListAnime.data.MediaList.completedAt)
tableItems[index].score = currentAniListAnime.data.MediaList.score
tableItems[index].repeat = currentAniListAnime.data.MediaList.repeat
tableItems[index].notes = currentAniListAnime.data.MediaList.notes
}
}
})
}
if(malLoggedIn) { if (malLoggedIn) {
let body: MALUploadStatus = { let body: MALUploadStatus = {
status: values.status.mal, status: submitData.status.mal,
is_rewatching: false, is_rewatching: submitData.repeat > 0,
score: values.score, score: submitData.rating,
num_watched_episodes: values.progress, num_watched_episodes: submitData.episodes,
num_times_rewatched: values.repeat, num_times_rewatched: submitData.repeat,
comments: values.notes comments: submitData.notes
} }
await MyAnimeListUpdate(currentMalAnime, body).then((malAnimeReturn: MyListStatus) => { await MyAnimeListUpdate(currentMalAnime, body).then((malAnimeReturn: MalListStatus) => {
currentMalAnime.my_list_status.status = malAnimeReturn.status malAnime.update(value => {
currentMalAnime.my_list_status.is_rewatching = malAnimeReturn.is_rewatching value.my_list_status.status = malAnimeReturn.status
currentMalAnime.my_list_status.score = malAnimeReturn.score value.my_list_status.is_rewatching = malAnimeReturn.is_rewatching
currentMalAnime.my_list_status.num_episodes_watched = malAnimeReturn.num_episodes_watched value.my_list_status.score = malAnimeReturn.score
currentMalAnime.my_list_status.num_times_rewatched = malAnimeReturn.num_times_rewatched value.my_list_status.num_episodes_watched = malAnimeReturn.num_episodes_watched
currentMalAnime.my_list_status.comments = malAnimeReturn.comments value.my_list_status.num_times_rewatched = malAnimeReturn.num_times_rewatched
for (let [index, item] of tableItems.entries()) { value.my_list_status.comments = malAnimeReturn.comments
if (item.service === "MyAnimeList") { return value
items.update(value => { })
value[index].id = currentMalAnime.id for (const [index, tableItem] of tableItems.entries()) {
value[index].progress = malAnimeReturn.num_episodes_watched if (tableItem.service === "MyAnimeList") {
value[index].status = malAnimeReturn.status tableItems[index].id = currentMalAnime.id
value[index].startedAt = malAnimeReturn.start_date tableItems[index].service = "MyAnimeList"
value[index].completedAt = malAnimeReturn.finish_date tableItems[index].progress = currentMalAnime.my_list_status.num_episodes_watched
value[index].score = malAnimeReturn.score tableItems[index].status = currentMalAnime.my_list_status.status
value[index].repeat = malAnimeReturn.num_times_rewatched tableItems[index].startedAt = currentMalAnime.my_list_status.start_date
value[index].notes = malAnimeReturn.comments tableItems[index].completedAt = currentMalAnime.my_list_status.finish_date
return value tableItems[index].score = currentMalAnime.my_list_status.score
}) tableItems[index].repeat = currentMalAnime.my_list_status.num_times_rewatched
tableItems[index].notes = currentMalAnime.my_list_status.comments
} }
} }
}) })
} }
if (simklLoggedIn) { if (simklLoggedIn) {
if (currentSimklAnime.watched_episodes_count !== values.progress) { if (currentSimklAnime.watched_episodes_count !== submitData.episodes) {
await SimklSyncEpisodes(currentSimklAnime, values.progress).then((simklAnimeReturn) => { await SimklSyncEpisodes(currentSimklAnime, submitData.episodes).then(value => {
simklAnime.set(simklAnimeReturn) simklAnime.update(newValue => {
for (let [index, item] of tableItems.entries()) { newValue = value
if (item.service === "Simkl") { return newValue
items.update(value => { })
value[index].progress = simklAnimeReturn.watched_episodes_count for (const [index, tableItem] of tableItems.entries()) {
return value if (tableItem.service === "MyAnimeList") {
}) tableItems[index].id = currentSimklAnime.show.ids.simkl
tableItems[index].service = "Simkl"
tableItems[index].progress = currentSimklAnime.watched_episodes_count
tableItems[index].status = currentSimklAnime.status
tableItems[index].startedAt = ""
tableItems[index].completedAt = ""
tableItems[index].score = currentSimklAnime.user_rating
tableItems[index].repeat = 0
tableItems[index].notes = ""
} }
} }
}) })
} }
if (currentSimklAnime.user_rating !== values.score) { if (currentSimklAnime.user_rating !== submitData.rating) {
await SimklSyncRating(currentSimklAnime, values.score).then((simklAnimeReturn) => { await SimklSyncRating(currentSimklAnime, submitData.rating).then(value => {
simklAnime.set(simklAnimeReturn) simklAnime.update(newValue => {
for (let [index, item] of tableItems.entries()) { newValue = value
if (item.service === "Simkl") { return newValue
items.update(value => { })
value[index].score = simklAnimeReturn.user_rating
return value
})
}
}
}) })
} }
if (currentSimklAnime.status !== values.status.simkl) { if (currentSimklAnime.status !== submitData.status.simkl) {
await SimklSyncStatus(currentSimklAnime, values.status.simkl).then((simklAnimeReturn) => { await SimklSyncStatus(currentSimklAnime, submitData.status.simkl).then(value => {
simklAnime.set(simklAnimeReturn) simklAnime.update(newValue => {
for (let [index, item] of tableItems.entries()) { newValue = value
if (item.service === "Simkl") { return newValue
items.update(value => { })
value[index].status = simklAnimeReturn.status
return value
})
}
}
}) })
} }
} }
submitting.set(false)
isSubmitSuccess = true
setTimeout(() => isSubmitSuccess = false, 2000)
}
submitting.set(false)
submitSuccess.set(true)
setTimeout(() => submitSuccess.set(false), 2000)
}
</script> </script>
<div class="container py-10"> <form on:submit|preventDefault={handleSubmit} class="container py-10">
<div class="grid grid-cols-1 md:grid-cols-10 grid-flow-col gap-4"> <div class="grid grid-cols-1 md:grid-cols-10 grid-flow-col gap-4">
<div class="md:col-span-2 space-y-3"> <div class="md:col-span-2 space-y-3">
<img class="rounded-lg" src={currentAniListAnime.data.MediaList.media.coverImage.large} alt="{title} Cover Image"> <img class="rounded-lg" src={currentAniListAnime.data.MediaList.media.coverImage.large}
<StarRatting bind:config on:change={changeRating}/> alt="{title} Cover Image">
<p>Rating: {config.score * 2}</p> <Rating bind:score={currentAniListAnime.data.MediaList.score}/>
<p>{ratingInWords[config.score * 2]}</p>
</div> </div>
<div class="md:col-span-8 "> <div class="md:col-span-8 ">
<div class="flex flex-col md:flex-row md:pl-10 md:pr-10 pt-5 pb-5 justify-center md:gap-x-24 lg:gap-x-56"> <div class="flex flex-col md:flex-row md:pl-10 md:pr-10 pt-5 pb-5 justify-center md:gap-x-24 lg:gap-x-56">
<div> <div>
<label for="episodes" class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Episode <label for="episodes"
class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Episode
Progress</label> Progress</label>
<input <input
type="number" type="number"
@ -428,11 +284,11 @@
min="0" min="0"
max="{currentAniListAnime.data.MediaList.media.episodes}" max="{currentAniListAnime.data.MediaList.media.episodes}"
id="episodes" id="episodes"
class="bg-gray-50 border {values.progress < 0 || values.progress > currentAniListAnime.data.MediaList.media.episodes ? class="bg-gray-50 border {currentAniListAnime.data.MediaList.progress < 0 || currentAniListAnime.data.MediaList.progress > currentAniListAnime.data.MediaList.media.episodes ?
'border-red-300 dark:border-red-500 border-[2px] text-rose-500 dark:text-rose-300 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500' : 'border-red-300 dark:border-red-500 border-[2px] text-rose-500 dark:text-rose-300 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500' :
'border-gray-300 dark:border-gray-500 text-gray-900 dark:text-white focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500' 'border-gray-300 dark:border-gray-500 text-gray-900 dark:text-white focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500'
} text-sm rounded-lg block w-24 p-2.5 dark:bg-gray-600 dark:placeholder-gray-400" } text-sm rounded-lg block w-24 p-2.5 dark:bg-gray-600 dark:placeholder-gray-400"
bind:value={values.progress} bind:value={currentAniListAnime.data.MediaList.progress}
required> required>
<div>of {currentAniListAnime.data.MediaList.media.episodes}</div> <div>of {currentAniListAnime.data.MediaList.media.episodes}</div>
</div> </div>
@ -441,11 +297,11 @@
<div> <div>
<label for="status" <label for="status"
class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Status</label> class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Status</label>
<select id="status" <select id="status" name="status"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500
focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400
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={startingAnilistStatusOption}
> >
{#each statusOptions as option} {#each statusOptions as option}
<option value={option}>{option.aniList}</option> <option value={option}>{option.aniList}</option>
@ -457,7 +313,8 @@
<div> <div>
<label for="startedAt" class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Date <label for="startedAt"
class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Date
Started</label> Started</label>
<div class="relative max-w-sm"> <div class="relative max-w-sm">
<div class="absolute inset-y-0 start-0 flex items-center ps-3.5 pointer-events-none"> <div class="absolute inset-y-0 start-0 flex items-center ps-3.5 pointer-events-none">
@ -475,13 +332,13 @@
dark:placeholder-gray-400 dark:text-white" dark:placeholder-gray-400 dark:text-white"
value={startedAtDate} value={startedAtDate}
placeholder="Date Started" placeholder="Date Started"
on:change={transformStartedAtDate}
> >
</div> </div>
</div> </div>
<div> <div>
<label for="completedAt" class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Date <label for="completedAt"
class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Date
Completed</label> Completed</label>
<div class="relative max-w-sm"> <div class="relative max-w-sm">
<div class="absolute inset-y-0 start-0 flex items-center ps-3.5 pointer-events-none"> <div class="absolute inset-y-0 start-0 flex items-center ps-3.5 pointer-events-none">
@ -499,7 +356,6 @@
dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
value={completedAtDate} value={completedAtDate}
placeholder="Date Completed" placeholder="Date Completed"
on:change={transformCompletedAtDate}
> >
</div> </div>
</div> </div>
@ -511,11 +367,11 @@
name="repeat" name="repeat"
min="0" min="0"
id="repeat" id="repeat"
class="bg-gray-50 border {values.repeat < 0 ? class="bg-gray-50 border {currentAniListAnime.data.MediaList.repeat < 0 ?
'border-red-300 dark:border-red-500 border-[2px] text-rose-500 dark:text-rose-300 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500' : 'border-red-300 dark:border-red-500 border-[2px] text-rose-500 dark:text-rose-300 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500' :
'border-gray-300 dark:border-gray-500 text-gray-900 dark:text-white focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500' 'border-gray-300 dark:border-gray-500 text-gray-900 dark:text-white focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500'
} text-sm rounded-lg block w-24 p-2.5 dark:bg-gray-600 dark:placeholder-gray-400 dark:text-white" } text-sm rounded-lg block w-24 p-2.5 dark:bg-gray-600 dark:placeholder-gray-400 dark:text-white"
bind:value={values.repeat} bind:value={currentAniListAnime.data.MediaList.repeat}
required> required>
</div> </div>
</div> </div>
@ -523,63 +379,40 @@
<div class="w-full"> <div class="w-full">
<label for="notes" class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your <label for="notes" class="text-left block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your
notes</label> notes</label>
<textarea id="notes" rows="3" <textarea id="notes" rows="3" name="notes"
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="Write your thoughts here..." placeholder="Write your thoughts here..."
bind:value={values.notes}></textarea> bind:value={currentAniListAnime.data.MediaList.notes}></textarea>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div id="external-data"> <div id="external-data">
<div id="anilist-data" class="flex flex-col md:flex-row md:pl-10 md:pr-10 pt-5 pb-5 justify-center md:gap-x-16 lg:gap-x-36 group"> <div id="anilist-data"
class="flex flex-col md:flex-row md:pl-10 md:pr-10 pt-5 pb-5 justify-center md:gap-x-16 lg:gap-x-36 group">
<h2 class="text-left mb-1 text-base font-semibold text-gray-900 dark:text-white">AniList</h2> <h2 class="text-left mb-1 text-base font-semibold text-gray-900 dark:text-white">AniList</h2>
</div> </div>
</div> </div>
<Table hoverable={true}> <AnimeTable items={tableItems}/>
<TableHead>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('id')}>ID</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('service')}>Service</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('progress')}>Episode Progress</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('status')}>Status</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('startedAt')}>Date Started</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('completedAt')}>Date Completed</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('score')}>Rating</TableHeadCell>
<TableHeadCell class="cursor-pointer" on:click={() => sortTable('repeat')}>Rewatches</TableHeadCell>
<TableHeadCell>Notes</TableHeadCell>
</TableHead>
<TableBody tableBodyClass="divide-y">
{#each $sortItems as item}
<TableBodyRow>
<TableBodyCell class="overflow-x-auto">{item.id}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.service}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.progress}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.status}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.startedAt}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.completedAt}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.score}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.repeat}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.notes}</TableBodyCell>
</TableBodyRow>
{/each}
</TableBody>
</Table>
<div class="bg-white rounded-lg shadow max-w-4-4 dark:bg-gray-800"> <div class="bg-white rounded-lg shadow max-w-4-4 dark:bg-gray-800">
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-end"> <div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-end">
<Button disabled={isSubmitting} <Button disabled={isSubmitting}
id="sync-button" id="sync-button"
class="text-white bg-blue-700 {isSubmitSuccess ? class="text-white bg-blue-700 {$submitSuccess ?
'dark:bg-green-600 hover:bg-green-800 dark:hover:bg-green-700 focus:ring-4 focus:ring-green-300 dark:focus:ring-green-800' : 'dark:bg-green-600 hover:bg-green-800 dark:hover:bg-green-700 focus:ring-4 focus:ring-green-300 dark:focus:ring-green-800' :
'dark:bg-blue-600 hover:bg-blue-800 dark:hover:bg-blue-700 focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800' 'dark:bg-blue-600 hover:bg-blue-800 dark:hover:bg-blue-700 focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800'
} font-medium } font-medium
rounded-lg text-sm px-5 py-2.5 me-2 mb-2 focus:outline-none" rounded-lg text-sm px-5 py-2.5 me-2 mb-2 focus:outline-none"
on:click={submitData}> type="submit">
<svg id="submit-loader" aria-hidden="true" role="status" class="{isSubmitting ? 'inline': 'hidden'} w-4 h-4 me-3 text-white animate-spin" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg id="submit-loader" aria-hidden="true" role="status"
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="#E5E7EB"/> class="{isSubmitting ? 'inline': 'hidden'} w-4 h-4 me-3 text-white animate-spin"
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentColor"/> viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="#E5E7EB"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentColor"/>
</svg> </svg>
Sync Changes Sync Changes
</Button> </Button>
@ -599,4 +432,4 @@
</h3> </h3>
<p>{@html currentAniListAnime.data.MediaList.media.description}</p> <p>{@html currentAniListAnime.data.MediaList.media.description}</p>
</div> </div>
</div> </form>

View File

@ -6,7 +6,7 @@ export function AniListLogin():Promise<void>;
export function AniListSearch(arg1:string):Promise<any>; export function AniListSearch(arg1:string):Promise<any>;
export function AniListUpdateEntry(arg1:main.AniListUpdateVariables):Promise<any>; export function AniListUpdateEntry(arg1:main.AniListUpdateVariables):Promise<main.AniListGetSingleAnime>;
export function CheckIfAniListLoggedIn():Promise<boolean>; export function CheckIfAniListLoggedIn():Promise<boolean>;
@ -36,7 +36,7 @@ export function LogoutSimkl():Promise<string>;
export function MyAnimeListLogin():Promise<void>; export function MyAnimeListLogin():Promise<void>;
export function MyAnimeListUpdate(arg1:main.MALAnime,arg2:main.MALUploadStatus):Promise<main.MyListStatus>; export function MyAnimeListUpdate(arg1:main.MALAnime,arg2:main.MALUploadStatus):Promise<main.MalListStatus>;
export function SimklGetUserWatchlist():Promise<main.SimklWatchList>; export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;

View File

@ -188,7 +188,7 @@ export namespace main {
updated_at: updatedAt; updated_at: updatedAt;
media_type: mediaType; media_type: mediaType;
status: status; status: status;
my_list_status: myListStatus; my_list_status: MalListStatus;
num_episodes: numEpisodes; num_episodes: numEpisodes;
start_season: startSeason; start_season: startSeason;
broadcast: broadcast; broadcast: broadcast;
@ -311,6 +311,40 @@ export namespace main {
return a; return a;
} }
} }
export class MalListStatus {
status: status;
score: score;
num_episodes_watched: numEpisodesWatched;
is_rewatching: isRewatching;
start_date: startDate;
finish_date: finishDate;
priority: priority;
num_times_rewatched: numTimesRewatched;
rewatch_value: rewatchValue;
tags: tags;
comments: comments;
updated_at: updatedAt;
static createFrom(source: any = {}) {
return new MalListStatus(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.status = source["status"];
this.score = source["score"];
this.num_episodes_watched = source["num_episodes_watched"];
this.is_rewatching = source["is_rewatching"];
this.start_date = source["start_date"];
this.finish_date = source["finish_date"];
this.priority = source["priority"];
this.num_times_rewatched = source["num_times_rewatched"];
this.rewatch_value = source["rewatch_value"];
this.tags = source["tags"];
this.comments = source["comments"];
this.updated_at = source["updated_at"];
}
}
export class MediaList { export class MediaList {
id: number; id: number;
mediaId: number; mediaId: number;
@ -425,40 +459,6 @@ export namespace main {
this.is_supporter = source["is_supporter"]; this.is_supporter = source["is_supporter"];
} }
} }
export class MyListStatus {
status: status;
score: score;
num_episodes_watched: numEpisodesWatched;
is_rewatching: isRewatching;
start_date: startDate;
finish_date: finishDate;
priority: priority;
num_times_rewatched: numTimesRewatched;
rewatch_value: rewatchValue;
tags: tags;
comments: comments;
updated_at: updatedAt;
static createFrom(source: any = {}) {
return new MyListStatus(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.status = source["status"];
this.score = source["score"];
this.num_episodes_watched = source["num_episodes_watched"];
this.is_rewatching = source["is_rewatching"];
this.start_date = source["start_date"];
this.finish_date = source["finish_date"];
this.priority = source["priority"];
this.num_times_rewatched = source["num_times_rewatched"];
this.rewatch_value = source["rewatch_value"];
this.tags = source["tags"];
this.comments = source["comments"];
this.updated_at = source["updated_at"];
}
}
export class SimklAnime { export class SimklAnime {
last_watched_at: last_watched_at; last_watched_at: last_watched_at;
status: status; status: status;