Handle drawer close

This commit is contained in:
Jon Staab
2024-10-15 14:44:21 -07:00
parent 903cd42650
commit cbf3d3566f
4 changed files with 17 additions and 8 deletions

View File

@@ -147,7 +147,7 @@
</div> </div>
{/if} {/if}
<button <button
class="join absolute -top-2 right-0 border border-solid border-neutral text-xs opacity-0 transition-all group-hover:opacity-100" class="join absolute top-1 right-1 border border-solid border-neutral text-xs opacity-0 transition-all group-hover:opacity-100"
on:click|stopPropagation> on:click|stopPropagation>
<ChannelMessageEmojiButton {url} {room} {event} /> <ChannelMessageEmojiButton {url} {room} {event} />
<Button class="btn join-item btn-xs" on:click={showInfo}> <Button class="btn join-item btn-xs" on:click={showInfo}>

View File

@@ -32,5 +32,6 @@ export const pushDrawer = (
export const clearModal = () => { export const clearModal = () => {
goto("#") goto("#")
modals.clear()
emitter.emit("close") emitter.emit("close")
} }

View File

@@ -24,7 +24,7 @@
</script> </script>
<div class="drawer drawer-end"> <div class="drawer drawer-end">
<input {id} type="checkbox" class="drawer-toggle" bind:this={input} /> <input {id} type="checkbox" class="drawer-toggle" bind:this={input} on:change />
<div class="drawer-content"> <div class="drawer-content">
<label for={id} bind:this={label} /> <label for={id} bind:this={label} />
</div> </div>

View File

@@ -62,7 +62,13 @@
} }
} }
let ready: Promise<unknown> const onDrawerClose = (e: any) => {
if (!e.target.checked) {
clearModal()
}
}
let ready: Promise<unknown> = Promise.resolve()
let dialog: HTMLDialogElement let dialog: HTMLDialogElement
let drawer: SvelteComponent let drawer: SvelteComponent
let modal: any let modal: any
@@ -156,10 +162,12 @@
if ($pubkey) { if ($pubkey) {
loadUserData($pubkey) loadUserData($pubkey)
} }
}
ready.then(async () => { ready.then(async () => {
await sleep(1) await sleep(1)
subs.push(
page.subscribe($page => { page.subscribe($page => {
modal = modals.get($page.url.hash.slice(1)) modal = modals.get($page.url.hash.slice(1))
@@ -178,8 +186,8 @@
dialog?.close() dialog?.close()
} }
}) })
}) )
} })
return () => { return () => {
for (const unsub of subs) { for (const unsub of subs) {
@@ -216,7 +224,7 @@
</form> </form>
{/if} {/if}
</dialog> </dialog>
<Drawer bind:this={drawer}> <Drawer bind:this={drawer} on:change={onDrawerClose}>
{#if modal && modal.options?.drawer} {#if modal && modal.options?.drawer}
{#key modal} {#key modal}
<svelte:component this={modal.component} {...modal.props} /> <svelte:component this={modal.component} {...modal.props} />