componentDidMount() {
    const urlState = queryString.parse(location.search)

    // if urlState is empty, default to v2
    if (Object.keys(urlState).length === 0) {
      return this.setUrlState(this.props.defaultSearchState)
    }

    // otherwise, set to urlState
    return this.setUrlState(urlState)
  }
Example #2
0
export const getProductFilterForSearch = locationSearch => {
	const queryFilter = queryString.parse(locationSearch);

	return {
		categoryId: null,
		priceFrom: parseInt(queryFilter.price_from || 0),
		priceTo: parseInt(queryFilter.price_to || 0),
		search: queryFilter.search,
		sort: 'search'
	};
};
Example #3
0
  this.after('initialize', function() {
    const name = queryString.parse(window.location.search).serviceName
        || Cookies.get('last-serviceName');
    this.triggerChange(name);

    this.$node.chosen({search_contains: true});
    this.$node.next('.chosen-container');

    this.on('change', this.onChange);
    this.on(document, 'dataServiceNames', this.updateServiceNameDropdown);
  });
Example #4
0
export function convertToApiQuery(windowLocationSearch) {
  const query = queryString.parse(windowLocationSearch);
  // zipkin's api looks back from endTs
  if (query.startTs) {
    if (query.endTs > query.startTs) {
      query.lookback = String(query.endTs - query.startTs);
    }
    delete query.startTs;
  }
  return query;
}
Example #5
0
function SearchScreen(matchProps: Object) {
  const {location} = matchProps;
  const parsedSearch = qs.parse(location.search);
  const title = constructTitle(parsedSearch);

  return (
    <DocumentTitle title={title}>
      <SearchResultsContainer {...matchProps} searchTerm={parsedSearch.q} />
    </DocumentTitle>
  );
}
Example #6
0
const getSearchQueryFromUrl = (key) => {

  if (window.location.search) {
    const queryObj = queryString.parse(window.location.search);

    return key ? queryObj[key] : queryObj;
  }

  return '';

};
const _getUrlObj = () => {
  let params = QueryString.parse(loc.search);
  // ensure each param value is an array
  Object.keys(params).forEach((key) => {
    if (!(params[key] instanceof Array)) {
      params[key] = [params[key]];
    }
  });
  let path = loc.pathname ? loc.pathname.toString() : "/";
  return { path, params };
};
Example #8
0
function extractQueryParamValues(searchKeys) {
  const o = {};
  const qs = queryString.parse(window.location.search)

  Object.keys(searchKeys).forEach(x => {
    if (qs[x] !== undefined) {
      o[searchKeys[x]] = qs[x];
    }
  });

  return o;
}
Example #9
0
    withPropsOnChange(['location'], ({ location: { search } }) => {
      const q = parse(search);

      return {
        variables: {
          offset: parseIntParam(q.offset, 0),
          size: 1000,
          filters: parseFilterParam(q.filters, null),
          projects_sort: parseJSONParam(q.projects_sort, DEFAULT_PROJECT_SORT),
        },
      };
    })
Example #10
0
const setupIframe = ({ handleNewPayload, handleEnterView,
resizeEvent }) => {

	pymChild = pymIframe({ resizeEvent })

	// determine environment (chartbuilder, dev, prod [default])
	const parsed = parse(window.location.search)
	const env = parsed.env || 'prod'

	const options = { chartbuilder, dev, prod }
	options[env]({ handleNewPayload, handleEnterView })
}
Example #11
0
  return function (req, res, next) {
    if (req.ua && req.ua.browser === 'facebook') {
      try {
        log.info('Facebook scraper request')
        var query = queryString.parse(req.query())
        var item
        var meta = {}

        // get defaults
        if (req.pkg.vigour && req.pkg.vigour.fbOGDefaults) {
          if (req.pkg.vigour.fbOGDefaults.title) {
            meta['og:title'] = req.pkg.vigour.fbOGDefaults.title
          }
          if (req.pkg.vigour.fbOGDefaults.description) {
            meta['og:description'] = req.pkg.vigour.fbOGDefaults.description
          }
          if (req.pkg.vigour.fbOGDefaults.image) {
            meta['og:image'] = makeFbImageUrl(req.pkg.vigour.fbOGDefaults.image)
          }
        }

        // replace defaults with data from query string if present
        for (item in query) {
          if (item.indexOf('og:') === 0) {
            if (item === 'og:image') {
              meta[item] = makeFbImageUrl(query[item])
            } else {
              meta[item] = query[item]
            }
          }
        }
        if (meta['og:title'] || meta['og:description'] || meta['og:image']) {
          var str = ''
          for (var prop in meta) {
            str += '<meta property="' +
              prop +
              '" content="' +
              meta[prop] +
              '" />'
          }
          log.info('Sending %s', str)
          res.end(str)
        } else {
          throw new Error('No facebook OG data')
        }
      } catch (err) {
        log.warn({err: err}, 'Caught error')
        next()
      }
    } else {
      next()
    }
  }
Example #12
0
	componentDidMount() {
		const query = queryString.parse(this.props.location.search);
		api.getTeamInfo(query.teamId)
			.then(data => {
				this.setState({
					isLoading: false,
					avatar: data[0].crestUrl,
					name: data[0].name,
					players: data[1].players
				})
			})
	}
export default function pubnubActionSyncer(inputOptions) {
    const options = Object.assign({}, {
        mode: parse(window.location.search).syncMode,
    }, inputOptions);

    const { subscribe, publish } = pubnubConnection(options);

    options.onActionRecived = subscribe;
    options.sendAction = publish;
    
    return actionSyncMiddleware(options);
}
Example #14
0
    Router.beforePopState(({ url }) => {
      const index = url.indexOf('?');
      const asParams = index > -1;
      let params = {};
      if (asParams) {
        const paramsString = url.slice(url.indexOf('?') + 1);
        params = queryString.parse(paramsString);
      }

      onBeforeState(params);
      return true;
    });
 changeHistory(nodeId, method) {
   if (!this.props.options.isUseBrowserHistory()) return;
   if (this.doNotCallChangeHistory) {
     this.doNotCallChangeHistory = false;
     return;
   }
   const { runtime } = this.props;
   const params = queryString.parse(location.search);
   params.nodeId = nodeId;
   const answers = runtime.getAnswers().toJS();
   method.call(window.history, { answers }, null, `${location.pathname}?${queryString.stringify(params)}`);
 }
Example #16
0
// Re-render the app when window.location changes
async function onLocationChange(location, action) {
  // Remember the latest scroll position for the previous location
  scrollPositionsHistory[currentLocation.key] = {
    scrollX: window.pageXOffset,
    scrollY: window.pageYOffset,
  };
  // Delete stored scroll position for next page if any
  if (action === 'PUSH') {
    delete scrollPositionsHistory[location.key];
  }
  currentLocation = location;

  try {
    // Traverses the list of routes in the order they are defined until
    // it finds the first route that matches provided URL path string
    // and whose action method returns anything other than `undefined`.
    const route = await UniversalRouter.resolve(routes, {
      path: location.pathname,
      query: queryString.parse(location.search),
    });

    // Prevent multiple page renders during the routing process
    if (currentLocation.key !== location.key) {
      return;
    }

    if (route.redirect) {
      history.replace(route.redirect);
      return;
    }

    appInstance = ReactDOM.render(
      <App context={context}>{route.component}</App>,
      container,
      () => onRenderComplete(route, location),
    );
  } catch (error) {
    // Display the error in full-screen for development mode
    if (__DEV__) {
      appInstance = null;
      document.title = `Error: ${error.message}`;
      ReactDOM.render(<ErrorReporter error={error} />, container);
      throw error;
    }

    console.error(error); // eslint-disable-line no-console

    // Do a full page reload if error occurs during client-side navigation
    if (action && currentLocation.key === location.key) {
      window.location.reload();
    }
  }
}
  constructor(props) {
    super(props);

    const query = parseQueryString(this.props.history.location.search);

    let types = [],
      tags = [],
      search = '',
      limit = 24,
      sortOrder = '',
      sortField = '';

    if (query.types) { types = query.types.split(','); }
    if (query.tags) { tags = query.tags.split(','); }
    if (query.search) { search = query.search; }
    if (query.sortOrder) { sortOrder = query.sortOrder; }
    if (query.sortField) { sortField = query.sortField; }

    const filters = {
      search,
      types,
      tags
    };

    const sort = {
      field: sortField || 'lastEdited',
      order: sortOrder || 'desc'
    };

    if (query.limit) {
      limit = parseInt(query.limit);
    }

    this.setQueryUrl = this.setQueryUrl.bind(this);
    this.setLimit = this.setLimit.bind(this);
    this.setSearch = this.setSearch.bind(this);
    this.setChartType = this.setChartType.bind(this);
    this.handleSelectChange = this.handleSelectChange.bind(this);
    this.handleSortFieldChange = this.handleSortFieldChange.bind(this);
    this.handleSortOrderChange = this.handleSortOrderChange.bind(this);
    this.state = {
      filters,
      limit,
      sort,
      expanded: {
        search: true,
        sort: true,
        tags: true,
        chartType: true
      },
      selectedOption: []
    };
  }
  componentDidMount() {
    let { show } = this.props;

    // TODO -- something else should read from qs and then
    // dispatch to redux
    const buttonId = this.props.buttonId || '1';
    const qs = queryString.parse(browserShim.getLocation().search);
    const showId = _.get(qs, 'dcshow');
    if (showId == buttonId || show) {
      this.showModal();
    }
  }
Example #19
0
  render() {
    const { location } = this.props
    const urlState = queryString.parse(location.search)

    const filtersApplied =
      urlState.s !== undefined
        ? urlState.s // if theres a search term
        : urlState.d && !Array.isArray(urlState.d)
          ? urlState.d // if theres a single dependency
          : `Library` // if no search term or single dependency

    return (
      <Layout location={location}>
        <Helmet>
          <title>Starter Library</title>
          <meta
            name="description"
            content={`Gatsby Starters: ${filtersApplied}`}
          />
          <meta
            property="og:description"
            content={`Gatsby Starters: ${filtersApplied}`}
          />
          <meta
            name="twitter:description"
            content={`Gatsby Starters: ${filtersApplied}`}
          />
          <meta property="og:title" content={filtersApplied} />
          <meta property="og:type" content="article" />
          <meta name="twitter.label1" content="Reading time" />
          <meta name="twitter:data1" content={`1 min read`} />
        </Helmet>
        <RRSM
          {...this.props}
          location={location}
          render={({ setURLState, urlState }) => (
            <FilteredStarters
              {...this.props}
              setURLState={setURLState}
              urlState={urlState}
            />
          )}
          defaultSearchState={{ v: [`2`] }}
        />
        <Unbird
          dataSetId="5c113a828240aa564734d954"
          publicKey={process.env.UNBIRD_FEEDBACK_KEY_STARTERLIB}
          feedbackPrompt="Have feedback on the Starter Library?"
        />
      </Layout>
    )
  }
Example #20
0
 const listener = function(event) {
   if (event.source == popup) {
     window.removeEventListener('message', listener)
     window.clearInterval(watchdog)
     if (event.data.error && event.data.error.length > 0) {
       console.log(event.data)
       reject(event.data.error)
     } else {
       const token = queryString.parse(event.data)
       resolve(token)
     }
   }
 }
  setSsoParams = () => {
    const parsed = queryString.parse(location.search); //eslint-disable-line

    if (this.state.ssoParamsPresent) {
      this.setState(
        {
          sso: parsed.sso,
          sig: parsed.sig
        },
        this.checkSsoLoggedIn
      );
    }
  };
function urlParamOverrides (response) {
  const {reportFor, studentId} = queryString.parse(window.location.search)
  if (reportFor) {
    response.type = reportFor
  }
  if (studentId && reportFor === 'student') {
    response.studentId = studentId
    response.hideControls = true
    if (response.result) {
      response.result.hideControls = true
    }
  }
}
Example #23
0
    function parseHash (url){

        var path = url.split('?')[0];
        if ((path.charAt(path.length-1) === '/') && (path.length > 1)){
            path = path.substr(0,path.length-1);  //remove ultimo caracter (o / )
        }
        var search = url.split('?')[1] || '' ;
        return {
            hash:url,
            path:path,
            search:qs.parse(search)
        };
    }
Example #24
0
const modalTemplate = (imageUrl, originalUrl, type, videoEmbed = null) => {
  if (type === 'image') {
    const parsed = qs.parse(imageUrl);
    imageUrl = parsed[Object.keys(parsed)[0]];
  }

  return Mustache.render(templates.modal, Object.assign(defaultData.modal, {
    imageUrl,
    videoEmbed,
    originalUrl,
    isVideo: type !== 'image',
  }));
};
export default (href: Href): Location => {
  if (typeof href === 'string') {
    const { search = '', ...other } = parsePath(href);
    const query = search && qs.parse(search);

    return query ? { ...other, query, search } : { ...other };
  }

  const { search, query } = href;

  const resolvedSearch =
    search ||
    (query && Object.keys(query).length && `?${qs.stringify(query)}`) ||
    '';
  const resolvedQuery = query || qs.parse(search || '');

  return {
    ...href,
    search: resolvedSearch,
    query: resolvedQuery
  };
};
    handleLogin(token) {
        LoginStore.storeToken(token);

        var tokenParameters = queryString.parse(decodeURIComponent(token));

        // Fetch the logged in user. TODO: This definitely won't work if the token structure is changed
        DirectorySource.findUser(tokenParameters.ManyWhoUserId, tokenParameters.Username).then(data => {
            this.setState({
                authenticated: true,
                user: data
            });
        });
    }
const About = ({location, match}) => {
  const query = queryString.parse(location.search);

  const { color } = query;

  return (
    <div>
      <h2 style={{color}}>소개</h2>
      <p>
        안녕하세요, 저는 {match.params.name}입니다.
      </p>
    </div>
  );
};
Example #28
0
  toggleModal = () => {
    const { pathname, search } = this.props.location
    const queryStrings = qs.parse(search)

    delete queryStrings.edit
    delete queryStrings.new

    const url = pathname + '?' + qs.stringify(queryStrings)
    this.props.history.push(url)

    // toggleModal() closes modal, but it is not called after form submits  
    // copy unfinished form to global window and check for it inside FormWizard 
    window.__unfinishedNewEvent = cloneDeep(this.state.form.getModel())
  }
Example #29
0
    (new GoodTables()).run('data').then(function(VR) {
      var params = fetchMock.calls('mock1');
          _.isEqual(queryString.parse(params[0][0].split('?')[1]), {
            data             : 'data',
            fail_fast        : 'true',
            format           : 'csv',
            ignore_empty_rows: 'false',
            report_limit     : '1000',
            report_type      : 'basic',
            row_limit        : '20000'
          }).should.be.true;

          done();
    });
Example #30
0
  handleOpenURL = ({ url }) => {
    const [, queryStringFromUrl] = url.match(/\?(.*)/);
    const { state, code } = queryString.parse(queryStringFromUrl);

    if (stateRandom === state) {
      this.setState({ code });

      this.props.auth(code, state);
    }

    if (Platform.OS === 'ios') {
      SafariView.dismiss();
    }
  };