index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import { Route, Switch } from 'react-router';
  3. import { I18nProps } from '@polkadot/react-components/types';
  4. import { RouteProps as AppMainRouteProps } from '@polkadot/apps-routing/types';
  5. import { withCalls } from '@polkadot/react-api/hoc';
  6. import { AccountId, Hash } from '@polkadot/types/interfaces';
  7. import Tabs from '@polkadot/react-components/Tabs';
  8. import { TabItem } from '@polkadot/react-components/Tabs/types';
  9. // our app-specific styles
  10. import style from './style';
  11. import styled from 'styled-components';
  12. // local imports and components
  13. import translate from './translate';
  14. import Dashboard from './Dashboard';
  15. import Council from './Council';
  16. import Applicants from './Applicants';
  17. import Votes from './Votes';
  18. import Reveals from './Reveals';
  19. import { queryToProp } from '@polkadot/joy-utils/functions/misc';
  20. import { Seat } from '@joystream/types/council';
  21. import { ApiProps } from '@polkadot/react-api/types';
  22. import FMReminderBanner from '@polkadot/joy-utils/react/components/FMReminderBanner';
  23. const ElectionMain = styled.main`${style}`;
  24. // define out internal types
  25. type Props = AppMainRouteProps & ApiProps & I18nProps & {
  26. activeCouncil?: Seat[];
  27. applicants?: AccountId[];
  28. commitments?: Hash[];
  29. };
  30. type State = Record<any, never>;
  31. class App extends React.PureComponent<Props, State> {
  32. state: State = {};
  33. private buildTabs (): TabItem[] {
  34. const { t, activeCouncil = [], applicants = [], commitments = [] } = this.props;
  35. return [
  36. {
  37. isRoot: true,
  38. name: 'council',
  39. text: t('Dashboard')
  40. },
  41. {
  42. name: 'members',
  43. text: t('Council members') + ` (${activeCouncil.length})`
  44. },
  45. {
  46. name: 'applicants',
  47. text: t('Applicants') + ` (${applicants.length})`
  48. },
  49. {
  50. name: 'votes',
  51. text: t('Votes') + ` (${commitments.length})`
  52. }
  53. ];
  54. }
  55. render () {
  56. const { basePath } = this.props;
  57. const tabs = this.buildTabs();
  58. return (
  59. <ElectionMain className='election--App'>
  60. <FMReminderBanner contextualTitle='Council'/>
  61. <header>
  62. <Tabs basePath={basePath} items={tabs} />
  63. </header>
  64. <Switch>
  65. <Route path={`${basePath}/members`} component={Council} />
  66. <Route path={`${basePath}/applicants`} component={Applicants} />
  67. <Route path={`${basePath}/votes`} component={Votes} />
  68. <Route path={`${basePath}/reveals`} component={Reveals} />
  69. <Route component={Dashboard} />
  70. </Switch>
  71. </ElectionMain>
  72. );
  73. }
  74. }
  75. export default translate(
  76. withCalls<Props>(
  77. queryToProp('query.council.activeCouncil'),
  78. queryToProp('query.councilElection.applicants'),
  79. queryToProp('query.councilElection.commitments')
  80. )(App)
  81. );