aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/FollowFix.svelte
blob: de7a7863cf024cd6855eaa4d777bf01f59d30732 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<script lang="ts">
	import { toggleFollow } from '$lib/AniList/follow';
	import type { AniListAuthorisation } from '$lib/AniList/identity';

	export let user: AniListAuthorisation;

	let input = '';
	let submit = '';
</script>

{#if user === undefined}
	Please log in to view this page.
{:else}
	<p>
		<input
			type="text"
			minlength="1"
			placeholder="Username"
			bind:value={input}
			on:keypress={(e) => {
				if (e.key === 'Enter') {
					submit = input;

					// eslint-disable-next-line no-undef
					umami.track('Fix Follow');
				}
			}}
		/>
		<a href={'#'} on:click={() => (submit = input)}>
			Toggle follow for {input.length === 0 ? '...' : input}
		</a>
	</p>

	{#if submit.length > 0}
		{#await toggleFollow(user, submit)}
			Toggling follow ...
		{:then response}
			<p>
				Successfully toggled follow for {submit}.

				{submit}
				{response.isFollower ? 'is' : 'is not'} following you, {response.isFollowing
					? 'but'
					: 'and'} you {response.isFollowing ? 'are' : 'are not'} following them.
			</p>
		{:catch}
			<p>Failed to toggle follow for {submit}.</p>
		{/await}
	{/if}
{/if}