2023-07-20 13:53:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-10-04 16:59:34 +00:00
|
|
|
import { useContext, useEffect, useState } from '@wordpress/element';
|
|
|
|
import { useQuery } from '@woocommerce/navigation';
|
2023-07-20 13:53:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './content.scss';
|
2023-10-12 09:56:46 +00:00
|
|
|
import { Product, ProductType, SearchResultType } from '../product-list/types';
|
2024-03-12 10:03:08 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2023-07-20 13:53:06 +00:00
|
|
|
import Discover from '../discover/discover';
|
2023-10-06 08:17:56 +00:00
|
|
|
import Products from '../products/products';
|
2023-10-04 16:59:34 +00:00
|
|
|
import SearchResults from '../search-results/search-results';
|
2023-09-21 14:00:22 +00:00
|
|
|
import MySubscriptions from '../my-subscriptions/my-subscriptions';
|
[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 <WooFooterItem> 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.
2023-08-23 15:49:36 +00:00
|
|
|
import { MarketplaceContext } from '../../contexts/marketplace-context';
|
2023-10-12 09:29:43 +00:00
|
|
|
import { fetchSearchResults } from '../../utils/functions';
|
2023-10-18 12:03:17 +00:00
|
|
|
import { SubscriptionsContextProvider } from '../../contexts/subscriptions-context';
|
2023-10-24 10:05:25 +00:00
|
|
|
import {
|
|
|
|
recordMarketplaceView,
|
|
|
|
recordLegacyTabView,
|
|
|
|
} from '../../utils/tracking';
|
2024-01-24 20:02:20 +00:00
|
|
|
import InstallNewProductModal from '../install-flow/install-new-product-modal';
|
2024-02-21 16:09:23 +00:00
|
|
|
import Promotions from '../promotions/promotions';
|
2024-04-17 10:13:24 +00:00
|
|
|
import ConnectNotice from '~/marketplace/components/connect-notice/connect-notice';
|
2023-07-20 13:53:06 +00:00
|
|
|
|
[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 <WooFooterItem> 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.
2023-08-23 15:49:36 +00:00
|
|
|
export default function Content(): JSX.Element {
|
|
|
|
const marketplaceContextValue = useContext( MarketplaceContext );
|
2023-10-04 16:59:34 +00:00
|
|
|
const [ products, setProducts ] = useState< Product[] >( [] );
|
|
|
|
const { setIsLoading, selectedTab } = marketplaceContextValue;
|
|
|
|
const query = useQuery();
|
|
|
|
|
|
|
|
// Get the content for this screen
|
|
|
|
useEffect( () => {
|
2023-10-04 17:38:18 +00:00
|
|
|
const abortController = new AbortController();
|
2023-10-24 10:05:25 +00:00
|
|
|
|
2023-10-24 12:54:31 +00:00
|
|
|
if ( query.tab && [ '', 'discover' ].includes( query.tab ) ) {
|
2023-10-04 16:59:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setIsLoading( true );
|
|
|
|
setProducts( [] );
|
|
|
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
|
|
|
if ( query.term ) {
|
|
|
|
params.append( 'term', query.term );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( query.category ) {
|
|
|
|
params.append(
|
|
|
|
'category',
|
|
|
|
query.category === '_all' ? '' : query.category
|
|
|
|
);
|
2023-10-24 12:54:31 +00:00
|
|
|
} else if ( query?.tab === 'themes' ) {
|
2023-10-04 16:59:34 +00:00
|
|
|
params.append( 'category', 'themes' );
|
2023-10-24 12:54:31 +00:00
|
|
|
} else if ( query?.tab === 'search' ) {
|
2023-10-04 16:59:34 +00:00
|
|
|
params.append( 'category', 'extensions-themes' );
|
|
|
|
}
|
|
|
|
|
|
|
|
const wccomSettings = getAdminSetting( 'wccomHelper', false );
|
|
|
|
if ( wccomSettings.storeCountry ) {
|
|
|
|
params.append( 'country', wccomSettings.storeCountry );
|
|
|
|
}
|
|
|
|
|
2023-10-12 09:29:43 +00:00
|
|
|
fetchSearchResults( params, abortController.signal )
|
2023-10-12 09:35:51 +00:00
|
|
|
.then( ( productList ) => {
|
2023-10-04 16:59:34 +00:00
|
|
|
setProducts( productList );
|
|
|
|
} )
|
|
|
|
.catch( () => {
|
|
|
|
setProducts( [] );
|
|
|
|
} )
|
|
|
|
.finally( () => {
|
2024-02-22 14:15:10 +00:00
|
|
|
// we are recording both the new and legacy events here for now
|
|
|
|
// they're separate methods to make it easier to remove the legacy one later
|
|
|
|
const marketplaceViewProps = {
|
|
|
|
view: query?.tab,
|
|
|
|
search_term: query?.term,
|
|
|
|
product_type: query?.section,
|
|
|
|
category: query?.category,
|
|
|
|
};
|
|
|
|
|
|
|
|
recordMarketplaceView( marketplaceViewProps );
|
|
|
|
recordLegacyTabView( marketplaceViewProps );
|
2023-10-04 16:59:34 +00:00
|
|
|
setIsLoading( false );
|
|
|
|
} );
|
2023-10-04 17:38:18 +00:00
|
|
|
return () => {
|
|
|
|
abortController.abort();
|
|
|
|
};
|
2023-10-24 10:05:25 +00:00
|
|
|
}, [
|
|
|
|
query.term,
|
|
|
|
query.category,
|
2023-10-24 12:54:31 +00:00
|
|
|
query?.tab,
|
2023-10-24 10:05:25 +00:00
|
|
|
setIsLoading,
|
|
|
|
query?.section,
|
|
|
|
] );
|
2023-10-04 16:59:34 +00:00
|
|
|
|
|
|
|
const renderContent = (): JSX.Element => {
|
|
|
|
switch ( selectedTab ) {
|
|
|
|
case 'extensions':
|
2023-10-06 08:17:56 +00:00
|
|
|
return (
|
|
|
|
<Products
|
|
|
|
products={ products }
|
|
|
|
categorySelector={ true }
|
|
|
|
type={ ProductType.extension }
|
|
|
|
/>
|
|
|
|
);
|
2023-10-04 16:59:34 +00:00
|
|
|
case 'themes':
|
2023-10-06 08:17:56 +00:00
|
|
|
return (
|
|
|
|
<Products
|
|
|
|
products={ products }
|
|
|
|
categorySelector={ true }
|
|
|
|
type={ ProductType.theme }
|
|
|
|
/>
|
|
|
|
);
|
2023-10-04 16:59:34 +00:00
|
|
|
case 'search':
|
2023-10-06 08:17:56 +00:00
|
|
|
return (
|
|
|
|
<SearchResults
|
|
|
|
products={ products }
|
|
|
|
type={ SearchResultType.all }
|
|
|
|
/>
|
|
|
|
);
|
2023-10-04 16:59:34 +00:00
|
|
|
case 'discover':
|
|
|
|
return <Discover />;
|
2023-09-21 14:00:22 +00:00
|
|
|
case 'my-subscriptions':
|
2023-10-18 09:14:14 +00:00
|
|
|
return (
|
|
|
|
<SubscriptionsContextProvider>
|
|
|
|
<MySubscriptions />
|
|
|
|
</SubscriptionsContextProvider>
|
|
|
|
);
|
2023-10-04 16:59:34 +00:00
|
|
|
default:
|
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-04 12:08:50 +00:00
|
|
|
return (
|
[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 <WooFooterItem> 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.
2023-08-23 15:49:36 +00:00
|
|
|
<div className="woocommerce-marketplace__content">
|
2024-02-21 16:09:23 +00:00
|
|
|
<Promotions />
|
2024-01-24 20:02:20 +00:00
|
|
|
<InstallNewProductModal products={ products } />
|
2024-04-17 10:13:24 +00:00
|
|
|
<ConnectNotice />
|
2023-10-04 16:59:34 +00:00
|
|
|
{ renderContent() }
|
[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 <WooFooterItem> 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.
2023-08-23 15:49:36 +00:00
|
|
|
</div>
|
2023-07-04 12:08:50 +00:00
|
|
|
);
|
2023-07-20 13:53:06 +00:00
|
|
|
}
|