How to use the @shopgate/pwa-common/selectors/history.getSearchPhrase function in @shopgate/pwa-common

To help you get started, we’ve selected a few @shopgate/pwa-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / commerce / filter / subscriptions / index.js View on Github external
subscribe(searchRouteWasUpdated$, ({ dispatch, getState }) => {
    // Reset the current activeFilters object and update the search phrase with the new one
    const searchPhrase = getSearchPhrase(getState());
    dispatch(setActiveFilters({}, { searchPhrase }));
    dispatch(getFilters());
  });
github shopgate / pwa / components / Navigator / subscriptions.js View on Github external
subscribe(searchRouteDidEnter$, ({ dispatch, getState }) => {
    const state = getState();

    // If search input is empty, set it to the value of the search query param.
    if (!state.navigator.searchPhrase) {
      dispatch(setSearchPhrase(getSearchPhrase(state)));
    }
  });
github shopgate / pwa / libraries / commerce / filter / actions / commitTemporaryFilters.js View on Github external
let temporaryFilters;

  if (roundDisplayAmounts) {
    temporaryFilters = getTemporaryFiltersWithRoundedDisplayAmounts(state);
  } else {
    temporaryFilters = getTemporaryFilters(state);
  }

  if (!activeFilters.length) {
    logger.error('Tried to submit temporary filters, but no active filter stack was created.');
    return;
  }

  if (!shallowEqual(temporaryFilters, activeFilters[activeFilters.length - 1].filters)) {
    const categoryId = getCurrentCategoryId(state);
    const searchPhrase = getSearchPhrase(state);

    dispatch(setActiveFilters(temporaryFilters, {
      ...categoryId && { categoryId },
      ...searchPhrase && { searchPhrase },
    }));

    const params = {
      ...categoryId && { categoryId },
      ...searchPhrase && { searchPhrase },
      limit: ITEMS_PER_LOAD,
      offset: 0,
      sort: getSortOrder(state),
    };

    // Enrich the parameters with the getProducts related properties for the initial product "page".
    setTimeout(() => {
github shopgate / pwa / search / actions / getSearchResults.js View on Github external
const getSearchResults = (offset = 0) => (dispatch, getState) => {
  const state = getState();
  const limit = ITEMS_PER_LOAD;
  const searchPhrase = getSearchPhrase(state);

  if (!searchPhrase) {
    return;
  }

  const sort = getSortOrder(state);

  const promise = dispatch(getProducts({
    params: {
      searchPhrase,
      offset,
      limit,
      sort,
    },
    onBeforeDispatch: () => {
      // Dispatch the request action before the related pipeline request is executed.
github shopgate / pwa / themes / theme-gmd / components / Navigator / actions / submitSearch.js View on Github external
if (!searchActive) {
    // Reset search phrase.
    dispatch(setNavigatorSearchPhrase(''));
    // Show search input.
    dispatch(toggleNavSearchField(true));
    return;
  } else if (!searchPhrase) {
    // Hide search input.
    dispatch(toggleNavSearchField(false));
    return;
  }

  // Perform search by entering/updating search route.
  const { history } = state;
  const { sort, ...otherParams } = history.queryParams;
  const prevSearchPhrase = getSearchPhrase(state);

  dispatch(setViewTop(true));

  // Set up next history location.
  const historyLocation = {
    pathname: SEARCH_PATH,
    params: {
      ...otherParams,
      s: searchPhrase,
    },
  };

  // Check if we are already on the search route.
  if (history.pathname.startsWith(SEARCH_PATH)) {
    if (searchPhrase !== prevSearchPhrase) {
      // Preserve current history state
github shopgate / pwa / components / Navigator / actions / index.js View on Github external
if (!searchActive) {
    // Reset search phrase
    dispatch(setSearchPhrase(''));
    // Show search input
    dispatch(toggleSearch(true));
    return;
  } else if (!searchPhrase) {
    // Hide search input
    dispatch(toggleSearch(false));
    return;
  }

  // Perform search by entering/updating search route
  const { history } = state;
  const { sort, ...otherParams } = history.queryParams;
  const prevSearchPhrase = getSearchPhrase(state);

  // Set up next history location.
  const historyLocation = {
    pathname: SEARCH_PATH,
    params: {
      ...otherParams,
      s: searchPhrase,
    },
    state: {
      // Force view to scroll back to top
      viewTop: true,
    },
  };

  // Check if we are already on the search route
  if (history.pathname.startsWith(SEARCH_PATH)) {
github shopgate / pwa / filter / actions / index.js View on Github external
const buildFilterParams = (state) => {
  const categoryId = getCurrentCategoryId(state);
  const searchPhrase = getSearchPhrase(state);

  return {
    ...categoryId && { categoryId },
    ...searchPhrase && { searchPhrase },
  };
};
github shopgate / pwa / components / Navigator / components / Content / components / Search / actions / setSearchPhrase.js View on Github external
const setSearchPhrase = query => (dispatch, getState) => {
  const searchPhrase = getSearchPhrase(getState()) || '';

  if (query === searchPhrase) {
    return;
  }

  dispatch(setPhrase(query));
};
github shopgate / pwa / pages / Search / connector.js View on Github external
const mapStateToProps = state => ({
  isLoading: isViewLoading(state, SEARCH_PATH),
  isFilterBarShown: isFilterBarShown(state),
  searchPhrase: getSearchPhrase(state),
  ...getProductsResult(state),
});