Rename types.

This commit is contained in:
Gan Eng Chin 2023-01-21 02:14:36 +08:00
parent a511054a3e
commit 0b1ab21836
No known key found for this signature in database
GPG Key ID: 94D5D972860ADB01
5 changed files with 16 additions and 22 deletions

View File

@ -2,7 +2,7 @@
* Internal dependencies
*/
import { TYPES } from './action-types';
import { ApiFetchError, Channel, RecommendedPlugin } from './types';
import { ApiFetchError, Channel, RecommendedChannel } from './types';
export const receiveChannelsSuccess = ( channels: Array< Channel > ) => {
return {
@ -20,7 +20,7 @@ export const receiveChannelsError = ( error: ApiFetchError ) => {
};
export const receiveRecommendedChannelsSuccess = (
channels: Array< RecommendedPlugin >
channels: Array< RecommendedChannel >
) => {
return {
type: TYPES.RECEIVE_RECOMMENDED_CHANNELS_SUCCESS,

View File

@ -12,7 +12,7 @@ import {
receiveRecommendedChannelsSuccess,
receiveRecommendedChannelsError,
} from './actions';
import { Channel, RecommendedPlugin } from './types';
import { Channel, RecommendedChannel } from './types';
import { API_NAMESPACE } from './constants';
import { isApiFetchError } from './guards';
@ -34,7 +34,7 @@ export function* getChannels() {
export function* getRecommendedChannels() {
try {
const data: RecommendedPlugin[] = yield apiFetch( {
const data: RecommendedChannel[] = yield apiFetch( {
path: `${ API_NAMESPACE }/recommendations?category=channels`,
} );

View File

@ -17,7 +17,7 @@ export type Channel = {
icon: string;
};
export type Channels = {
export type ChannelsState = {
data?: Array< Channel >;
error?: ApiFetchError;
};
@ -35,7 +35,7 @@ type Tag = {
name: string;
};
export type RecommendedPlugin = {
export type RecommendedChannel = {
title: string;
description: string;
url: string;
@ -48,12 +48,12 @@ export type RecommendedPlugin = {
tags: Array< Tag >;
};
export type RecommendedChannels = {
data?: Array< RecommendedPlugin >;
export type RecommendedChannelsState = {
data?: Array< RecommendedChannel >;
error?: ApiFetchError;
};
export type State = {
channels: Channels;
recommendedChannels: RecommendedChannels;
channels: ChannelsState;
recommendedChannels: RecommendedChannelsState;
};

View File

@ -10,7 +10,7 @@ import { differenceWith } from 'lodash';
*/
import { STORE_KEY } from '~/marketing/data-multichannel/constants';
import { RecommendedChannel } from '~/marketing/types';
import { RecommendedChannels } from '~/marketing/data-multichannel/types';
import { RecommendedChannelsState } from '~/marketing/data-multichannel/types';
type UseRecommendedChannels = {
loading: boolean;
@ -21,7 +21,8 @@ export const useRecommendedChannels = (): UseRecommendedChannels => {
return useSelect( ( select ) => {
const { hasFinishedResolution, getRecommendedChannels } =
select( STORE_KEY );
const { data, error } = getRecommendedChannels< RecommendedChannels >();
const { data, error } =
getRecommendedChannels< RecommendedChannelsState >();
const { getActivePlugins } = select( PLUGINS_STORE_NAME );
const activePlugins = getActivePlugins();

View File

@ -3,14 +3,7 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import {
createElement,
useCallback,
useState,
useEffect,
useMemo,
useRef,
} from '@wordpress/element';
import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
@ -20,7 +13,7 @@ import { STORE_KEY } from '~/marketing/data-multichannel/constants';
import {
ApiFetchError,
Channel,
Channels,
ChannelsState,
} from '~/marketing/data-multichannel/types';
type UseRegisteredChannels = {
@ -151,7 +144,7 @@ export const useRegisteredChannels = (): UseRegisteredChannels => {
return useSelect( ( select ) => {
const { hasFinishedResolution, getChannels } = select( STORE_KEY );
const channels = getChannels< Channels >();
const channels = getChannels< ChannelsState >();
return {
loading: ! hasFinishedResolution( 'getChannels' ),