| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { useState, WPElement } from '@wordpress/element'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies. |
| 8 |
*/ |
| 9 |
import { useApiSearch } from '../../api-search'; |
| 10 |
import { facets } from '../config'; |
| 11 |
import Facet from './facets/facet'; |
| 12 |
import SearchTermFacet from './facets/search-term-facet'; |
| 13 |
import Results from './layout/results'; |
| 14 |
import Sidebar from './layout/sidebar'; |
| 15 |
import Toolbar from './layout/toolbar'; |
| 16 |
import ActiveConstraints from './tools/active-constraints'; |
| 17 |
import ClearConstraints from './tools/clear-constraints'; |
| 18 |
import SidebarToggle from './tools/sidebar-toggle'; |
| 19 |
import Sort from './tools/sort'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Search dialog. |
| 23 |
* |
| 24 |
* @returns {WPElement} Component element. |
| 25 |
*/ |
| 26 |
export default () => { |
| 27 |
const { isLoading } = useApiSearch(); |
| 28 |
|
| 29 |
const [isSidebarOpen, setIsSidebarOpen] = useState(false); |
| 30 |
|
| 31 |
/** |
| 32 |
* Sidebar toggle click handler. |
| 33 |
* |
| 34 |
* @returns {void} |
| 35 |
*/ |
| 36 |
const onClickSidebarToggle = () => { |
| 37 |
setIsSidebarOpen(!isSidebarOpen); |
| 38 |
}; |
| 39 |
|
| 40 |
return ( |
| 41 |
<div className={`ep-search-page ${isLoading ? 'is-loading' : ''}`}> |
| 42 |
<div className="ep-search-page__header"> |
| 43 |
<SearchTermFacet /> |
| 44 |
|
| 45 |
<Toolbar> |
| 46 |
<ActiveConstraints /> |
| 47 |
<ClearConstraints /> |
| 48 |
<SidebarToggle isOpen={isSidebarOpen} onClick={onClickSidebarToggle} /> |
| 49 |
</Toolbar> |
| 50 |
</div> |
| 51 |
|
| 52 |
<div className="ep-search-page__body"> |
| 53 |
<Sidebar isOpen={isSidebarOpen}> |
| 54 |
<Sort /> |
| 55 |
{facets.map(({ label, name, postTypes, type }, index) => ( |
| 56 |
<Facet |
| 57 |
index={index} |
| 58 |
key={name} |
| 59 |
label={label} |
| 60 |
name={name} |
| 61 |
postTypes={postTypes} |
| 62 |
type={type} |
| 63 |
/> |
| 64 |
))} |
| 65 |
</Sidebar> |
| 66 |
|
| 67 |
<Results /> |
| 68 |
</div> |
| 69 |
</div> |
| 70 |
); |
| 71 |
}; |
| 72 |
|