Apply useCounter for new menu items (#7962)
* Apply useCounter for new menu items * Adjust * Adjust useCounter usage * Adjust
This commit is contained in:
parent
04cbef4358
commit
e8a878c2de
@ -4,7 +4,7 @@
|
||||
import type { TFunction } from 'i18next';
|
||||
import type { Route } from './types';
|
||||
|
||||
import Component from '@polkadot/app-alliance';
|
||||
import Component, { useCounter } from '@polkadot/app-alliance';
|
||||
|
||||
export default function create (t: TFunction): Route {
|
||||
return {
|
||||
@ -17,6 +17,7 @@ export default function create (t: TFunction): Route {
|
||||
group: 'governance',
|
||||
icon: 'people-group',
|
||||
name: 'alliance',
|
||||
text: t('nav.alliance', 'Alliance', { ns: 'apps-routing' })
|
||||
text: t('nav.alliance', 'Alliance', { ns: 'apps-routing' }),
|
||||
useCounter
|
||||
};
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
import type { TFunction } from 'i18next';
|
||||
import type { Route } from './types';
|
||||
|
||||
import Component from '@polkadot/app-fellowship';
|
||||
import Component, { useCounter } from '@polkadot/app-fellowship';
|
||||
|
||||
export default function create (t: TFunction): Route {
|
||||
return {
|
||||
@ -19,6 +19,7 @@ export default function create (t: TFunction): Route {
|
||||
group: 'governance',
|
||||
icon: 'people-arrows',
|
||||
name: 'fellowship',
|
||||
text: t('nav.fellowship', 'Fellowship', { ns: 'apps-routing' })
|
||||
text: t('nav.fellowship', 'Fellowship', { ns: 'apps-routing' }),
|
||||
useCounter
|
||||
};
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
import type { TFunction } from 'i18next';
|
||||
import type { Route } from './types';
|
||||
|
||||
import Component from '@polkadot/app-ranked';
|
||||
import Component, { useCounter } from '@polkadot/app-ranked';
|
||||
|
||||
export default function create (t: TFunction): Route {
|
||||
return {
|
||||
@ -19,6 +19,7 @@ export default function create (t: TFunction): Route {
|
||||
group: 'governance',
|
||||
icon: 'people-arrows',
|
||||
name: 'ranked',
|
||||
text: t('nav.ranked', 'Ranked collective', { ns: 'apps-routing' })
|
||||
text: t('nav.ranked', 'Ranked collective', { ns: 'apps-routing' }),
|
||||
useCounter
|
||||
};
|
||||
}
|
||||
|
||||
@ -4,8 +4,7 @@
|
||||
import type { TFunction } from 'i18next';
|
||||
import type { Route } from './types';
|
||||
|
||||
import Component from '@polkadot/app-referenda';
|
||||
import useCounter from '@polkadot/app-referenda/useCounter';
|
||||
import Component, { useCounter } from '@polkadot/app-referenda';
|
||||
|
||||
export default function create (t: TFunction): Route {
|
||||
return {
|
||||
|
||||
@ -19,6 +19,8 @@ import useMembers from './useMembers';
|
||||
import useRule from './useRule';
|
||||
import useUnscrupulous from './useUnscrupulous';
|
||||
|
||||
export { default as useCounter } from './useCounter';
|
||||
|
||||
interface Props {
|
||||
basePath: string;
|
||||
className?: string;
|
||||
|
||||
18
packages/page-alliance/src/useCounter.ts
Normal file
18
packages/page-alliance/src/useCounter.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2022 @polkadot/app-democracy authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
|
||||
|
||||
function useCounterImpl (): number {
|
||||
const { api, isApiReady } = useApi();
|
||||
const proposalHashes = useCall<unknown[]>(isApiReady && api.derive.alliance.proposalHashes);
|
||||
|
||||
return useMemo(
|
||||
() => (proposalHashes && proposalHashes.length) || 0,
|
||||
[proposalHashes]
|
||||
);
|
||||
}
|
||||
|
||||
export default createNamedHook('useCounter', useCounterImpl);
|
||||
@ -5,6 +5,8 @@ import React from 'react';
|
||||
|
||||
import Main from '@polkadot/app-ranked/App';
|
||||
|
||||
export { default as useCounter } from './useCounter';
|
||||
|
||||
interface Props {
|
||||
basePath: string;
|
||||
className?: string;
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/app-ranked authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { PalletPoll } from './types';
|
||||
|
||||
import { useCounterNamed } from '@polkadot/app-referenda/useCounter';
|
||||
import { createNamedHook } from '@polkadot/react-hooks';
|
||||
|
||||
function useRefCounterImpl (collective: PalletPoll): number {
|
||||
return useCounterNamed(collective);
|
||||
function useCounterImpl (): number {
|
||||
return useCounterNamed('fellowshipReferenda');
|
||||
}
|
||||
|
||||
export default createNamedHook('useRefCounter', useRefCounterImpl);
|
||||
export default createNamedHook('useCounter', useCounterImpl);
|
||||
@ -6,13 +6,12 @@ import type { PalletColl, PalletPoll } from './types';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Route, Switch } from 'react-router';
|
||||
|
||||
import Referenda from '@polkadot/app-referenda/Referenda';
|
||||
import Referenda, { useCounter } from '@polkadot/app-referenda/Referenda';
|
||||
import { Tabs } from '@polkadot/react-components';
|
||||
|
||||
import Members from './Members';
|
||||
import { useTranslation } from './translate';
|
||||
import useMembers from './useMembers';
|
||||
import useRefCounter from './useRefCounter';
|
||||
|
||||
interface Props {
|
||||
basePath: string;
|
||||
@ -24,7 +23,7 @@ interface Props {
|
||||
function App ({ basePath, className, palletColl, palletPoll }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const members = useMembers(palletColl);
|
||||
const refCount = useRefCounter(palletPoll);
|
||||
const refCount = useCounter(palletPoll);
|
||||
|
||||
const tabs = useMemo(
|
||||
() => [
|
||||
|
||||
@ -5,6 +5,8 @@ import React from 'react';
|
||||
|
||||
import Main from './App';
|
||||
|
||||
export { default as useCounter } from './useCounter';
|
||||
|
||||
interface Props {
|
||||
basePath: string;
|
||||
className?: string;
|
||||
|
||||
11
packages/page-ranked/src/useCounter.ts
Normal file
11
packages/page-ranked/src/useCounter.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/app-ranked authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { useCounterNamed } from '@polkadot/app-referenda/useCounter';
|
||||
import { createNamedHook } from '@polkadot/react-hooks';
|
||||
|
||||
function useCounterImpl (): number {
|
||||
return useCounterNamed('rankedPolls');
|
||||
}
|
||||
|
||||
export default createNamedHook('useCounter', useCounterImpl);
|
||||
@ -14,6 +14,8 @@ import useSummary from '../useSummary';
|
||||
import Referendum from './Referendum';
|
||||
import Summary from './Summary';
|
||||
|
||||
export { useCounterNamed as useCounter } from '../useCounter';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
members?: string[];
|
||||
|
||||
@ -8,6 +8,8 @@ import { Tabs } from '@polkadot/react-components';
|
||||
import Referenda from './Referenda';
|
||||
import { useTranslation } from './translate';
|
||||
|
||||
export { default as useCounter } from './useCounter';
|
||||
|
||||
interface Props {
|
||||
basePath: string;
|
||||
className?: string;
|
||||
|
||||
@ -13,9 +13,7 @@ export function useCounterNamed (palletReferenda: PalletReferenda): number {
|
||||
const refs = useReferenda(palletReferenda);
|
||||
|
||||
return useMemo(
|
||||
() => refs
|
||||
? refs.filter(({ info }) => info.isOngoing).length
|
||||
: 0,
|
||||
() => (refs && refs.filter(({ info }) => info.isOngoing).length) || 0,
|
||||
[refs]
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,9 +65,9 @@ const OPT_MULTI = {
|
||||
};
|
||||
|
||||
function useReferendaImpl (palletReferenda: PalletReferenda): Referendum[] | undefined {
|
||||
const { api } = useApi();
|
||||
const { api, isApiReady } = useApi();
|
||||
const ids = useReferendaIds(palletReferenda);
|
||||
const referenda = useCall(ids && ids.length !== 0 && api.query[palletReferenda].referendumInfoFor.multi, [ids], OPT_MULTI);
|
||||
const referenda = useCall(isApiReady && ids && ids.length !== 0 && api.query[palletReferenda].referendumInfoFor.multi, [ids], OPT_MULTI);
|
||||
|
||||
return useMemo(
|
||||
() => ids && ids.length === 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user