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

View File

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

View File

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

View File

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

View File

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