Show spinner when joining room

This commit is contained in:
Jon Staab 2025-02-13 15:34:14 -08:00
parent 07dd1e97dc
commit c089812363

View file

@ -50,8 +50,12 @@
const joinRoom = async () => { const joinRoom = async () => {
if (hasNip29($relay)) { if (hasNip29($relay)) {
joiningRoom = true
const message = await getThunkError(nip29.joinRoom(url, room)) const message = await getThunkError(nip29.joinRoom(url, room))
joiningRoom = false
if (message && !message.includes("already")) { if (message && !message.includes("already")) {
return pushToast({theme: "error", message}) return pushToast({theme: "error", message})
} }
@ -126,7 +130,8 @@
const scrollToBottom = () => element?.scrollTo({top: 0, behavior: "smooth"}) const scrollToBottom = () => element?.scrollTo({top: 0, behavior: "smooth"})
let loading = $state(true) let joiningRoom = $state(false)
let loadingEvents = $state(true)
let share = $state(popKey<TrustedEvent | undefined>("share")) let share = $state(popKey<TrustedEvent | undefined>("share"))
let parent: TrustedEvent | undefined = $state() let parent: TrustedEvent | undefined = $state()
let element: HTMLElement | undefined = $state() let element: HTMLElement | undefined = $state()
@ -202,7 +207,7 @@
subscriptionFilters: [{kinds: [DELETE, REACTION, MESSAGE], "#h": [room], since: now()}], subscriptionFilters: [{kinds: [DELETE, REACTION, MESSAGE], "#h": [room], since: now()}],
initialEvents: getEventsForUrl(url, [{...filter, limit: 20}]), initialEvents: getEventsForUrl(url, [{...filter, limit: 20}]),
onExhausted: () => { onExhausted: () => {
loading = false loadingEvents = false
}, },
})) }))
}) })
@ -238,8 +243,12 @@
Leave Room Leave Room
</Button> </Button>
{:else} {:else}
<Button class="btn btn-neutral btn-sm" onclick={joinRoom}> <Button class="btn btn-neutral btn-sm" disabled={joiningRoom} onclick={joinRoom}>
{#if joiningRoom}
<span class="loading loading-spinner loading-sm"></span>
{:else}
<Icon icon="login-2" /> <Icon icon="login-2" />
{/if}
Join Room Join Room
</Button> </Button>
{/if} {/if}
@ -271,8 +280,8 @@
{/if} {/if}
{/each} {/each}
<p class="flex h-10 items-center justify-center py-20"> <p class="flex h-10 items-center justify-center py-20">
{#if loading} {#if loadingEvents}
<Spinner loading>Looking for messages...</Spinner> <Spinner loading={loadingEvents}>Looking for messages...</Spinner>
{:else} {:else}
<Spinner>End of message history</Spinner> <Spinner>End of message history</Spinner>
{/if} {/if}