Remove useChannels and use useRegisteredChannels and useRecommendedChannels directly.
This commit is contained in:
parent
9e0b71ff1c
commit
7bd32ba638
|
@ -13,24 +13,25 @@ import {
|
||||||
CardHeaderDescription,
|
CardHeaderDescription,
|
||||||
CenteredSpinner,
|
CenteredSpinner,
|
||||||
} from '~/marketing/components';
|
} from '~/marketing/components';
|
||||||
import { useChannels } from './useChannels';
|
import { useRegisteredChannels } from './useRegisteredChannels';
|
||||||
import './Channels.scss';
|
import { useRecommendedChannels } from './useRecommendedChannels';
|
||||||
import { InstalledChannelCardBody } from './InstalledChannelCardBody';
|
import { InstalledChannelCardBody } from './InstalledChannelCardBody';
|
||||||
import { RecommendedChannels } from './RecommendedChannels';
|
import { RecommendedChannels } from './RecommendedChannels';
|
||||||
import { RecommendedChannelsList } from './RecommendedChannelsList';
|
import { RecommendedChannelsList } from './RecommendedChannelsList';
|
||||||
|
import './Channels.scss';
|
||||||
|
|
||||||
export const Channels = () => {
|
export const Channels = () => {
|
||||||
const {
|
const { loading: loadingRegistered, data: dataRegistered } =
|
||||||
loading,
|
useRegisteredChannels();
|
||||||
data: { registeredChannels, recommendedChannels },
|
const { loading: loadingRecommended, data: dataRecommended } =
|
||||||
} = useChannels();
|
useRecommendedChannels();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: we may need to filter the channels against
|
* TODO: we may need to filter the channels against
|
||||||
* `@woocommerce/data` installed plugins.
|
* `@woocommerce/data` installed plugins.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( loading ) {
|
if ( loadingRegistered || loadingRecommended ) {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
|
@ -50,12 +51,12 @@ export const Channels = () => {
|
||||||
* we should display recommended channels without collapsible list
|
* we should display recommended channels without collapsible list
|
||||||
* and with a description in the card header.
|
* and with a description in the card header.
|
||||||
*/
|
*/
|
||||||
if ( registeredChannels.length === 0 ) {
|
if ( dataRegistered.length === 0 ) {
|
||||||
/**
|
/**
|
||||||
* If for some reasons we don't have recommended channels,
|
* If for some reasons we don't have recommended channels,
|
||||||
* then we should not show the Channels card at all.
|
* then we should not show the Channels card at all.
|
||||||
*/
|
*/
|
||||||
if ( recommendedChannels.length === 0 ) {
|
if ( dataRecommended.length === 0 ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ export const Channels = () => {
|
||||||
</CardHeaderDescription>
|
</CardHeaderDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<RecommendedChannelsList
|
<RecommendedChannelsList
|
||||||
recommendedChannels={ recommendedChannels }
|
recommendedChannels={ dataRecommended }
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
@ -94,22 +95,18 @@ export const Channels = () => {
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
{ /* Registered channels section. */ }
|
{ /* Registered channels section. */ }
|
||||||
{ registeredChannels.map( ( el, idx ) => {
|
{ dataRegistered.map( ( el, idx ) => {
|
||||||
return (
|
return (
|
||||||
<Fragment key={ el.slug }>
|
<Fragment key={ el.slug }>
|
||||||
<InstalledChannelCardBody installedChannel={ el } />
|
<InstalledChannelCardBody installedChannel={ el } />
|
||||||
{ idx < registeredChannels.length - 1 && (
|
{ idx < dataRegistered.length - 1 && <CardDivider /> }
|
||||||
<CardDivider />
|
|
||||||
) }
|
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
} ) }
|
} ) }
|
||||||
|
|
||||||
{ /* Recommended channels section. */ }
|
{ /* Recommended channels section. */ }
|
||||||
{ recommendedChannels.length > 0 && (
|
{ dataRecommended.length > 0 && (
|
||||||
<RecommendedChannels
|
<RecommendedChannels recommendedChannels={ dataRecommended } />
|
||||||
recommendedChannels={ recommendedChannels }
|
|
||||||
/>
|
|
||||||
) }
|
) }
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
import { useRecommendedChannels } from './useRecommendedChannels';
|
|
||||||
import { useRegisteredChannels } from './useRegisteredChannels';
|
|
||||||
|
|
||||||
export const useChannels = () => {
|
|
||||||
const { loading: loadingRegistered, data: dataRegistered } =
|
|
||||||
useRegisteredChannels();
|
|
||||||
const { loading: loadingRecommended, data: dataRecommended } =
|
|
||||||
useRecommendedChannels();
|
|
||||||
|
|
||||||
return {
|
|
||||||
loading: loadingRegistered || loadingRecommended,
|
|
||||||
data: {
|
|
||||||
registeredChannels: dataRegistered,
|
|
||||||
recommendedChannels: dataRecommended,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
Loading…
Reference in New Issue