flotilla/src/routes/home/chats/+page.svelte

57 lines
1.8 KiB
Svelte
Raw Normal View History

2024-10-09 23:11:23 +00:00
<script lang="ts">
import {onMount} from "svelte"
import {ctx, ago} from "@welshman/lib"
2024-10-09 23:11:23 +00:00
import {WRAP} from "@welshman/util"
import {pubkey, subscribe} from "@welshman/app"
import {fly} from "@lib/transition"
import Icon from "@lib/components/Icon.svelte"
2024-10-18 16:53:35 +00:00
import Button from "@lib/components/Button.svelte"
import ChatItem from "@app/components/ChatItem.svelte"
2024-10-18 16:53:35 +00:00
import ChatStart from "@app/components/ChatStart.svelte"
2024-10-09 23:11:23 +00:00
import {chatSearch, pullConservatively} from "@app/state"
2024-10-18 16:53:35 +00:00
import {pushModal} from "@app/modal"
2024-10-09 23:11:23 +00:00
let term = ""
2024-10-18 16:53:35 +00:00
const startChat = () => pushModal(ChatStart)
2024-10-09 23:11:23 +00:00
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
onMount(() => {
const filter = {kinds: [WRAP], "#p": [$pubkey!]}
const sub = subscribe({filters: [{...filter, since: ago(30)}]})
pullConservatively({
filters: [filter],
relays: ctx.app.router.InboxRelays().getUrls(),
})
return () => sub.close()
})
</script>
<div class="content column gap-2">
2024-10-18 16:53:35 +00:00
<div class="row-2 min-w-0 items-center">
<label class="input input-bordered flex flex-grow items-center gap-2" in:fly={{delay: 250}}>
<Icon icon="magnifer" />
<input bind:value={term} class="grow" type="text" placeholder="Search for conversations..." />
</label>
<Button class="btn btn-primary" on:click={startChat}>
<Icon icon="add-circle" />
</Button>
</div>
2024-10-09 23:15:09 +00:00
<div class="column gap-2 overflow-auto">
2024-10-15 19:02:11 +00:00
{#each chats as { id, pubkeys, messages } (id)}
<ChatItem {id} {pubkeys} {messages} />
2024-10-18 16:53:35 +00:00
{:else}
<div class="py-20 max-w-sm col-4 items-center m-auto text-center">
<p>No chats found! Try starting one up.</p>
<Button class="btn btn-primary" on:click={startChat}>
<Icon icon="add-circle" />
Start a Chat
</Button>
</div>
2024-10-09 23:11:23 +00:00
{/each}
</div>
</div>