Download wp-calypso/client/my-sites/jetpack-search/controller.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.26 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/jetpack-search/controller.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/my-sites/jetpack-search/controller.js
-
curl -L -o controller.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/jetpack-search/controller.js
4.26 kB
| import { isJetpackSearchSlug } from '@automattic/calypso-products'; | |
| import Debug from 'debug'; | |
| import QueryJetpackModules from 'calypso/components/data/query-jetpack-modules'; | |
| import QuerySiteSettings from 'calypso/components/data/query-site-settings'; | |
| import QueryUserPurchases from 'calypso/components/data/query-user-purchases'; | |
| import IsJetpackDisconnectedSwitch from 'calypso/components/jetpack/is-jetpack-disconnected-switch'; | |
| import { UpsellProductCardPlaceholder } from 'calypso/components/jetpack/upsell-product-card'; | |
| import UpsellSwitch from 'calypso/components/jetpack/upsell-switch'; | |
| import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud'; | |
| import { | |
| hasLoadedUserPurchasesFromServer, | |
| isFetchingUserPurchases, | |
| } from 'calypso/state/purchases/selectors'; | |
| import getSiteSetting from 'calypso/state/selectors/get-site-setting'; | |
| import isFetchingJetpackModules from 'calypso/state/selectors/is-fetching-jetpack-modules'; | |
| import isJetpackModuleActive from 'calypso/state/selectors/is-jetpack-module-active'; | |
| import { isRequestingSiteSettings } from 'calypso/state/site-settings/selectors'; | |
| import { isJetpackSite } from 'calypso/state/sites/selectors'; | |
| import getSelectedSiteId from 'calypso/state/ui/selectors/get-selected-site-id'; | |
| import JetpackSearchDisconnected from './disconnected'; | |
| import JetpackSearchUpsell from './jetpack-search-upsell'; | |
| import SearchMain from './main'; | |
| import WpcomSearchUpsellPlaceholder from './wpcom-search-upsell-placeholder'; | |
| const debug = new Debug( 'calypso:my-sites:search:controller' ); | |
| export function showUpsellIfNoSearch( context, next ) { | |
| debug( 'controller: showUpsellIfNoSearch', context.params ); | |
| const state = context.store.getState(); | |
| const siteId = getSelectedSiteId( state ); | |
| const isJetpack = isJetpackSite( state, siteId ); | |
| const QueryComponent = isJetpack ? QueryJetpackModules : QuerySiteSettings; | |
| const getSearchState = isJetpack ? getJetpackSearchState : getWPComSearchState; | |
| const isRequestingForSite = ( asyncState, asyncSiteId ) => { | |
| // On Jetpack sites, we need to check if the search module is active, on WPCom sites we | |
| // check 'jetpack_search_enabled' in the site settings. | |
| const isRequestingSearchStatus = isJetpack | |
| ? isFetchingJetpackModules | |
| : isRequestingSiteSettings; | |
| // We also need to wait for user purchases to be loaded, or we risk flashing the upsell to | |
| // customers who already own the product. | |
| const isRequestingPurchases = | |
| ! hasLoadedUserPurchasesFromServer( asyncState ) || isFetchingUserPurchases( asyncState ); | |
| return isRequestingPurchases || isRequestingSearchStatus( asyncState, asyncSiteId ); | |
| }; | |
| const UpsellPlaceholder = isJetpackCloud() | |
| ? UpsellProductCardPlaceholder | |
| : WpcomSearchUpsellPlaceholder; | |
| context.primary = ( | |
| <> | |
| <QueryUserPurchases /> | |
| <UpsellSwitch | |
| UpsellComponent={ JetpackSearchUpsell } | |
| QueryComponent={ QueryComponent } | |
| getStateForSite={ getSearchState } | |
| isRequestingForSite={ isRequestingForSite } | |
| display={ context.primary } | |
| productSlugTest={ isJetpackSearchSlug } | |
| > | |
| <UpsellPlaceholder /> | |
| </UpsellSwitch> | |
| </> | |
| ); | |
| next(); | |
| } | |
| export function showJetpackIsDisconnected( context, next ) { | |
| debug( 'controller: showJetpackIsDisconnected', context.params ); | |
| context.primary = ( | |
| <IsJetpackDisconnectedSwitch | |
| trueComponent={ <JetpackSearchDisconnected /> } | |
| falseComponent={ context.primary } | |
| /> | |
| ); | |
| next(); | |
| } | |
| /* handles /jetpack-search/:site, see `jetpackSearchMainPath` */ | |
| export function jetpackSearchMain( context, next ) { | |
| debug( 'controller: jetpackSearchMain', context.params ); | |
| context.primary = <SearchMain />; | |
| next(); | |
| } | |
| // Selectors used for the Search UpsellSwitch (above) | |
| function getJetpackSearchState( state, siteId ) { | |
| const isSearchModuleActive = isJetpackModuleActive( state, siteId, 'search' ); | |
| return { | |
| state: isSearchModuleActive ? 'active' : 'unavailable', | |
| ...( ! isSearchModuleActive && { reason: 'search_not_active' } ), | |
| }; | |
| } | |
| function getWPComSearchState( state, siteId ) { | |
| const isSearchSettingEnabled = getSiteSetting( state, siteId, 'jetpack_search_enabled' ); | |
| return { | |
| state: isSearchSettingEnabled ? 'active' : 'unavailable', | |
| ...( ! isSearchSettingEnabled && { reason: 'search_not_active' } ), | |
| }; | |
| } | |