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

65 lines
2 KiB
Svelte
Raw Normal View History

2024-08-16 18:12:14 +00:00
<script lang="ts">
import {page} from "$app/stores"
2024-10-08 18:39:16 +00:00
import {WRAP} from "@welshman/util"
import {Router} from "@welshman/router"
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"
2024-12-11 00:38:22 +00:00
import {chatSearch} from "@app/state"
import {pullConservatively} from "@app/requests"
2024-10-08 18:39:16 +00:00
import {pushModal} from "@app/modal"
2025-02-04 00:37:14 +00:00
interface Props {
children?: import("svelte").Snippet
}
const {children}: Props = $props()
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!]}],
2025-04-09 22:32:18 +00:00
relays: Router.get().UserInbox().getUrls(),
})
2025-02-04 00:37:14 +00:00
let term = $state("")
2024-10-04 00:04:00 +00:00
const chats = $derived($chatSearch.searchOptions(term))
2024-08-16 18:12:14 +00:00
</script>
<SecondaryNav>
<SecondaryNavSection>
2024-10-21 21:03:36 +00:00
<SecondaryNavHeader>
Chats
<Button onclick={startChat}>
2024-10-21 21:03:36 +00:00
<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}
2025-02-04 00:37:14 +00:00
{@render children?.()}
{/key}
2024-08-16 18:12:14 +00:00
</Page>