About.tsx 2.77 KB
Newer Older
Andrey Azov's avatar
Andrey Azov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React, { ReactNode } from 'react';
import { useLocation } from 'react-router';

import useApiService from 'src/shared/hooks/useApiService';

Andrey Azov's avatar
Andrey Azov committed
22 23
import {
  TextArticle,
24
  RelatedArticles,
Andrey Azov's avatar
Andrey Azov committed
25 26
  HelpArticleGrid
} from 'src/shared/components/help-article';
Andrey Azov's avatar
Andrey Azov committed
27 28 29 30
import {
  TopMenu,
  SideMenu
} from 'src/content/app/about/components/about-menu/AboutMenu';
31
import { CircleLoader } from 'src/shared/components/loader/Loader';
Andrey Azov's avatar
Andrey Azov committed
32 33

import { Menu as MenuType } from 'src/shared/types/help-and-docs/menu';
Andrey Azov's avatar
Andrey Azov committed
34
import { TextArticleData } from 'src/shared/types/help-and-docs/article';
Andrey Azov's avatar
Andrey Azov committed
35

36
import helpStyles from '../help/Help.scss';
Andrey Azov's avatar
Andrey Azov committed
37 38 39 40 41 42 43
import styles from './About.scss';

const About = () => {
  const location = useLocation();
  const { data: menu } = useApiService<MenuType>({
    endpoint: `/api/docs/menus?name=about`
  });
Andrey Azov's avatar
Andrey Azov committed
44
  const { data: article } = useApiService<TextArticleData>({
Andrey Azov's avatar
Andrey Azov committed
45 46 47 48
    endpoint: `/api/docs/article?url=${encodeURIComponent(location.pathname)}`
  });

  return (
49 50 51 52 53
    <div className={helpStyles.help}>
      <AppBar />
      <TopMenuBar>
        {menu && <TopMenu menu={menu} currentUrl={location.pathname} />}
      </TopMenuBar>
Andrey Azov's avatar
Andrey Azov committed
54
      <HelpArticleGrid className={styles.grid}>
55 56 57 58 59 60 61
        {article ? (
          <TextArticle article={article} />
        ) : (
          <div className={styles.spinnerContainer}>
            <CircleLoader />
          </div>
        )}
Andrey Azov's avatar
Andrey Azov committed
62
        <aside className={styles.aside}>
63 64 65 66 67 68 69 70 71 72 73 74 75
          {article?.related_articles.length ? (
            <RelatedArticles
              title="More about…"
              articles={article.related_articles}
              highlightActiveArticle={true}
            />
          ) : (
            menu && (
              <>
                <div className={styles.asideTitle}>More about…</div>
                <SideMenu menu={menu} currentUrl={location.pathname} />
              </>
            )
Andrey Azov's avatar
Andrey Azov committed
76 77
          )}
        </aside>
Andrey Azov's avatar
Andrey Azov committed
78
      </HelpArticleGrid>
79
    </div>
Andrey Azov's avatar
Andrey Azov committed
80 81 82 83 84 85 86 87 88 89 90 91
  );
};

const AppBar = () => {
  return <div className={styles.appBar}>About Ensembl</div>;
};

const TopMenuBar = (props: { children: ReactNode }) => {
  return <div className={styles.topMenuBar}>{props.children}</div>;
};

export default About;