johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
<script lang="ts">
import type * as followActor from '#lib/lexicons/dev/knotless/followActor.ts';
import type * as unfollowActor from '#lib/lexicons/dev/knotless/unfollowActor.ts';
import type { DidString } from '@atproto/lex';
import { call } from '#lib/data.ts';
import { LOGIN } from '#lib/login.ts';
/**
* Following the account `did` as whoever is `in`, its `following` record
* if they do, and telling `followed` how many follow it after: for
* anyone else, the way to log in first.
*/
let {
did,
following,
in: logged,
followed
}: { did: string; following?: string; in: boolean; followed: (count: number) => void } = $props();
let mine = $derived(following);
let busy = $state(false);
async function toggle() {
busy = true;
const input = { subject: did as DidString };
const nsid = mine ? 'dev.knotless.unfollowActor' : 'dev.knotless.followActor';
const state = await call<typeof followActor.main | typeof unfollowActor.main>(
nsid,
input
).catch(() => null);
if (state) {
mine = state.following;
followed(state.followersCount);
}
busy = false;
}
</script>
{#if logged}
<button
class="btn follow"
type="button"
aria-pressed={!!mine}
disabled={busy}
aria-busy={busy}
onclick={toggle}>{mine ? 'Unfollow' : 'Follow'}</button
>
{:else}
<button class="btn follow" type="button" popovertarget={LOGIN}>Follow</button>
{/if}