flotilla/src/routes/chat/+layout.svelte

59 lines
1.9 KiB
Svelte
Raw Normal View History

2024-08-16 18:12:14 +00:00
<script lang="ts">
import {page} from "$app/stores"
2024-11-14 00:14:05 +00:00
import {ctx} from "@welshman/lib"
2024-10-08 18:39:16 +00:00
import {WRAP} from "@welshman/util"
import {pubkey} from "@welshman/app"
2024-08-16 18:12:14 +00:00
import Icon from "@lib/components/Icon.svelte"
import Page from "@lib/components/Page.svelte"
2024-10-03 22:28:06 +00:00
import Button from "@lib/components/Button.svelte"
import Spinner from "@lib/components/Spinner.svelte"
2024-08-16 18:12:14 +00:00
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
import SecondaryNavHeader from "@lib/components/SecondaryNavHeader.svelte"
import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte"
2024-10-03 22:28:06 +00:00
import ChatStart from "@app/components/ChatStart.svelte"
import ChatItem from "@app/components/ChatItem.svelte"
import {chatSearch, pullConservatively} from "@app/state"
2024-10-08 18:39:16 +00:00
import {pushModal} from "@app/modal"
2024-10-03 22:28:06 +00:00
const startChat = () => pushModal(ChatStart)
2024-10-04 00:04:00 +00:00
const promise = pullConservatively({
2024-11-14 00:14:05 +00:00
filters: [{kinds: [WRAP], "#p": [$pubkey!]}],
relays: ctx.app.router.UserInbox().getUrls(),
})
2024-10-04 00:04:00 +00:00
let term = ""
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
2024-08-16 18:12:14 +00:00
</script>
<SecondaryNav>
<SecondaryNavSection>
2024-10-21 21:03:36 +00:00
<SecondaryNavHeader>
Chats
<Button on:click={startChat}>
<Icon icon="add-circle" />
</Button>
</SecondaryNavHeader>
2024-10-04 00:04:00 +00:00
</SecondaryNavSection>
2024-10-21 21:03:36 +00:00
<label class="input input-sm input-bordered mx-6 -mt-4 mb-2 flex items-center gap-2">
2024-10-04 00:04:00 +00:00
<Icon icon="magnifer" />
<input bind:value={term} class="grow" type="text" />
</label>
2024-11-14 20:16:44 +00:00
<div class="overflow-auto">
{#each chats as { id, pubkeys, messages } (id)}
<ChatItem {id} {pubkeys} {messages} />
{/each}
{#await promise}
<div class="border-t border-solid border-base-100 px-6 py-4 text-xs">
<Spinner loading>Loading conversations...</Spinner>
</div>
{/await}
</div>
2024-08-16 18:12:14 +00:00
</SecondaryNav>
<Page>
{#key $page.url.pathname}
<slot />
{/key}
2024-08-16 18:12:14 +00:00
</Page>