import SearchBar, { TSearchBarRef } from '@/components/SearchBar' import SearchResult from '@/components/SearchResult' import PrimaryPageLayout, { TPrimaryPageLayoutRef } from '@/layouts/PrimaryPageLayout' import { usePrimaryPage } from '@/PageManager' import { TSearchParams } from '@/types' import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react' const SearchPage = forwardRef((_, ref) => { const { current, display } = usePrimaryPage() const [input, setInput] = useState('') const [searchParams, setSearchParams] = useState(null) const isActive = useMemo(() => current === 'search' && display, [current, display]) const searchBarRef = useRef(null) const layoutRef = useRef(null) useImperativeHandle( ref, () => ({ scrollToTop: (behavior: ScrollBehavior = 'smooth') => layoutRef.current?.scrollToTop(behavior) }), [] ) useEffect(() => { if (isActive && !searchParams) { searchBarRef.current?.focus() } }, [isActive, searchParams]) const onSearch = (params: TSearchParams | null) => { setSearchParams(params) if (params?.input) { setInput(params.input) } layoutRef.current?.scrollToTop('instant') } return (
Search Nostr
) }) SearchPage.displayName = 'SearchPage' export default SearchPage