From d210d464ac22e4dcbe9c19d18c46ef3e2e10147f Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 14 Jan 2024 22:19:59 -0800
Subject: feat(tools): likes

---
 src/lib/Tools/Likes.svelte | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 src/lib/Tools/Likes.svelte

(limited to 'src/lib/Tools/Likes.svelte')

diff --git a/src/lib/Tools/Likes.svelte b/src/lib/Tools/Likes.svelte
new file mode 100644
index 00000000..e54923bb
--- /dev/null
+++ b/src/lib/Tools/Likes.svelte
@@ -0,0 +1,46 @@
+<script lang="ts">
+	import { activityLikes } from '$lib/AniList/activity';
+	import { threadLikes } from '$lib/AniList/forum';
+	import RateLimited from '$lib/Error/RateLimited.svelte';
+	import InputTemplate from './InputTemplate.svelte';
+
+	let submission = '';
+
+	$: normalisedSubmission = submission.replace(/.*\/(activity|thread)\/(\d+).*/, '$2');
+	$: submissionType = submission.replace(/.*\/(activity|thread)\/(\d+).*/, '$1');
+	$: likesPromise =
+		submissionType === 'activity'
+			? activityLikes(Number(normalisedSubmission))
+			: threadLikes(Number(normalisedSubmission));
+</script>
+
+<InputTemplate
+	field="Activity or Thread URL"
+	bind:submission
+	event="Get All Likes"
+	submitText="Get All Likes"
+>
+	{#if submission.match(/https:\/\/anilist.co\/(activity|forum\/thread)\/\d+/)}
+		{#await likesPromise}
+			Loading {submissionType} ... 50%
+		{:then likes}
+			{#if likes && likes.length > 0}
+				<ul>
+					{#each likes as like}
+						<li>
+							<a href={`https://anilist.co/user/${like.name}`} target="_blank">
+								{like.name}
+							</a>
+						</li>
+					{/each}
+				</ul>
+			{:else}
+				No likes were found for that {submissionType}.
+			{/if}
+		{:catch}
+			<RateLimited type="Likes" list={false} />
+		{/await}
+	{:else}
+		Please enter a valid Activity or Thread URL.
+	{/if}
+</InputTemplate>
-- 
cgit v1.2.3

