[wccom-17942] Making sure snackbar doesn't appear before content has loaded.

- Fixing `prettier` linter errors.
This commit is contained in:
And Finally 2023-09-04 15:45:24 +01:00
parent 6ae83b08ec
commit 6d65d54ed5
7 changed files with 18 additions and 21 deletions

View File

@ -1,5 +1,7 @@
export const DEFAULT_TAB_KEY = 'discover';
export const MARKETPLACE_HOST = 'https://woocommerce.com';
export const MARKETPLACE_PATH = '/extensions';
export const MARKETPLACE_SEARCH_API_PATH = '/wp-json/wccom-extensions/1.0/search';
export const MARKETPLACE_CATEGORY_API_PATH = '/wp-json/wccom-extensions/1.0/categories';
export const MARKETPLACE_SEARCH_API_PATH =
'/wp-json/wccom-extensions/1.0/search';
export const MARKETPLACE_CATEGORY_API_PATH =
'/wp-json/wccom-extensions/1.0/categories';

View File

@ -14,14 +14,11 @@ import { MarketplaceContext } from '../../contexts/marketplace-context';
import ProductListContent from '../product-list-content/product-list-content';
import ProductLoader from '../product-loader/product-loader';
import NoResults from '../product-list-content/no-results';
import {
Product,
SearchAPIProductType,
} from '../product-list/types';
import { Product, SearchAPIProductType } from '../product-list/types';
import { MARKETPLACE_SEARCH_API_PATH, MARKETPLACE_HOST } from '../constants';
export default function Extensions(): JSX.Element {
const [ productList, setProductList ] = useState<Product[]>( [] );
const [ productList, setProductList ] = useState< Product[] >( [] );
const marketplaceContextValue = useContext( MarketplaceContext );
const { isLoading, setIsLoading } = marketplaceContextValue;
@ -43,7 +40,8 @@ export default function Extensions(): JSX.Element {
const wccomSearchEndpoint =
MARKETPLACE_HOST +
MARKETPLACE_SEARCH_API_PATH + '?' +
MARKETPLACE_SEARCH_API_PATH +
'?' +
params.toString();
// Fetch data from WCCOM API

View File

@ -83,8 +83,6 @@ export default function FeedbackModal(): JSX.Element {
const { createNotice } = useDispatch( 'core/notices' );
function maybeShowSnackbar() {
let timer: ReturnType<typeof setTimeout> | undefined;
// Don't show if we're still loading content
if ( isLoading ) {
return;
@ -104,12 +102,14 @@ export default function FeedbackModal(): JSX.Element {
return;
}
timer = setTimeout( showSnackbar, SNACKBAR_TIMEOUT );
const timer = setTimeout( showSnackbar, SNACKBAR_TIMEOUT );
// Without this, navigating between screens will create a series of snackbars
dismissToday();
return () => { clearTimeout( timer ); }
return () => {
clearTimeout( timer );
}
}
function showSnackbar() {

View File

@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { WooFooterItem } from '@woocommerce/admin-layout';
import { __ } from '@wordpress/i18n';
import { check, commentContent, shield } from '@wordpress/icons';
import { createInterpolateElement } from '@wordpress/element';

View File

@ -108,12 +108,7 @@ const Tabs = ( props: TabsProps ): JSX.Element => {
const marketplaceContextValue = useContext( MarketplaceContext );
const { setSelectedTab } = marketplaceContextValue;
interface Query {
path?: string;
tab?: string;
}
const query: Record<string, string> = useQuery();
const query: Record< string, string > = useQuery();
useEffect( () => {
if ( query?.tab && tabs[ query.tab ] ) {

View File

@ -26,7 +26,7 @@ export function MarketplaceContextProvider( props: {
isLoading,
setIsLoading,
selectedTab,
setSelectedTab
setSelectedTab,
};
return (

View File

@ -7,7 +7,10 @@ import apiFetch from '@wordpress/api-fetch';
* Internal dependencies
*/
import { Product } from '../components/product-list/types';
import { MARKETPLACE_HOST, MARKETPLACE_CATEGORY_API_PATH } from '../components/constants';
import {
MARKETPLACE_HOST,
MARKETPLACE_CATEGORY_API_PATH
} from '../components/constants';
import { CategoryAPIItem } from '../components/category-selector/types';
import { LOCALE } from '../../utils/admin-settings';