import './search.css'; import { useEffect, useRef, useState } from 'preact/hooks'; import { useSearchParams } from 'react-router-dom'; import Avatar from '../components/avatar'; import Link from '../components/link'; import Menu from '../components/menu'; import NameText from '../components/name-text'; import Status from '../components/status'; import { api } from '../utils/api'; function Search() { const { masto, instance, authenticated } = api(); const [searchParams, setSearchParams] = useSearchParams(); const searchFieldRef = useRef(); const q = searchParams.get('q'); const [statusResults, setStatusResults] = useState([]); const [accountResults, setAccountResults] = useState([]); useEffect(() => { if (q) { searchFieldRef.current.value = q; (async () => { const results = await masto.v2.search({ q, limit: 20, resolve: authenticated, }); console.log(results); setStatusResults(results.statuses); setAccountResults(results.accounts); })(); } }, [q]); console.log({ accountResults }); return (
{ e.preventDefault(); const { q } = e.target; if (q.value) { setSearchParams({ q: q.value }); } }} >

Accounts

{accountResults.length > 0 && (
    {accountResults.map((account) => (
  • ))}
)}

Posts

{statusResults.length > 0 && (
    {statusResults.map((status) => (
  • ))}
)}
); } export default Search;