|
1 |
| -import React from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import { CategoriesMenu } from './categories/CategoriesMenu';
|
3 | 3 | import { ContentMenu } from './contents/ContentMenu';
|
4 | 4 | import { useAppState } from '../../state/useAppState';
|
5 | 5 | import { classNames } from '../../utils/classNames';
|
| 6 | +import { SearchInput } from './search/SearchInput'; |
| 7 | +import { SearchResult } from './search/search-result/SearchResult'; |
| 8 | +import { ContentSearchResult } from '../../../common/contentSearchResult'; |
6 | 9 |
|
7 | 10 | import style from './AppLeftSection.module.css';
|
8 | 11 |
|
9 | 12 | export const AppLeftSection = () => {
|
| 13 | + const [searchResult, setSearchResult] = useState<ContentSearchResult | null>(null); |
| 14 | + const [searchResultOpen, setSearchResultOpen] = useState(false); |
| 15 | + |
10 | 16 | const { selectedCategory, appContext, contentSelectorOpen } = useAppState();
|
11 | 17 | const { rootCategories } = appContext;
|
12 | 18 |
|
| 19 | + useEffect(() => { |
| 20 | + setSearchResultOpen(!!searchResult); |
| 21 | + }, [searchResult]); |
| 22 | + |
13 | 23 | return (
|
14 |
| - <div className={style.leftSection}> |
15 |
| - <div className={classNames(style.categoriesMenu, contentSelectorOpen && style.hidden)}> |
16 |
| - <CategoriesMenu rootCategories={rootCategories} /> |
| 24 | + <div className={style.root}> |
| 25 | + <div |
| 26 | + className={classNames( |
| 27 | + style.categoriesAndSearch, |
| 28 | + contentSelectorOpen && style.hidden |
| 29 | + )} |
| 30 | + > |
| 31 | + <SearchInput setSearchResult={setSearchResult} /> |
| 32 | + <div className={style.categoriesAndSearchResult}> |
| 33 | + <div |
| 34 | + className={classNames( |
| 35 | + style.categoriesMenu, |
| 36 | + searchResultOpen && style.hidden |
| 37 | + )} |
| 38 | + > |
| 39 | + <CategoriesMenu rootCategories={rootCategories} /> |
| 40 | + </div> |
| 41 | + <div className={classNames(style.searchResult, searchResultOpen && style.open)}> |
| 42 | + <SearchResult |
| 43 | + result={searchResult} |
| 44 | + close={() => setSearchResultOpen(false)} |
| 45 | + /> |
| 46 | + </div> |
| 47 | + </div> |
17 | 48 | </div>
|
18 |
| - <div className={classNames(style.contentsMenu, contentSelectorOpen && style.open)}> |
| 49 | + <div className={classNames(style.contentMenu, contentSelectorOpen && style.open)}> |
19 | 50 | {selectedCategory && <ContentMenu parentCategory={selectedCategory} />}
|
20 | 51 | </div>
|
21 | 52 | </div>
|
|
0 commit comments