~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/spaces-bookclub

Book club: a Svelte demo app for atproto spaces (@atproto/lex-space)

0
0
main
48 lines · 1.2 KB Raw History
<script lang="ts">
  import type { SpaceRefString } from '@atproto/lex'
  import Input from '../atoms/Input.svelte'
  import Field from '../molecules/Field.svelte'
  import ActionDialog from './ActionDialog.svelte'
  import type { BookClubApp } from '../../lib/atproto.ts'
  import { clubFromInviteLink } from '../../lib/invite.ts'

  let {
    open = $bindable(false),
    app,
    onjoined,
  }: { open?: boolean; app: BookClubApp; onjoined: (uri: SpaceRefString) => void } = $props()

  let invite = $state('')

  $effect(() => {
    if (open) invite = ''
  })

  async function join() {
    const uri = clubFromInviteLink(invite)
    if (!uri) throw new Error('That isn’t a book club invite link.')
    onjoined(await app.join(uri))
  }
</script>

<ActionDialog
  bind:open
  title="Join a club"
  description="Paste the invite link a club’s host shared with you. They need to have added you as a member first."
  submitLabel="Join club"
  submitIcon="log-in"
  onsubmit={join}
>
  <Field label="Invite link">
    {#snippet children(id)}
      <Input
        {id}
        bind:value={invite}
        type="url"
        placeholder="{window.location.origin}/join/…"
        required
        spellcheck={false}
      />
    {/snippet}
  </Field>
</ActionDialog>