TicketsState
Reactive list of the identified customer's tickets. The tickets, isLoading, error, and hasMore fields update as the fetch resolves.
Usage
src/routes/help/+page.svelte
<script>
import { TicketsState } from '@cstar.help/svelte';
// Pulls the identified customer's full ticket list from the chat provider.
const tix = new TicketsState();
// Client-side filter — TicketsState fetches the full list, no server-side params.
const open = $derived(tix.tickets.filter((t) => t.status === 'open'));
async function newTicket() {
await tix.create({ title: 'Need help with my account' });
// create() prepends the new ticket to .tickets — no manual refresh needed.
}
</script>
{#if tix.isLoading}
<p>Summoning tickets...</p>
{:else if tix.error}
<p>Couldn't load — try again?</p>
{:else}
<button onclick={newTicket}>New ticket</button>
<ul>
{#each open as t (t.id)}
<li>{t.title}</li>
{/each}
</ul>
<button onclick={() => tix.refresh()} disabled={tix.isLoading}>Refresh</button>
{/if}Cleanup
TicketsState doesn't open subscriptions, so there's nothing to tear down — no destroy() call needed. (Compare with MessagesState and TypingState, which do subscribe to realtime and require onDestroy(() => state.destroy()).)