@shopgate/engage
Version:
Shopgate's ENGAGE library.
7 lines • 1.93 kB
JavaScript
import React,{useMemo,useCallback}from'react';import PropTypes from'prop-types';import{useSelector}from'react-redux';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{getPreferredLocation}from"../selectors";import{STORE_FINDER_PATTERN}from"../constants";import{StoreFinderContext}from"../locations.context";import connect from"./StoreFinder.connector";import{useNavigation}from"../../core";/**
* @param {Object} props The component props
* @returns {JSX}
*/var StoreFinderProvider=function StoreFinderProvider(_ref){var children=_ref.children,locations=_ref.locations,isFetching=_ref.isFetching,shopSettings=_ref.shopSettings,userSearch=_ref.userSearch,storeFinderSearch=_ref.storeFinderSearch,selectGlobalLocation=_ref.selectGlobalLocation,selectLocation=_ref.selectLocation;var _useNavigation=useNavigation(),pop=_useNavigation.pop;var selectedLocation=useSelector(getPreferredLocation);var selectLocationCb=useCallback(function(location){selectLocation(location,true);selectGlobalLocation(location);// Back navigation
pop();},[selectLocation,selectGlobalLocation,pop]);/**
* @param {bool} loading
*/var setIsLoading=useCallback(function(loading){if(loading){LoadingProvider.setLoading(STORE_FINDER_PATTERN);return;}LoadingProvider.unsetLoading(STORE_FINDER_PATTERN);},[]);var value=useMemo(function(){return{locations:locations,selectedLocation:selectedLocation,selectLocation:selectLocationCb,isFetching:isFetching,shopSettings:shopSettings,userSearch:userSearch,storeFinderSearch:storeFinderSearch,setIsLoading:setIsLoading};},[isFetching,locations,selectLocationCb,selectedLocation,shopSettings,storeFinderSearch,userSearch,setIsLoading]);return React.createElement(StoreFinderContext.Provider,{value:value},children);};StoreFinderProvider.defaultProps={children:null,locations:[],isFetching:false,shopSettings:null,userSearch:null,storeFinderSearch:null};export default connect(StoreFinderProvider);