import { Input, Tab, TabPanel, Tabs, TabsBody, TabsHeader } from '@material-tailwind/react' import { Entity, MegalodonInterface } from 'megalodon' import { useRouter } from 'next/router' import { FormEvent, useEffect, useState } from 'react' import { FaMagnifyingGlass } from 'react-icons/fa6' import { FormattedMessage, useIntl } from 'react-intl' import Statuses from './search/Statuses' import { Account } from '@/db' import Accounts from './search/Accounts' import Hashtags from './search/Hashtags' type Props = { client: MegalodonInterface account: Account openMedia: (media: Array, index: number) => void } export default function Search(props: Props) { const router = useRouter() const { formatMessage } = useIntl() const [query, setQuery] = useState('') const [activeTab, setActiveTab] = useState('statuses') const [results, setResults] = useState({ accounts: [], hashtags: [], statuses: [] }) const [loading, setLoading] = useState(false) useEffect(() => { if (router.query.q) { setQuery(router.query.q as string) search(router.query.q as string) } }, [router.query.q]) const search = (query: string) => { setLoading(true) setResults({ accounts: [], hashtags: [], statuses: [] }) props.client .search(query) .then(res => { setResults(res.data) }) .finally(() => { setLoading(false) }) } const submit = (ev: FormEvent) => { ev.preventDefault() const word = ((ev.target as HTMLFormElement).elements[0] as HTMLInputElement).value if (word.length > 0) { router.push({ query: Object.assign({}, router.query, { timeline: 'search', q: word }) }) } } return ( <>
submit(ev)}> setQuery(e.target.value)} icon={} />
setActiveTab('statuses')}> setActiveTab('accounts')}> setActiveTab('hashtags')}>
) }