summaryrefslogtreecommitdiff
path: root/ui/lib/components/CreateChannelForm.svelte
blob: 8fab4c403b99a6641e8e0525ca6651ec1d1a5497 (plain)
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
<script>
  import { createChannel } from '$lib/apiServer';

  let name = $state('');
  let disabled = $state(false);

  async function handleSubmit(event) {
    event.preventDefault();
    disabled = true;
    const response = await createChannel(name);
    if (200 <= response.status && response.status < 300) {
      name = '';
    }
    disabled = false;
  }
</script>

<form onsubmit={handleSubmit}>
  <input
    type="text"
    placeholder="create channel"
    bind:value={name}
    {disabled}
  />
  <button type="submit">&#x2795;</button>
</form>