<script>
    import { createChannel } from '../apiServer';

    import { channelsList } from '../store';

    let name = '';
    let disabled = false;

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

<form on:submit={handleSubmit}>
    <input type="text" placeholder="channel name" bind:value={name} disabled={disabled} />
    <button type="submit">create</button>
</form>

<style>
</style>
