import ComponentAccount from '@components/Account' import ComponentHashtag from '@components/Hashtag' import ComponentSeparator from '@components/Separator' import CustomText from '@components/Text' import TimelineDefault from '@components/Timeline/Default' import { TabSharedStackScreenProps } from '@utils/navigation/navigators' import { useSearchQuery } from '@utils/queryHooks/search' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useCallback, useMemo } from 'react' import { Trans, useTranslation } from 'react-i18next' import { KeyboardAvoidingView, Platform, SectionList, StyleSheet, View } from 'react-native' import { Circle } from 'react-native-animated-spinkit' const TabSharedSearch: React.FC> = ({ route: { params: { text } } }) => { const { t } = useTranslation('screenTabs') const { colors } = useTheme() const mapKeyToTranslations = { accounts: t('shared.search.sections.accounts'), hashtags: t('shared.search.sections.hashtags'), statuses: t('shared.search.sections.statuses') } const { status, data } = useSearchQuery< { title: string translation: string data: any[] }[] >({ term: text, options: { enabled: text !== undefined, select: data => Object.keys(data as Mastodon.Results) .map(key => ({ title: key, // @ts-ignore translation: mapKeyToTranslations[key], // @ts-ignore data: data[key] })) .sort((a, b) => { if (!a.data.length) { return 1 } else if (!b.data.length) { return -1 } else { return 0 } }) } }) const listEmpty = useMemo(() => { return ( {status === 'loading' ? ( ) : ( <> }} /> {t('shared.search.empty.advanced.header')} @username@domain {' '} {t('shared.search.empty.advanced.example.account')} #example {' '} {t('shared.search.empty.advanced.example.hashtag')} URL {' '} {t('shared.search.empty.advanced.example.statusLink')} URL {' '} {t('shared.search.empty.advanced.example.accountLink')} )} ) }, [status]) const listItem = useCallback(({ item, section }: { item: any; section: any }) => { switch (section.title) { case 'accounts': return case 'hashtags': return case 'statuses': return default: return null } }, []) return ( ( {translation} )} renderSectionFooter={({ section: { data, translation } }) => !data.length ? ( }} /> ) : null } keyExtractor={(item, index) => item + index} SectionSeparatorComponent={ComponentSeparator} ItemSeparatorComponent={ComponentSeparator} /> ) } const styles = StyleSheet.create({ emptyAdvanced: { marginBottom: StyleConstants.Spacing.S } }) export default TabSharedSearch