diff options
| author | Fuwn <[email protected]> | 2023-12-03 15:43:05 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-03 15:43:05 -0800 |
| commit | 841b28a408df43b5380fa00388075a07129f7146 (patch) | |
| tree | 901c731e66c8d1f3a335148732f655be9a79be9f /src/lib/Tools | |
| parent | feat(wrapped): remove old colour preview (diff) | |
| download | due.moe-841b28a408df43b5380fa00388075a07129f7146.tar.xz due.moe-841b28a408df43b5380fa00388075a07129f7146.zip | |
feat(birthdays): add second birthday source
Diffstat (limited to 'src/lib/Tools')
| -rw-r--r-- | src/lib/Tools/CharacterBirthdays.svelte | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/src/lib/Tools/CharacterBirthdays.svelte b/src/lib/Tools/CharacterBirthdays.svelte index d1d03ed0..c012d65e 100644 --- a/src/lib/Tools/CharacterBirthdays.svelte +++ b/src/lib/Tools/CharacterBirthdays.svelte @@ -1,33 +1,71 @@ -<script> - import { ACDBBirthdays } from '$lib/ACDB'; +<script lang="ts"> + import { ACDBBirthdays, type ACDBBirthday } from '$lib/ACDB'; + import { aniSearchBirthdays, type aniSearchBirthday } from '$lib/Birthday/aniSearch'; import Error from '$lib/Error.svelte'; + import { onMount } from 'svelte'; + + interface Birthday { + name: string; + image: string; + origin?: string; + } let date = new Date(); + let month = date.getMonth() + 1; + let day = date.getDate(); + let anisearchBirthdays: Promise<aniSearchBirthday[]>; + + onMount(async () => { + anisearchBirthdays = aniSearchBirthdays(month, day); + }); + + const combineBirthdaySources = ( + acdbArray: ACDBBirthday[], + aniSearchArray: aniSearchBirthday[] + ): Birthday[] => + Array.from( + new Map( + [ + ...aniSearchArray.map((entry) => ({ + name: entry.name, + image: entry.image + })), + ...acdbArray.map((entry) => ({ + name: entry.name, + image: entry.character_image, + origin: entry.origin + })) + ].map((entry) => [entry.name, entry]) + ).values() + ); </script> -{#await ACDBBirthdays(date.getMonth() + 1, date.getDate())} - <p>Loading ...</p> -{:then birthdays} - <p> - This tool does not use AniList's API, so it will have more characters than AniList, but also - some unexpected characters which may not be present in AniList. - </p> +{#await ACDBBirthdays(month, day)} + <p>Loading set one ...</p> +{:then acdbBirthdays} + {#await anisearchBirthdays} + <p>Loading set two ...</p> + {:then anisearch} + {@const birthdays = combineBirthdaySources(acdbBirthdays, anisearch)} - <div id="characters"> - {#each birthdays as birthday} - <div> - <a - href={`https://anilist.co/search/characters?search=${encodeURIComponent( - birthday.name - ).replace(/%20/g, '+')}`} - target="_blank" - > - {birthday.name} - <img src={birthday.character_image} alt="Character (Large)" class="character-image" /> - </a> - </div> - {/each} - </div> + <div id="characters"> + {#each birthdays as birthday} + <div> + <a + href={`https://anilist.co/search/characters?search=${encodeURIComponent( + birthday.name + ).replace(/%20/g, '+')}`} + target="_blank" + > + {birthday.name} + <img src={birthday.image} alt="Character (Large)" class="character-image" /> + </a> + </div> + {/each} + </div> + {:catch} + <Error type="Character" /> + {/await} {:catch} <Error type="Character" /> {/await} |