index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2017-2020 @polkadot/app-explorer authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { AppProps, BareProps } from '@polkadot/react-components/types';
  5. import { KeyedEvent } from './types';
  6. import React, { useContext, useMemo } from 'react';
  7. import { Route, Switch } from 'react-router';
  8. // import styled from 'styled-components';
  9. import Tabs from '@polkadot/react-components/Tabs';
  10. import { useApi } from '@polkadot/react-hooks';
  11. import { BlockAuthorsContext, EventsContext } from '@polkadot/react-query';
  12. import uiSettings from '@polkadot/ui-settings';
  13. import BlockInfo from './BlockInfo';
  14. import Forks from './Forks';
  15. import Main from './Main';
  16. import NodeInfo from './NodeInfo';
  17. import { useTranslation } from './translate';
  18. interface Props extends AppProps, BareProps {
  19. newEvents?: KeyedEvent[];
  20. }
  21. function ExplorerApp ({ basePath, className }: Props): React.ReactElement<Props> {
  22. const { t } = useTranslation();
  23. const { api } = useApi();
  24. const { lastHeaders } = useContext(BlockAuthorsContext);
  25. const events = useContext(EventsContext);
  26. const items = useMemo(() => [
  27. {
  28. isRoot: true,
  29. name: 'chain',
  30. text: t('Chain info')
  31. },
  32. {
  33. hasParams: true,
  34. name: 'query',
  35. text: t('Block details')
  36. },
  37. {
  38. name: 'forks',
  39. text: t('Forks')
  40. },
  41. {
  42. name: 'node',
  43. text: t('Node info')
  44. }
  45. ], [t]);
  46. return (
  47. <main className={className}>
  48. <header>
  49. <Tabs
  50. basePath={basePath}
  51. hidden={
  52. uiSettings.uiMode === 'full'
  53. ? api.query.babe ? [] : ['forks']
  54. : ['node', 'forks']
  55. }
  56. items={items}
  57. />
  58. </header>
  59. <Switch>
  60. <Route path={`${basePath}/forks`}><Forks /></Route>
  61. <Route path={`${basePath}/query/:value`}><BlockInfo /></Route>
  62. <Route path={`${basePath}/query`}><BlockInfo /></Route>
  63. <Route path={`${basePath}/node`}><NodeInfo /></Route>
  64. <Route>
  65. <Main
  66. events={events}
  67. headers={lastHeaders}
  68. />
  69. </Route>
  70. </Switch>
  71. </main>
  72. );
  73. }
  74. export default React.memo(ExplorerApp);