All files / web/modules/navbar/components Navbar.tsx

45.83% Statements 11/24
100% Branches 2/2
0% Functions 0/4
57.89% Lines 11/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x 1x 1x 1x   1x 1x 1x   1x                               1x                                                                       1x  
import Menu, { ClickParam } from 'antd/lib/menu';
import * as React from 'react';
import { Query } from 'react-apollo';
import { compose } from 'redux';
import styled from 'styled-components';
import { ICategory } from '../../../../shared';
import Spin from '../../components/Spin';
import withRouter, { IWithRouterProps } from '../../hoc/withRouter';
import { NAVBAR_CATEGORIES } from '../queries';
 
const Root = styled.div`
  font-weight: 700;
 
  .ant-tabs-nav .ant-tabs-tab-active {
    font-weight: 700;
  }
 
  .ant-menu-root {
    padding: 0 10%;
 
    @media only screen and (max-width: 1000px) {
      padding: 0;
    }
  }
`;
 
const Navbar = ({ location, push }: IWithRouterProps) => {
  const handleClick = (param: ClickParam) => push(param.key);
 
  return (
    <Query query={NAVBAR_CATEGORIES}>
      {({ loading, error, data }) => {
        if (error) {
          console.log(error);
          return null;
        }
 
        if (loading) {
          return <Spin size={15} />;
        }
 
        return (
          <Root>
            <Menu
              onClick={handleClick}
              selectedKeys={[location.pathname]}
              mode="horizontal"
              style={{ backgroundColor: '#f5f5f5' }}
            >
              {data.categories.map((category: ICategory) => (
                <Menu.Item key={`/${category.slug}`}>
                  {category.title}
                </Menu.Item>
              ))}
            </Menu>
          </Root>
        );
      }}
    </Query>
  );
};
 
export default compose(withRouter)(Navbar);