Fix incorrect data while loading in useInstalledPlugins.

This commit is contained in:
Gan Eng Chin 2023-03-21 18:33:57 +08:00
parent f45e43b990
commit 79023a4a10
No known key found for this signature in database
GPG Key ID: 94D5D972860ADB01
1 changed files with 13 additions and 6 deletions

View File

@ -25,8 +25,14 @@ export type UseInstalledPlugins = {
* The list of installed plugins will not include registered and recommended marketing channels.
*/
export const useInstalledPlugins = (): UseInstalledPlugins => {
const { data: dataRegisteredChannels = [] } = useRegisteredChannels();
const { data: dataRecommendedChannels = [] } = useRecommendedChannels();
const {
loading: loadingRegisteredChannels,
data: dataRegisteredChannels = [],
} = useRegisteredChannels();
const {
loading: loadingRecommendedChannels,
data: dataRecommendedChannels = [],
} = useRecommendedChannels();
const { installedPlugins, activatingPlugins } = useSelect( ( select ) => {
const { getInstalledPlugins, getActivatingPlugins } =
@ -38,6 +44,10 @@ export const useInstalledPlugins = (): UseInstalledPlugins => {
};
}, [] );
const { activateInstalledPlugin, loadInstalledPluginsAfterActivation } =
useDispatch( STORE_KEY );
const loading = loadingRegisteredChannels || loadingRecommendedChannels;
const installedPluginsWithoutChannels = chain( installedPlugins )
.differenceWith( dataRegisteredChannels, ( a, b ) => a.slug === b.slug )
.differenceWith(
@ -46,11 +56,8 @@ export const useInstalledPlugins = (): UseInstalledPlugins => {
)
.value();
const { activateInstalledPlugin, loadInstalledPluginsAfterActivation } =
useDispatch( STORE_KEY );
return {
installedPlugins: installedPluginsWithoutChannels,
installedPlugins: loading ? [] : installedPluginsWithoutChannels,
activatingPlugins,
activateInstalledPlugin,
loadInstalledPluginsAfterActivation,