forked from coracle/flotilla
72 lines
2.2 KiB
Svelte
72 lines
2.2 KiB
Svelte
<script lang="ts">
|
|
import {onMount} from "svelte"
|
|
import {ctx} from "@welshman/lib"
|
|
import {WRAP} from "@welshman/util"
|
|
import type {TrustedEvent} from "@welshman/util"
|
|
import {pubkey, repository} from "@welshman/app"
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
import Page from "@lib/components/Page.svelte"
|
|
import Button from "@lib/components/Button.svelte"
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
|
import SecondaryNavHeader from "@lib/components/SecondaryNavHeader.svelte"
|
|
import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte"
|
|
import ChatStart from "@app/components/ChatStart.svelte"
|
|
import ChatItem from "@app/components/ChatItem.svelte"
|
|
import {chatSearch, pullConservatively, ensureUnwrapped} from "@app/state"
|
|
import {pushModal} from "@app/modal"
|
|
|
|
const startChat = () => pushModal(ChatStart)
|
|
|
|
const promise = pullConservatively({
|
|
filters: [{kinds: [WRAP], "#p": [$pubkey!]}],
|
|
relays: ctx.app.router.UserInbox().getUrls(),
|
|
})
|
|
|
|
const onUpdate = ({added}: {added: TrustedEvent[]}) => {
|
|
for (const event of added) {
|
|
ensureUnwrapped(event)
|
|
}
|
|
}
|
|
|
|
let term = ""
|
|
|
|
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
|
|
|
|
onMount(() => {
|
|
repository.on("update", onUpdate)
|
|
|
|
return () => {
|
|
repository.off("update", onUpdate)
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<SecondaryNav>
|
|
<SecondaryNavSection>
|
|
<SecondaryNavHeader>
|
|
Chats
|
|
<Button on:click={startChat}>
|
|
<Icon icon="add-circle" />
|
|
</Button>
|
|
</SecondaryNavHeader>
|
|
</SecondaryNavSection>
|
|
<label class="input input-sm input-bordered mx-6 -mt-4 mb-2 flex items-center gap-2">
|
|
<Icon icon="magnifer" />
|
|
<input bind:value={term} class="grow" type="text" />
|
|
</label>
|
|
<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>
|
|
</SecondaryNav>
|
|
<Page>
|
|
<slot />
|
|
</Page>
|