import { Button, Container } from 'react-bootstrap' import styles from './search.module.css' import SearchIcon from '../svgs/search-line.svg' import CloseIcon from '../svgs/close-line.svg' import { useEffect, useState } from 'react' import { Form, Input, Select, SubmitButton } from './form' import { useRouter } from 'next/router' export default function Search ({ sub }) { const router = useRouter() const [searching, setSearching] = useState(router.query.q) const [q, setQ] = useState(router.query.q || '') const [atBottom, setAtBottom] = useState() useEffect(() => { setAtBottom(Math.ceil(window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) window.onscroll = function (ev) { if (Math.ceil(window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) { setAtBottom(true) } else { setAtBottom(false) } } }, []) const search = async values => { let prefix = '' if (sub) { prefix = `/~${sub}` } if (values.q?.trim() !== '') { if (values.what === 'users') { await router.push({ pathname: '/users/search', query: { q, what: 'users' } }) return } if (values.what === '') delete values.what if (values.sort === '') delete values.sort if (values.when === '') delete values.when await router.push({ pathname: prefix + '/search', query: values }) } } const showSearch = atBottom || searching || router.query.q const filter = sub !== 'jobs' return ( <>