index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { KeyedEvent } from '@polkadot/react-query/types';
  5. import React, { useContext, useMemo } from 'react';
  6. import { Route, Switch } from 'react-router';
  7. // import styled from 'styled-components';
  8. import Tabs from '@polkadot/react-components/Tabs';
  9. import { useApi } from '@polkadot/react-hooks';
  10. import { BlockAuthorsContext, EventsContext } from '@polkadot/react-query';
  11. import uiSettings from '@polkadot/ui-settings';
  12. import BlockInfo from './BlockInfo';
  13. import Forks from './Forks';
  14. import Main from './Main';
  15. import NodeInfo from './NodeInfo';
  16. import { useTranslation } from './translate';
  17. interface Props {
  18. basePath: string;
  19. className?: string;
  20. newEvents?: KeyedEvent[];
  21. }
  22. function ExplorerApp ({ basePath, className }: Props): React.ReactElement<Props> {
  23. const { t } = useTranslation();
  24. const { api } = useApi();
  25. const { lastHeaders } = useContext(BlockAuthorsContext);
  26. const events = useContext(EventsContext);
  27. const items = useMemo(() => [
  28. {
  29. isRoot: true,
  30. name: 'chain',
  31. text: t<string>('Chain info')
  32. },
  33. {
  34. hasParams: true,
  35. name: 'query',
  36. text: t<string>('Block details')
  37. },
  38. {
  39. name: 'forks',
  40. text: t<string>('Forks')
  41. },
  42. {
  43. name: 'node',
  44. text: t<string>('Node info')
  45. }
  46. ], [t]);
  47. return (
  48. <main className={className}>
  49. <header>
  50. <Tabs
  51. basePath={basePath}
  52. hidden={
  53. uiSettings.uiMode === 'full'
  54. ? api.query.babe ? [] : ['forks']
  55. : ['node', 'forks']
  56. }
  57. items={items}
  58. />
  59. </header>
  60. <Switch>
  61. <Route path={`${basePath}/forks`}><Forks /></Route>
  62. <Route path={`${basePath}/query/:value`}><BlockInfo /></Route>
  63. <Route path={`${basePath}/query`}><BlockInfo /></Route>
  64. <Route path={`${basePath}/node`}><NodeInfo /></Route>
  65. <Route>
  66. <Main
  67. events={events}
  68. headers={lastHeaders}
  69. />
  70. </Route>
  71. </Switch>
  72. </main>
  73. );
  74. }
  75. export default React.memo(ExplorerApp);