4 Commits

3 changed files with 873 additions and 823 deletions

View File

@@ -17,6 +17,7 @@
"svelte": "^4.0.0", "svelte": "^4.0.0",
"svelte-check": "^3.4.3", "svelte-check": "^3.4.3",
"svelte-headless-table": "^0.18.2", "svelte-headless-table": "^0.18.2",
"@tanstack/svelte-table": "^8.20.5",
"svelte-preprocess": "^5.0.3", "svelte-preprocess": "^5.0.3",
"svelte-spa-router": "^4.0.1", "svelte-spa-router": "^4.0.1",
"tailwind-merge": "^2.5.2", "tailwind-merge": "^2.5.2",

View File

@@ -23,15 +23,9 @@
} from "../mal/types/MALTypes"; } from "../mal/types/MALTypes";
import type { SimklAnime } from "../simkl/types/simklTypes"; import type { SimklAnime } from "../simkl/types/simklTypes";
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import type { import type { StatusOption, StatusOptions } from "../helperTypes/StatusTypes";
StatusOption,
StatusOptions,
} from "../helperTypes/StatusTypes";
import type { AniListUpdateVariables } from "../anilist/types/AniListTypes"; import type { AniListUpdateVariables } from "../anilist/types/AniListTypes";
import { import { convertDateToAniList } from "../helperFunctions/convertDateToAniList";
convertDateStringToAniList,
convertDateToAniList,
} from "../helperFunctions/convertDateToAniList";
import { import {
AniListDeleteEntry, AniListDeleteEntry,
AniListUpdateEntry, AniListUpdateEntry,
@@ -83,8 +77,7 @@
{ id: 5, aniList: "REPEATING", mal: "rewatching", simkl: "watching" }, { id: 5, aniList: "REPEATING", mal: "rewatching", simkl: "watching" },
]; ];
let startingAnilistStatusOption: StatusOption = statusOptions.filter( let startingAnilistStatusOption: StatusOption = statusOptions.filter(
(option) => (option) => currentAniListAnime.data.MediaList.status === option.aniList,
currentAniListAnime.data.MediaList.status === option.aniList,
)[0]; )[0];
let startedAtDate: Date | null = convertAniListDateToDate( let startedAtDate: Date | null = convertAniListDateToDate(
currentAniListAnime.data.MediaList.startedAt, currentAniListAnime.data.MediaList.startedAt,
@@ -115,15 +108,11 @@
let startDate = ""; let startDate = "";
let finishDate = ""; let finishDate = "";
if (currentMalAnime.my_list_status.start_date !== "") { if (currentMalAnime.my_list_status.start_date !== "") {
const startArray = re.exec( const startArray = re.exec(currentMalAnime.my_list_status.start_date);
currentMalAnime.my_list_status.start_date,
);
startDate = `${startArray[2]}-${startArray[3]}-${startArray[1]}`; startDate = `${startArray[2]}-${startArray[3]}-${startArray[1]}`;
} }
if (currentMalAnime.my_list_status.finish_date !== "") { if (currentMalAnime.my_list_status.finish_date !== "") {
const finishArray = re.exec( const finishArray = re.exec(currentMalAnime.my_list_status.finish_date);
currentMalAnime.my_list_status.finish_date,
);
finishDate = `${finishArray[2]}-${finishArray[3]}-${finishArray[1]}`; finishDate = `${finishArray[2]}-${finishArray[3]}-${finishArray[1]}`;
} }
AddAnimeServiceToTable({ AddAnimeServiceToTable({
@@ -200,10 +189,7 @@
submitData[key] = value; submitData[key] = value;
} }
if ( if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) {
isAniListLoggedIn &&
currentAniListAnime.data.MediaList.mediaId !== 0
) {
let body: AniListUpdateVariables = { let body: AniListUpdateVariables = {
mediaId: currentAniListAnime.data.MediaList.mediaId, mediaId: currentAniListAnime.data.MediaList.mediaId,
progress: submitData.episodes, progress: submitData.episodes,
@@ -214,8 +200,7 @@
startedAt: convertDateToAniList(startedAtDate), startedAt: convertDateToAniList(startedAtDate),
completedAt: convertDateToAniList(completedAtDate), completedAt: convertDateToAniList(completedAtDate),
}; };
await AniListUpdateEntry(body).then( await AniListUpdateEntry(body).then((value: AniListGetSingleAnime) => {
(value: AniListGetSingleAnime) => {
/* TODO in future when you inevitably add tags to typescript, until Anilist fixes the api bug /* TODO 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 where tags break the SaveMediaListEntry return, you'll want to use this delete line
delete value.data.MediaList.media.tags */ delete value.data.MediaList.media.tags */
@@ -239,8 +224,7 @@
repeat: currentAniListAnime.data.MediaList.repeat, repeat: currentAniListAnime.data.MediaList.repeat,
notes: currentAniListAnime.data.MediaList.notes, notes: currentAniListAnime.data.MediaList.notes,
}); });
}, });
);
} }
if (malLoggedIn && currentMalAnime.id !== 0) { if (malLoggedIn && currentMalAnime.id !== 0) {
@@ -257,8 +241,7 @@
(malAnimeReturn: MalListStatus) => { (malAnimeReturn: MalListStatus) => {
malAnime.update((value) => { malAnime.update((value) => {
value.my_list_status.status = malAnimeReturn.status; value.my_list_status.status = malAnimeReturn.status;
value.my_list_status.is_rewatching = value.my_list_status.is_rewatching = malAnimeReturn.is_rewatching;
malAnimeReturn.is_rewatching;
value.my_list_status.score = malAnimeReturn.score; value.my_list_status.score = malAnimeReturn.score;
value.my_list_status.num_episodes_watched = value.my_list_status.num_episodes_watched =
malAnimeReturn.num_episodes_watched; malAnimeReturn.num_episodes_watched;
@@ -285,14 +268,12 @@
id: `m-${currentMalAnime.id}`, id: `m-${currentMalAnime.id}`,
title: currentMalAnime.title, title: currentMalAnime.title,
service: "MyAnimeList", service: "MyAnimeList",
progress: progress: currentMalAnime.my_list_status.num_episodes_watched,
currentMalAnime.my_list_status.num_episodes_watched,
status: currentMalAnime.my_list_status.status, status: currentMalAnime.my_list_status.status,
startedAt: startDate, startedAt: startDate,
completedAt: finishDate, completedAt: finishDate,
score: currentMalAnime.my_list_status.score, score: currentMalAnime.my_list_status.score,
repeat: currentMalAnime.my_list_status repeat: currentMalAnime.my_list_status.num_times_rewatched,
.num_times_rewatched,
notes: currentMalAnime.my_list_status.comments, notes: currentMalAnime.my_list_status.comments,
}); });
}, },
@@ -300,13 +281,9 @@
} }
if (simklLoggedIn && currentSimklAnime.show.ids.simkl !== 0) { if (simklLoggedIn && currentSimklAnime.show.ids.simkl !== 0) {
if ( if (currentSimklAnime.watched_episodes_count !== submitData.episodes) {
currentSimklAnime.watched_episodes_count !== submitData.episodes await SimklSyncEpisodes(currentSimklAnime, submitData.episodes).then(
) { (value: SimklAnime) => {
await SimklSyncEpisodes(
currentSimklAnime,
submitData.episodes,
).then((value: SimklAnime) => {
AddAnimeServiceToTable({ AddAnimeServiceToTable({
id: `s-${value.show.ids.simkl}`, id: `s-${value.show.ids.simkl}`,
title: value.show.title, title: value.show.title,
@@ -323,14 +300,13 @@
newValue = value; newValue = value;
return newValue; return newValue;
}); });
}); },
);
} }
if (currentSimklAnime.user_rating !== submitData.rating) { if (currentSimklAnime.user_rating !== submitData.rating) {
await SimklSyncRating( await SimklSyncRating(currentSimklAnime, submitData.rating).then(
currentSimklAnime, (value) => {
submitData.rating,
).then((value) => {
AddAnimeServiceToTable({ AddAnimeServiceToTable({
id: `s-${value.show.ids.simkl}`, id: `s-${value.show.ids.simkl}`,
title: value.show.title, title: value.show.title,
@@ -347,14 +323,13 @@
newValue = value; newValue = value;
return newValue; return newValue;
}); });
}); },
);
} }
if (currentSimklAnime.status !== submitData.status.simkl) { if (currentSimklAnime.status !== submitData.status.simkl) {
await SimklSyncStatus( await SimklSyncStatus(currentSimklAnime, submitData.status.simkl).then(
currentSimklAnime, (value) => {
submitData.status.simkl,
).then((value) => {
AddAnimeServiceToTable({ AddAnimeServiceToTable({
id: `s-${value.show.ids.simkl}`, id: `s-${value.show.ids.simkl}`,
title: value.show.title, title: value.show.title,
@@ -371,7 +346,8 @@
newValue = value; newValue = value;
return newValue; return newValue;
}); });
}); },
);
} }
} }
@@ -382,10 +358,7 @@
const deleteEntries = async () => { const deleteEntries = async () => {
submitting.set(true); submitting.set(true);
if ( if (isAniListLoggedIn && currentAniListAnime.data.MediaList.mediaId !== 0) {
isAniListLoggedIn &&
currentAniListAnime.data.MediaList.mediaId !== 0
) {
await AniListDeleteEntry(currentAniListAnime.data.MediaList.id); await AniListDeleteEntry(currentAniListAnime.data.MediaList.id);
AddAnimeServiceToTable({ AddAnimeServiceToTable({
id: `a-${currentAniListAnime.data.MediaList.mediaId}`, id: `a-${currentAniListAnime.data.MediaList.mediaId}`,
@@ -445,8 +418,7 @@
currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode !== 0 currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode !== 0
) { ) {
max = max =
currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode - currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode - 1;
1;
} }
</script> </script>
@@ -507,22 +479,18 @@
id="episodes" id="episodes"
class="border border-x-0 p-2.5 h-11 text-center text-sm block w-full placeholder-gray-400 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none class="border border-x-0 p-2.5 h-11 text-center text-sm block w-full placeholder-gray-400 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none
{currentAniListAnime.data.MediaList.progress < 0 || {currentAniListAnime.data.MediaList.progress < 0 ||
(currentAniListAnime.data.MediaList.media.episodes > (currentAniListAnime.data.MediaList.media.episodes > 0 &&
0 &&
currentAniListAnime.data.MediaList.progress > currentAniListAnime.data.MediaList.progress >
currentAniListAnime.data.MediaList.media currentAniListAnime.data.MediaList.media.episodes) ||
.episodes) || (currentAniListAnime.data.MediaList.media.nextAiringEpisode
(currentAniListAnime.data.MediaList.media .episode > 0 &&
.nextAiringEpisode.episode > 0 &&
currentAniListAnime.data.MediaList.progress > currentAniListAnime.data.MediaList.progress >
currentAniListAnime.data.MediaList.media currentAniListAnime.data.MediaList.media.nextAiringEpisode
.nextAiringEpisode.episode - .episode -
1) 1)
? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500' ? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500'
: 'bg-gray-700 hover:bg-gray-600 border-gray-600 text-white focus:ring-blue-500 focus:border-blue-500'} w-24" : 'bg-gray-700 hover:bg-gray-600 border-gray-600 text-white focus:ring-blue-500 focus:border-blue-500'} w-24"
bind:value={ bind:value={currentAniListAnime.data.MediaList.progress}
currentAniListAnime.data.MediaList.progress
}
required required
/> />
<button <button
@@ -551,16 +519,15 @@
</button> </button>
</div> </div>
<div> <div>
/ {currentAniListAnime.data.MediaList.media / {currentAniListAnime.data.MediaList.media.nextAiringEpisode
.nextAiringEpisode.episode !== 0 .episode !== 0
? currentAniListAnime.data.MediaList.media ? currentAniListAnime.data.MediaList.media.nextAiringEpisode
.nextAiringEpisode.episode - 1 .episode - 1
: currentAniListAnime.data.MediaList.media.episodes} : currentAniListAnime.data.MediaList.media.episodes}
</div> </div>
{#if currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode !== 0} {#if currentAniListAnime.data.MediaList.media.nextAiringEpisode.episode !== 0}
<div> <div>
of {currentAniListAnime.data.MediaList.media of {currentAniListAnime.data.MediaList.media.episodes}
.episodes}
</div> </div>
{/if} {/if}
</div> </div>
@@ -633,8 +600,7 @@
name="repeat" name="repeat"
min="0" min="0"
id="repeat" id="repeat"
class="border {currentAniListAnime.data.MediaList class="border {currentAniListAnime.data.MediaList.repeat < 0
.repeat < 0
? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500' ? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500'
: 'border-gray-500 text-white focus:ring-blue-500 focus:border-blue-500'} text-sm rounded-lg block w-24 p-2.5 bg-gray-600 placeholder-gray-400 text-white" : 'border-gray-500 text-white focus:ring-blue-500 focus:border-blue-500'} text-sm rounded-lg block w-24 p-2.5 bg-gray-600 placeholder-gray-400 text-white"
bind:value={currentAniListAnime.data.MediaList.repeat} bind:value={currentAniListAnime.data.MediaList.repeat}
@@ -663,17 +629,53 @@
</div> </div>
</div> </div>
</div> </div>
<div id="external-data"> <div class="flex mb-4 rounded-lg shadow max-w-4-4 bg-gray-800">
<div <div
id="anilist-data" class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-end"
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-white"> <Button
AniList disabled={isSubmitting}
</h2> id="sync-button"
class="text-white {$submitSuccess
? 'bg-green-600 dark:bg-green-600 hover:bg-green-700 dark:hover:bg-green-700 focus:ring-4 focus:ring-green-800 dark:focus:ring-green-800'
: 'bg-blue-600 dark:bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-700 focus:ring-4 focus:ring-blue-800 dark:focus:ring-blue-800'} font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 focus:outline-none"
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"
>
<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>
Sync Changes
</Button>
<Button
class="text-white bg-gray-800 border border-gray-600 focus:outline-none hover:bg-gray-700 focus:ring-4
focus:ring-gray-700 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:text-white
dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700"
on:click={async () => {
await CheckIfAniListLoggedInAndLoadWatchList();
return push("/");
}}
>
Go Home
</Button>
</div> </div>
</div> </div>
<AnimeTable /> <AnimeTable />
<div class="flex rounded-lg shadow max-w-4-4 bg-gray-800"> <div class="flex rounded-lg shadow max-w-4-4 bg-gray-800">

View File

@@ -1,119 +1,166 @@
<script lang="ts"> <script lang="ts">
import { writable } from "svelte/store";
import { import {
createRender, createSvelteTable,
createTable, flexRender,
Render, getCoreRowModel,
Subscribe, getSortedRowModel,
} from "svelte-headless-table" type OnChangeFn,
// @ts-ignore renderComponent,
import { addSortBy } from "svelte-headless-table/plugins" } from "@tanstack/svelte-table";
import { tableItems } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte" import type {
import WebsiteLink from "./WebsiteLink.svelte" ColumnDef,
SortingState,
TableOptions,
Updater,
} from "@tanstack/svelte-table";
import { tableItems } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
import type { TableItem, TableItems } from "../helperTypes/TableTypes";
import WebsiteLink from "./WebsiteLink.svelte";
//when adding sort here is code { sort: addSortBy() } let currentTableItems: TableItems;
const table = createTable(tableItems, { sort: addSortBy() })
const columns = table.createColumns([ tableItems.subscribe((value: TableItems) => (currentTableItems = value));
table.column({
header: "Service Id", const defaultColumns: ColumnDef<TableItem>[] = [
cell: ({ value }) => createRender(WebsiteLink, {id: value}), {
accessor: "id", accessorKey: "id",
}), cell: (cell) => {
table.column({ return renderComponent(WebsiteLink, { id: cell.renderValue() });
header: "Anime Title", },
accessor: "title", header: () => "Service ID",
}), },
table.column({ {
header: "Service", accessorKey: "title",
accessor: "service", header: () => "Anime Title",
}), },
table.column({ {
header: "Episode Progress", accessorKey: "service",
accessor: "progress", header: () => "Service",
}), },
table.column({ {
accessorKey: "progress",
header: () => "Episode Progress",
},
{
accessorKey: "status",
header: "Status", header: "Status",
accessor: "status", },
}), {
table.column({ accessorKey: "startedAt",
header: "Started At", header: "Started At",
accessor: "startedAt", },
}), {
table.column({ accessorKey: "completedAt",
header: "Completed At", header: "Completed At",
accessor: "completedAt", },
}), {
table.column({ accessorKey: "score",
header: "Rating", header: "Rating",
accessor: "score", },
}), {
table.column({ accessorKey: "repeat",
header: "Repeat", header: "Repeat",
accessor: "repeat", },
}), {
table.column({ accessorKey: "notes",
header: "Notes", header: "Notes",
accessor: "notes", },
}), ];
])
//add pluginStates when add sort back //sorting info
const { headerRows, rows, tableAttrs, tableBodyAttrs } = let sorting: SortingState[] = [];
table.createViewModel(columns)
const setSorting: OnChangeFn<SortingState> = (updater) => {
if (updater instanceof Function) {
sorting = updater(sorting);
} else {
sorting = updater;
}
options.update((old) => ({
...old,
state: {
...old.state,
sorting,
},
}));
};
const options = writable<TableOptions<TableItem>>({
data: currentTableItems,
columns: defaultColumns,
state: {
sorting,
},
onSortingChange: setSorting,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
});
const rerender = () => {
options.update((options) => ({
...options,
data: currentTableItems,
}));
};
const table = createSvelteTable(options);
</script> </script>
<div class="relative overflow-x-auto rounded-lg mb-5"> <div>
<table <div class="relative overflow-x-auto rounded-lg mb-5">
class="w-full text-sm text-left rtl:text-right text-gray-400" <table class="w-full text-sm text-left rtl:text-right text-gray-400">
{...$tableAttrs}
>
<thead class="text-xs uppercase bg-gray-700 text-gray-400"> <thead class="text-xs uppercase bg-gray-700 text-gray-400">
{#each $headerRows as headerRow (headerRow.id)} {#each $table.getHeaderGroups() as headerGroup}
<Subscribe attrs={headerRow.attrs()} let:attrs> <tr>
<tr {...attrs}> {#each headerGroup.headers as header}
{#each headerRow.cells as cell (cell.id)} <th colSpan={header.colSpan} class="px-6 py-3">
<Subscribe {#if !header.isPlaceholder}
attrs={cell.attrs()} <div
let:attrs class:cursor-pointer={header.column.getCanSort()}
props={cell.props()} class:select-none={header.column.getCanSort()}
let:props on:click={header.column.getToggleSortingHandler()}
> >
<th <svelte:component
{...attrs} this={flexRender(
on:click={props.sort.toggle} header.column.columnDef.header,
class:sorted={props.sort.order !== header.getContext(),
undefined} )}
class="px-6 py-3" />
> {#if header.column.getIsSorted().toString() === "asc"}
<div>
<Render of={cell.render()} />
{#if props.sort.order === "asc"}
⬇️
{:else if props.sort.order === "desc"}
⬆️ ⬆️
{:else if header.column.getIsSorted().toString() === "desc"}
⬇️
{/if} {/if}
</div> </div>
{/if}
</th> </th>
</Subscribe>
{/each} {/each}
</tr> </tr>
</Subscribe>
{/each} {/each}
</thead> </thead>
<tbody {...$tableBodyAttrs}> <tbody class="bg-gray-800 border-gray-700">
{#each $rows as row (row.id)} {#each $table.getRowModel().rows as row}
<Subscribe attrs={row.attrs()} let:attrs> <tr>
<tr {...attrs} class="bg-gray-800 border-gray-700"> {#each row.getVisibleCells() as cell}
{#each row.cells as cell (cell.id)} <td class="px-6 py-4">
<Subscribe attrs={cell.attrs()} let:attrs> <svelte:component
<td {...attrs} class="px-6 py-4"> this={flexRender(
<Render of={cell.render()} /> cell.column.columnDef.cell,
cell.getContext(),
)}
/>
</td> </td>
</Subscribe>
{/each} {/each}
</tr> </tr>
</Subscribe>
{/each} {/each}
</tbody> </tbody>
</table> </table>
</div>
<!-- <button -->
<!-- class="text-white bg-blue-600 dark:bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-700 focus:ring-4 focus:ring-blue-800 dark:focus:ring-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 focus:outline-none" -->
<!-- on:click={() => rerender()} -->
<!-- > -->
<!-- Rerender -->
<!-- </button> -->
</div> </div>