Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update council counter refresh #2082

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/app-council/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { DerivedCollectiveProposals } from '@polkadot/api-derive/types';
import { AppProps, BareProps, I18nProps } from '@polkadot/react-components/types';
import { AppProps, BareProps } from '@polkadot/react-components/types';

import React from 'react';
import { Route, Switch } from 'react-router';
Expand All @@ -12,17 +12,20 @@ import styled from 'styled-components';
import { Tabs } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';

import useCounter from './useCounter';
import Overview from './Overview';
import Motions from './Motions';
import translate from './translate';
import { useTranslation } from './translate';

export { default as useCounter } from './useCounter';
export { useCounter };

interface Props extends AppProps, BareProps, I18nProps {}
interface Props extends AppProps, BareProps {}

function CouncilApp ({ basePath, className, t }: Props): React.ReactElement<Props> {
function CouncilApp ({ basePath, className }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const { pathname } = useLocation();
const numMotions = useCounter();
const motions = useCall<DerivedCollectiveProposals>(api.derive.council.proposals, []);

return (
Expand All @@ -42,7 +45,7 @@ function CouncilApp ({ basePath, className, t }: Props): React.ReactElement<Prop
},
{
name: 'motions',
text: t('Motions ({{count}})', { replace: { count: motions?.length || 0 } })
text: t('Motions ({{count}})', { replace: { count: numMotions } })
}
]}
/>
Expand All @@ -57,10 +60,8 @@ function CouncilApp ({ basePath, className, t }: Props): React.ReactElement<Prop
);
}

export default translate(
styled(CouncilApp)`
.council--hidden {
display: none;
}
`
);
export default styled(CouncilApp)`
.council--hidden {
display: none;
}
`;
6 changes: 5 additions & 1 deletion packages/app-council/src/useCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default function useCounter (): number {
const [counter, setCounter] = useState(0);

useEffect((): void => {
setCounter(motions?.length || 0);
setCounter(
motions
? motions.filter(({ votes }): boolean => !!votes).length
: 0
);
}, [motions]);

return counter;
Expand Down