aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/FollowFix.svelte
blob: b9fddeff243d4d58e19615e2f7a5a9d4bcf80504 (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
51
52
<script lang="ts">
  import { toggleFollow } from '$lib/Data/AniList/follow';
  import type { AniListAuthorisation } from '$lib/Data/AniList/identity';
  import LogInRestricted from '$lib/Error/LogInRestricted.svelte';

  export let user: AniListAuthorisation;

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

{#if user === undefined}
  <LogInRestricted />
{:else}
  <p>
    <!-- svelte-ignore missing-declaration -->
    <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}