@@ -8,20 +8,29 @@ import {Bot} from '../info-panel/bot'
88
99type Props = { teamID ?: T . Teams . TeamID }
1010
11- const renderSectionHeader = ( { section} : { section : { title : string } } ) => {
11+ const renderSectionHeader = ( { section} : { section : { title ? : string } } ) => {
1212 return < Kb . SectionDivider label = { section . title } />
1313}
1414
15- const userEmptyPlaceholder = '---EMPTYUSERS---'
16- const resultEmptyPlaceholder = '---EMPTYRESULT---'
15+ const userEmptyPlaceholder = '---EMPTYUSERS---' as const
16+ const resultEmptyPlaceholder = '---EMPTYRESULT---' as const
17+
18+ type Item =
19+ | { type : 'bot' ; bot : T . RPCGen . FeaturedBot }
20+ | { type : 'str' ; str : string }
21+ | { type : 'dummy' ; value : typeof userEmptyPlaceholder | typeof resultEmptyPlaceholder }
22+ type Section = Omit < Kb . SectionType < Item > , 'title' > & { title : string }
1723
1824const SearchBotPopup = ( props : Props ) => {
1925 const conversationIDKey = C . useChatContext ( s => s . id )
2026 const teamID = props . teamID
2127 const [ lastQuery , setLastQuery ] = React . useState ( '' )
2228 const featuredBotsMap = C . useBotsState ( s => s . featuredBotsMap )
2329 const botSearchResults = C . useBotsState ( s => s . botSearchResults )
24- const waiting = C . Waiting . useAnyWaiting ( [ C . Bots . waitingKeyBotSearchUsers , C . Bots . waitingKeyBotSearchFeatured ] )
30+ const waiting = C . Waiting . useAnyWaiting ( [
31+ C . Bots . waitingKeyBotSearchUsers ,
32+ C . Bots . waitingKeyBotSearchFeatured ,
33+ ] )
2534 const clearModals = C . useRouterState ( s => s . dispatch . clearModals )
2635 const onClose = ( ) => {
2736 clearModals ( )
@@ -52,60 +61,66 @@ const SearchBotPopup = (props: Props) => {
5261 getFeaturedBots ( )
5362 } )
5463
55- const botData : Array < T . RPCGen . FeaturedBot | string > =
64+ const botData : Array < Item > =
5665 lastQuery . length > 0
57- ? botSearchResults . get ( lastQuery ) ?. bots . slice ( ) ?? [ ]
58- : C . Bots . getFeaturedSorted ( featuredBotsMap )
66+ ? ( botSearchResults
67+ . get ( lastQuery )
68+ ?. bots . slice ( )
69+ . map ( bot => ( { bot, type : 'bot' } ) as const ) ?? [ ] )
70+ : C . Bots . getFeaturedSorted ( featuredBotsMap ) . map ( bot => ( { bot, type : 'bot' } ) )
5971 if ( ! botData . length && ! waiting ) {
60- botData . push ( resultEmptyPlaceholder )
72+ botData . push ( { type : 'dummy' , value : resultEmptyPlaceholder } )
6173 }
62- const botSection = {
74+ const botSection : Section = {
6375 data : botData ,
64- renderItem : ( { index, item} : { index : number ; item : T . RPCGen . FeaturedBot | string } ) => {
65- return item === resultEmptyPlaceholder ? (
76+ renderItem : ( { index, item} : { index : number ; item : Item } ) => {
77+ return item . type === 'dummy' && item . value === resultEmptyPlaceholder ? (
6678 < Kb . Text
6779 style = { { ...Styles . padding ( Styles . globalMargins . tiny , Styles . globalMargins . tiny ) } }
6880 type = "BodySmall"
6981 >
7082 No results were found
7183 </ Kb . Text >
72- ) : typeof item !== 'string ' ? (
73- < Bot { ...item } onClick = { onSelect } firstItem = { index === 0 } />
84+ ) : item . type === 'bot ' ? (
85+ < Bot { ...item . bot } onClick = { onSelect } firstItem = { index === 0 } />
7486 ) : null
7587 } ,
7688 title : 'Featured bots' ,
7789 }
78- const userData = ! lastQuery . length
79- ? [ userEmptyPlaceholder ]
80- : botSearchResults
81- . get ( lastQuery )
82- ?. users . filter ( u => ! featuredBotsMap . get ( u ) )
83- . slice ( 0 , 3 ) ?? [ ]
90+ const userData : Array < Item > = ! lastQuery . length
91+ ? [ { type : 'dummy' , value : userEmptyPlaceholder } as const ]
92+ : (
93+ botSearchResults
94+ . get ( lastQuery )
95+ ?. users . filter ( u => ! featuredBotsMap . get ( u ) )
96+ . slice ( 0 , 3 ) ?? [ ]
97+ ) . map ( str => ( { str, type : 'str' } ) as const )
98+
8499 if ( ! userData . length && ! waiting ) {
85- userData . push ( resultEmptyPlaceholder )
100+ userData . push ( { type : 'dummy' , value : resultEmptyPlaceholder } as const )
86101 }
87- const usersSection = {
102+ const usersSection : Section = {
88103 data : userData ,
89- renderItem : ( { item} : { item : string } ) => {
104+ renderItem : ( { item} : { item : Item } ) => {
90105 return (
91106 < Kb . Box2
92107 direction = "horizontal"
93108 fullWidth = { true }
94109 style = { { ...Styles . padding ( Styles . globalMargins . tiny , Styles . globalMargins . tiny ) } }
95110 >
96- { item === userEmptyPlaceholder ? (
111+ { item . type === 'dummy' && item . value === userEmptyPlaceholder ? (
97112 < Kb . Text type = "BodySmall" > Enter a bot username above</ Kb . Text >
98- ) : item === resultEmptyPlaceholder ? (
113+ ) : item . type === 'dummy' && item . value === resultEmptyPlaceholder ? (
99114 < Kb . Text type = "BodySmall" > No results were found</ Kb . Text >
100- ) : (
115+ ) : item . type === 'str' ? (
101116 < Kb . NameWithIcon
102- username = { item }
117+ username = { item . str }
103118 horizontal = { true }
104119 colorFollowing = { true }
105120 onClick = { onSelect }
106121 clickType = "onClick"
107122 />
108- ) }
123+ ) : null }
109124 </ Kb . Box2 >
110125 )
111126 } ,
0 commit comments