import { createSignal, createEffect, onMount, onCleanup, Show, Switch, Match, type Component, } from 'solid-js'; import { useNavigate } from '@solidjs/router'; import { createVirtualizer } from '@tanstack/solid-virtual'; import uniq from 'lodash/uniq'; import Column from '@/components/Column'; import SideBar from '@/components/SideBar'; import Timeline from '@/components/Timeline'; import Notification from '@/components/Notification'; import ProfileDisplay from '@/components/ProfileDisplay'; import usePool from '@/nostr/usePool'; import useConfig from '@/nostr/useConfig'; import useSubscription from '@/nostr/useSubscription'; import useFollowings from '@/nostr/useFollowings'; import usePubkey from '@/nostr/usePubkey'; import { useMountShortcutKeys } from '@/hooks/useShortcutKeys'; import usePersistStatus from '@/hooks/usePersistStatus'; import useModalState from '@/hooks/useModalState'; import ensureNonNull from '@/utils/ensureNonNull'; import epoch from '@/utils/epoch'; const Home: Component = () => { useMountShortcutKeys(); const navigate = useNavigate(); const { persistStatus } = usePersistStatus(); const { modalState, closeModal } = useModalState(); const pool = usePool(); const { config } = useConfig(); const pubkey = usePubkey(); createEffect(() => { config().relayUrls.map(async (relayUrl) => { const relay = await pool().ensureRelay(relayUrl); relay.on('notice', (msg: string) => { console.error(`NOTICE: ${relayUrl}: ${msg}`); }); }); }); const { followingPubkeys } = useFollowings(() => ensureNonNull([pubkey()] as const)(([pubkeyNonNull]) => ({ relayUrls: config().relayUrls, pubkey: pubkeyNonNull, })), ); const { events: followingsPosts } = useSubscription(() => { const authors = uniq([...followingPubkeys()]); if (authors.length === 0) return null; return { relayUrls: config().relayUrls, filters: [ { kinds: [1, 6], authors, limit: 25, }, ], }; }); const { events: myPosts } = useSubscription(() => ensureNonNull([pubkey()] as const)(([pubkeyNonNull]) => ({ relayUrls: config().relayUrls, filters: [ { kinds: [1, 6], authors: [pubkeyNonNull], limit: 25, }, ], })), ); const { events: myReactions } = useSubscription(() => ensureNonNull([pubkey()] as const)(([pubkeyNonNull]) => ({ relayUrls: config().relayUrls, filters: [ { kinds: [7], authors: [pubkeyNonNull], limit: 25, }, ], })), ); const { events: notifications } = useSubscription(() => ensureNonNull([pubkey()] as const)(([pubkeyNonNull]) => ({ relayUrls: config().relayUrls, filters: [ { kinds: [1, 6, 7], '#p': [pubkeyNonNull], limit: 25, }, ], })), ); const { events: localTimeline } = useSubscription(() => ({ relayUrls: [ 'wss://relay-jp.nostr.wirednet.jp', 'wss://nostr.h3z.jp', 'wss://nostr.holybea.com', ], filters: [ { kinds: [1, 6], limit: 25, since: epoch() - 12 * 60 * 60, }, ], })); onMount(() => { if (!persistStatus().loggedIn) { navigate('/hello'); } }); return (
{(state) => ( {(pubkeyNonNull: string) => ( )} )}
); }; export default Home;