index.tsx raw
1 import client from '@/services/client.service'
2 import storage from '@/services/local-storage.service'
3 import { TSearchParams } from '@/types'
4 import NormalFeed from '../NormalFeed'
5 import Profile from '../Profile'
6 import { ProfileListBySearch } from '../ProfileListBySearch'
7 import Relay from '../Relay'
8 import RelayConfigurationRequired from '../RelayConfigurationRequired'
9
10 export default function SearchResult({ searchParams }: { searchParams: TSearchParams | null }) {
11 if (!searchParams) {
12 return null
13 }
14 if (searchParams.type === 'profile') {
15 return <Profile id={searchParams.search} />
16 }
17 if (searchParams.type === 'profiles') {
18 // Check if search relays are configured
19 if (!storage.hasCustomSearchRelays()) {
20 return (
21 <div className="p-4">
22 <RelayConfigurationRequired type="search" />
23 </div>
24 )
25 }
26 return <ProfileListBySearch search={searchParams.search} />
27 }
28 if (searchParams.type === 'notes') {
29 // Check if search relays are configured
30 const searchRelays = storage.getSearchRelays()
31 if (searchRelays.length === 0) {
32 return (
33 <div className="p-4">
34 <RelayConfigurationRequired type="search" />
35 </div>
36 )
37 }
38 return (
39 <NormalFeed
40 subRequests={[{ urls: searchRelays, filter: { search: searchParams.search } }]}
41 showRelayCloseReason
42 />
43 )
44 }
45 if (searchParams.type === 'hashtag') {
46 return (
47 <NormalFeed
48 subRequests={[{ urls: client.currentRelays, filter: { '#t': [searchParams.search] } }]}
49 showRelayCloseReason
50 />
51 )
52 }
53 if (searchParams.type === 'nak') {
54 return <NormalFeed subRequests={[searchParams.request]} showRelayCloseReason />
55 }
56 return <Relay url={searchParams.search} />
57 }
58