Skip to content

Commit b4a8045

Browse files
committed
fix flickering message
1 parent 6ff3705 commit b4a8045

File tree

2 files changed

+32
-19
lines changed
  • projects/packages/forms/src/dashboard

2 files changed

+32
-19
lines changed

projects/packages/forms/src/dashboard/components/empty-responses/index.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import type { Integration } from '../../../types/index.ts';
2828

2929
type UseInstallAkismetReturn = {
3030
shouldShowAkismetCta: boolean;
31-
isIntegrationsLoading: boolean;
3231
wrapperBody: string;
3332
isInstallingAkismet: boolean;
3433
canPerformAkismetAction: boolean;
@@ -48,20 +47,16 @@ type EmptyResponsesProps = {
4847
* @return {UseInstallAkismetReturn} An object containing the necessary data and functions to handle Akismet installation and activation.
4948
*/
5049
const useInstallAkismet = (): UseInstallAkismetReturn => {
51-
const { akismetIntegration, isIntegrationsLoading } = useSelect(
52-
( select: SelectIntegrations ) => {
53-
const store = select( INTEGRATIONS_STORE );
54-
const integrations = store.getIntegrations() || [];
55-
56-
return {
57-
akismetIntegration: integrations.find(
58-
( integration: Integration ) => integration.id === 'akismet'
59-
),
60-
isIntegrationsLoading: store.isIntegrationsLoading(),
61-
};
62-
},
63-
[]
64-
) as { akismetIntegration?: Integration; isIntegrationsLoading: boolean };
50+
const { akismetIntegration } = useSelect( ( select: SelectIntegrations ) => {
51+
const store = select( INTEGRATIONS_STORE );
52+
const integrations = store.getIntegrations() || [];
53+
54+
return {
55+
akismetIntegration: integrations.find(
56+
( integration: Integration ) => integration.id === 'akismet'
57+
),
58+
};
59+
}, [] ) as { akismetIntegration?: Integration };
6560

6661
const { refreshIntegrations } = useDispatch( INTEGRATIONS_STORE ) as IntegrationsDispatch;
6762

@@ -142,7 +137,6 @@ const useInstallAkismet = (): UseInstallAkismetReturn => {
142137

143138
return {
144139
shouldShowAkismetCta,
145-
isIntegrationsLoading,
146140
wrapperBody,
147141
isInstallingAkismet,
148142
canPerformAkismetAction,
@@ -167,7 +161,6 @@ const EmptyResponses = ( { status, isSearch, readStatusFilter }: EmptyResponsesP
167161
const emptyTrashDays = useConfigValue( 'emptyTrashDays' ) ?? 0;
168162
const {
169163
shouldShowAkismetCta,
170-
isIntegrationsLoading,
171164
wrapperBody,
172165
isInstallingAkismet,
173166
canPerformAkismetAction,
@@ -210,7 +203,7 @@ const EmptyResponses = ( { status, isSearch, readStatusFilter }: EmptyResponsesP
210203
);
211204

212205
if ( status === 'spam' ) {
213-
if ( shouldShowAkismetCta && ! isIntegrationsLoading ) {
206+
if ( shouldShowAkismetCta ) {
214207
return (
215208
<EmptyWrapper
216209
heading={ noSpamHeading }

projects/packages/forms/src/dashboard/inbox/stage/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*/
44
import jetpackAnalytics from '@automattic/jetpack-analytics';
55
import { JetpackLogo } from '@automattic/jetpack-components';
6+
import { isSimpleSite } from '@automattic/jetpack-script-data';
67
import { Badge } from '@automattic/ui';
78
import { ExternalLink, Modal } from '@wordpress/components';
89
import { useResizeObserver, useViewportMatch } from '@wordpress/compose';
10+
import { useSelect } from '@wordpress/data';
911
import { DataViews } from '@wordpress/dataviews/wp';
1012
import { dateI18n, getSettings as getDateSettings } from '@wordpress/date';
1113
import { useCallback, useMemo, useState } from '@wordpress/element';
@@ -19,6 +21,7 @@ import { useSearchParams } from 'react-router';
1921
* Internal dependencies
2022
*/
2123
import useConfigValue from '../../../hooks/use-config-value.ts';
24+
import { INTEGRATIONS_STORE } from '../../../store/integrations/index.ts';
2225
import CreateFormButton from '../../components/create-form-button/index.tsx';
2326
import EmptyResponses from '../../components/empty-responses/index.tsx';
2427
import EmptySpamButton from '../../components/empty-spam-button/index.tsx';
@@ -137,6 +140,23 @@ export default function InboxView() {
137140
totalItems,
138141
totalPages,
139142
} = useInboxData();
143+
const isAkismetStatusPending = useSelect(
144+
select => {
145+
const store = select( INTEGRATIONS_STORE );
146+
const integrations = store.getIntegrations() || [];
147+
const isIntegrationsLoading = store.isIntegrationsLoading();
148+
const akismetIntegration = integrations.find( integration => integration.id === 'akismet' );
149+
150+
return (
151+
statusFilter === 'spam' &&
152+
! isSimpleSite() &&
153+
( isIntegrationsLoading || ! akismetIntegration || akismetIntegration.__isPartial )
154+
);
155+
},
156+
[ statusFilter ]
157+
);
158+
159+
const isInboxLoading = isLoadingData || isAkismetStatusPending;
140160

141161
useEffect( () => {
142162
const _filters = view.filters?.reduce( ( accumulator, { field, value } ) => {
@@ -497,7 +517,7 @@ export default function InboxView() {
497517
fields={ fields }
498518
actions={ actions }
499519
data={ records || EMPTY_ARRAY }
500-
isLoading={ isLoadingData }
520+
isLoading={ isInboxLoading }
501521
view={ view }
502522
onChangeView={ setView }
503523
selection={ selection }

0 commit comments

Comments
 (0)