From c9c66508290a41c2077de643ab33ca8a82df55de Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 25 Jan 2025 22:50:35 -0500 Subject: [PATCH] significantly improved datepicker --- frontend/src/helperComponents/Anime.svelte | 142 +++++++++--------- .../src/helperComponents/Datepicker.svelte | 6 +- .../helperFunctions/convertAniListDateIn.ts | 37 +++++ .../convertAniListDateToString.ts | 17 --- .../convertDateStringToAniList.ts | 22 --- .../helperFunctions/convertDateToAniList.ts | 39 +++++ 6 files changed, 152 insertions(+), 111 deletions(-) create mode 100644 frontend/src/helperFunctions/convertAniListDateIn.ts delete mode 100644 frontend/src/helperFunctions/convertAniListDateToString.ts delete mode 100644 frontend/src/helperFunctions/convertDateStringToAniList.ts create mode 100644 frontend/src/helperFunctions/convertDateToAniList.ts diff --git a/frontend/src/helperComponents/Anime.svelte b/frontend/src/helperComponents/Anime.svelte index 53651ca..95a46c2 100644 --- a/frontend/src/helperComponents/Anime.svelte +++ b/frontend/src/helperComponents/Anime.svelte @@ -11,7 +11,10 @@ import { Button } from "flowbite-svelte"; import type { AniListGetSingleAnime } from "../anilist/types/AniListCurrentUserWatchListType"; import Rating from "./Rating.svelte"; - import convertAniListDateToString from "../helperFunctions/convertAniListDateToString"; + import { + convertAniListDateToString, + convertAniListDateToDate, + } from "../helperFunctions/convertAniListDateIn"; import AnimeTable from "./AnimeTable.svelte"; import type { MALAnime, @@ -25,7 +28,10 @@ StatusOptions, } from "../helperTypes/StatusTypes"; import type { AniListUpdateVariables } from "../anilist/types/AniListTypes"; - import convertDateStringToAniList from "../helperFunctions/convertDateStringToAniList"; + import { + convertDateStringToAniList, + convertDateToAniList, + } from "../helperFunctions/convertDateToAniList"; import { AniListDeleteEntry, AniListUpdateEntry, @@ -39,6 +45,7 @@ import { AddAnimeServiceToTable } from "../helperModules/AddAnimeServiceToTable.svelte"; import { CheckIfAniListLoggedInAndLoadWatchList } from "../helperModules/CheckIfAniListLoggedInAndLoadWatchList.svelte"; import Datepicker from "./Datepicker.svelte"; + const re = /^([0-9]{4})-([0-9]{2})-([0-9]{2})/; let isAniListLoggedIn: boolean; let isMalLoggedIn: boolean; @@ -79,10 +86,10 @@ (option) => currentAniListAnime.data.MediaList.status === option.aniList, )[0]; - const startedAtDate = convertAniListDateToString( + let startedAtDate: Date | null = convertAniListDateToDate( currentAniListAnime.data.MediaList.startedAt, ); - const completedAtDate = convertAniListDateToString( + let completedAtDate: Date | null = convertAniListDateToDate( currentAniListAnime.data.MediaList.completedAt, ); @@ -104,19 +111,34 @@ notes: currentAniListAnime.data.MediaList.notes, }); - if (isMalLoggedIn) + if (isMalLoggedIn) { + let startDate = ""; + let finishDate = ""; + if (currentMalAnime.my_list_status.start_date !== "") { + const startArray = re.exec( + currentMalAnime.my_list_status.start_date, + ); + startDate = `${startArray[2]}-${startArray[3]}-${startArray[1]}`; + } + if (currentMalAnime.my_list_status.finish_date !== "") { + const finishArray = re.exec( + currentMalAnime.my_list_status.finish_date, + ); + finishDate = `${finishArray[2]}-${finishArray[3]}-${finishArray[1]}`; + } AddAnimeServiceToTable({ id: `m-${currentMalAnime.id}`, title: currentMalAnime.title, 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, + startedAt: startDate, + completedAt: finishDate, score: currentMalAnime.my_list_status.score, repeat: currentMalAnime.my_list_status.num_times_rewatched, notes: currentMalAnime.my_list_status.comments, }); + } if (isSimklLoggedIn && Object.keys(currentSimklAnime).length > 0) AddAnimeServiceToTable({ @@ -138,8 +160,8 @@ rating: number; episodes: number; status: StatusOption; - startedAt: string; - completedAt: string; + startedAt: Date | null; + completedAt: Date | null; repeat: number; notes: string; } = { @@ -151,8 +173,8 @@ mal: "", simkl: "", }, - startedAt: "", - completedAt: "", + startedAt: null, + completedAt: null, repeat: 0, notes: "", }; @@ -189,8 +211,8 @@ score: submitData.rating, repeat: submitData.repeat, notes: submitData.notes, - startedAt: convertDateStringToAniList(submitData.startedAt), - completedAt: convertDateStringToAniList(submitData.completedAt), + startedAt: convertDateToAniList(startedAtDate), + completedAt: convertDateToAniList(completedAtDate), }; await AniListUpdateEntry(body).then( (value: AniListGetSingleAnime) => { @@ -245,6 +267,20 @@ value.my_list_status.comments = malAnimeReturn.comments; return value; }); + let startDate = ""; + let finishDate = ""; + if (currentMalAnime.my_list_status.start_date !== "") { + const startArray = re.exec( + currentMalAnime.my_list_status.start_date, + ); + startDate = `${startArray[2]}-${startArray[3]}-${startArray[1]}`; + } + if (currentMalAnime.my_list_status.finish_date !== "") { + const finishArray = re.exec( + currentMalAnime.my_list_status.finish_date, + ); + finishDate = `${finishArray[2]}-${finishArray[3]}-${finishArray[1]}`; + } AddAnimeServiceToTable({ id: `m-${currentMalAnime.id}`, title: currentMalAnime.title, @@ -252,8 +288,8 @@ 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, + startedAt: startDate, + completedAt: finishDate, score: currentMalAnime.my_list_status.score, repeat: currentMalAnime.my_list_status .num_times_rewatched, @@ -414,7 +450,6 @@ } -/B

{title} @@ -559,34 +594,16 @@ class="text-left block mb-2 text-sm font-medium text-white" >Date Started -
-
- -
- - -
+
-
-
- -
- -
+