Navbar.tsx 995 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import useStore from '../store';
  3. import useActions from '../actions';
  4. import NavbarComponent from '../components/Navbar';
  5. import Search from '../components/Search';
  6. import Annotations from '../components/Annotations';
  7. import Thumbnails from './Thumbnails';
  8. const Navbar: React.FunctionComponent = () => {
  9. const [{ navbarState }, dispatch] = useStore();
  10. const { switchNavbar } = useActions(dispatch);
  11. const onClick = (state: string): void => {
  12. if (state === navbarState) {
  13. switchNavbar('');
  14. } else {
  15. switchNavbar(state);
  16. }
  17. };
  18. const transferProps = (role: string): any => ({
  19. isActive: navbarState === role,
  20. close: (): void => { onClick(''); },
  21. });
  22. return (
  23. <NavbarComponent
  24. onClick={onClick}
  25. navbarState={navbarState}
  26. >
  27. <Search {...transferProps('search')} />
  28. <Annotations {...transferProps('annotations')} />
  29. <Thumbnails />
  30. </NavbarComponent>
  31. );
  32. };
  33. export default Navbar;