Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195<script lang="ts"> import { channelClient } from '$lib/rpc'; import { invalidateAll } from '$app/navigation';
let isOpen = $state(false); let frequency = $state(''); let description = $state(''); let loading = $state(false); let error = $state<string | null>(null);
async function handleSubmit(e: SubmitEvent) { e.preventDefault(); if (!frequency) return;
loading = true; error = null;
try { await channelClient.createChannel({ frequency, description }); // Reset form and close frequency = ''; description = ''; isOpen = false; // Refresh list await invalidateAll(); } catch (err: any) { console.error('Failed to create channel:', err); error = err.message || 'Creation failed'; } finally { loading = false; } }</script>
<div class="create-channel"> {#if !isOpen} <button class="toggle-btn" onclick={() => (isOpen = true)}> [ + CREATE NEW CHANNEL ] </button> {:else} <form onsubmit={handleSubmit} class="terminal-form"> <div class="form-header"> <span>NEW CHANNEL CONFIGURATION</span> <button type="button" class="close-btn" onclick={() => (isOpen = false)}>[X]</button> </div> <div class="input-group"> <label for="frequency">FREQUENCY:</label> <input id="frequency" type="text" bind:value={frequency} placeholder="e.g. 104.2 FM" required disabled={loading} autofocus /> </div>
<div class="input-group"> <label for="description">DESCRIPTION:</label> <input id="description" type="text" bind:value={description} placeholder="Channel tagline..." disabled={loading} /> </div>
{#if error} <div class="form-error">! ERROR: {error}</div> {/if}
<div class="form-actions"> <button type="submit" disabled={loading || !frequency}> {loading ? '[ PROCESSING... ]' : '[ INITIALIZE CHANNEL ]'} </button> </div> </form> {/if}</div>
<style> .create-channel { margin: 1rem; }
.toggle-btn { background: none; border: 1px solid var(--term-text); color: var(--term-text); padding: 0.5rem 1rem; font-family: var(--font-mono); cursor: pointer; font-weight: bold; }
.toggle-btn:hover { background: var(--term-text); color: var(--term-bg); box-shadow: 0 0 10px var(--term-text); }
.terminal-form { border: 1px solid var(--term-text); padding: 1rem; background: rgba(0, 255, 65, 0.05); }
.form-header { display: flex; justify-content: space-between; margin-bottom: 1rem; border-bottom: 1px dashed var(--term-dim); padding-bottom: 0.5rem; font-weight: bold; }
.close-btn { background: none; border: none; color: var(--term-dim); cursor: pointer; font-family: var(--font-mono); }
.close-btn:hover { color: red; }
.input-group { margin-bottom: 0.75rem; display: flex; flex-direction: column; }
label { font-size: 0.8rem; color: var(--term-dim); margin-bottom: 0.25rem; }
input { background: none; border: 1px solid var(--term-dim); color: var(--term-text); font-family: var(--font-mono); padding: 0.5rem; outline: none; }
input:focus { border-color: var(--term-text); box-shadow: 0 0 5px var(--term-text); }
.form-error { color: red; font-size: 0.8rem; margin-bottom: 1rem; }
.form-actions { display: flex; justify-content: flex-end; }
.form-actions button { background: none; border: 1px solid var(--term-text); color: var(--term-text); padding: 0.5rem 1rem; font-family: var(--font-mono); cursor: pointer; font-weight: bold; }
.form-actions button:hover:not(:disabled) { background: var(--term-text); color: var(--term-bg); }
.form-actions button:disabled { color: var(--term-dim); border-color: var(--term-dim); cursor: not-allowed; }</style>