From 3c8f4861e417ff66026a36f52c175d4f27159c9d Mon Sep 17 00:00:00 2001 From: And Finally Date: Wed, 23 Aug 2023 16:49:36 +0100 Subject: [PATCH] [wccom-17942] Only showing feedback snackbar when content of in-app marketplace has finished loading. Making sure snackbar is fixed position, so it's visible wherever you are on the page. - `ProductListContextProvider` provides `setIsLoading` function as well as `isLoading`. - `Discover` uses these values from context, instead of keeping a loading state in itself. - `FeedbackModal` calls `maybSetTimeout` when `isLoading` changes. If `isLoading` isn't truthy, and snackbar hasn't already rendered, it sets a timeout of 5 seconds to show it. - Removed wrapping from around Footer component, so it's no longer a child of the WooCommerce Admin `.woocommerce-layout__footer` footer. - Removed the `position: relative` from `.woocommerce-layout__footer`. It needs to be `position: fixed`. - Added FooterContent component to Footer, to allow the layout we want. - Changed use of context. This now only has states for the selected tab and loading state. - We use this context in `Tabs` and `Content` to keep track of which tab is selected, and set the selected tab. - We also use it in `Discover` and `Extensions`, which both report loading state to the context. This allows us to use it to only render the snackbar when loading is complete. - Extensions: moved `productList` and `setProductList` and logic for getting product list from the context provider to a state in this component. We don't need to share the list of products in the context. - Renamed `ProductListContext`, `ProductListContextProvider` and `productListContextValue` to more generic `MarketplaceContext`, `MarketplaceContextProvider` and `marketplaceContextValue`. - Renamed a constant and created constants for API paths. - Only shows snackbar after content has loaded, and after a timeout. We set a date `marketplace_redesign_2023_last_shown_date` in local storage to ensure we only show one snackbar. --- .../marketplace/components/constants.ts | 4 +- .../components/content/content.tsx | 23 ++--- .../components/discover/discover.tsx | 7 +- .../components/extensions/extensions.tsx | 72 +++++++++++++- .../feedback-modal/feedback-modal.tsx | 42 ++++++-- .../marketplace/components/footer/footer.scss | 66 ++++++------- .../marketplace/components/footer/footer.tsx | 14 +-- .../header-account/header-account.tsx | 4 +- .../marketplace/components/header/header.tsx | 14 +-- .../marketplace/components/tabs/tabs.tsx | 18 ++-- .../contexts/marketplace-context.tsx | 37 +++++++ .../contexts/product-list-context.tsx | 98 ------------------- .../client/marketplace/contexts/types.ts | 6 ++ .../client/marketplace/index.tsx | 25 ++--- .../client/marketplace/utils/functions.tsx | 4 +- 15 files changed, 224 insertions(+), 210 deletions(-) create mode 100644 plugins/woocommerce-admin/client/marketplace/contexts/marketplace-context.tsx delete mode 100644 plugins/woocommerce-admin/client/marketplace/contexts/product-list-context.tsx create mode 100644 plugins/woocommerce-admin/client/marketplace/contexts/types.ts diff --git a/plugins/woocommerce-admin/client/marketplace/components/constants.ts b/plugins/woocommerce-admin/client/marketplace/components/constants.ts index 548249734e2..4666ee78804 100644 --- a/plugins/woocommerce-admin/client/marketplace/components/constants.ts +++ b/plugins/woocommerce-admin/client/marketplace/components/constants.ts @@ -1,3 +1,5 @@ export const DEFAULT_TAB_KEY = 'discover'; +export const MARKETPLACE_API_HOST = 'https://woocommerce.com'; export const MARKETPLACE_PATH = '/extensions'; -export const MARKETPLACE_URL = 'https://woocommerce.com'; +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'; diff --git a/plugins/woocommerce-admin/client/marketplace/components/content/content.tsx b/plugins/woocommerce-admin/client/marketplace/components/content/content.tsx index 9c9af5fb837..4149b5291f1 100644 --- a/plugins/woocommerce-admin/client/marketplace/components/content/content.tsx +++ b/plugins/woocommerce-admin/client/marketplace/components/content/content.tsx @@ -1,6 +1,7 @@ /** * External dependencies */ +import { useContext } from '@wordpress/element'; /** * Internal dependencies @@ -8,12 +9,7 @@ import './content.scss'; import Discover from '../discover/discover'; import Extensions from '../extensions/extensions'; -import Footer from '../footer/footer'; -import FeedbackModal from '../feedback-modal/feedback-modal'; - -export interface ContentProps { - selectedTab?: string | undefined; -} +import { MarketplaceContext } from '../../contexts/marketplace-context'; const renderContent = ( selectedTab?: string ): JSX.Element => { switch ( selectedTab ) { @@ -24,15 +20,12 @@ const renderContent = ( selectedTab?: string ): JSX.Element => { } }; -export default function Content( props: ContentProps ): JSX.Element { - const { selectedTab } = props; +export default function Content(): JSX.Element { + const marketplaceContextValue = useContext( MarketplaceContext ); + const { selectedTab } = marketplaceContextValue; return ( - <> -
- { renderContent( selectedTab ) } -
-