components#ExploreApiSearch TypeScript Examples

The following examples show how to use components#ExploreApiSearch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.tsx    From substrate-api-explorer with Apache License 2.0 6 votes vote down vote up
Main = ({ api, match }: Props) => {
  const location = useLocation()

  return (
    <S.Wrapper>
      <S.Title>
        <S.CategoryName>{api.url}</S.CategoryName>
        <S.Search>
          <ExploreApiSearch focusOnMount={location?.state?.fromSearch} />
        </S.Search>
      </S.Title>
      {_isEmpty(api.description) ? (
        <S.Empty>There&apos;s nothing in here ?</S.Empty>
      ) : (
        Object.keys(api.description)
          .sort()
          .map((item, idx) => (
            <ExploreApiLink
              key={`exploreApi-category-${idx}`}
              to={`${match.url}/${item}`}
              name={item}
              description={api.description[item].description}
            />
          ))
      )}
    </S.Wrapper>
  )
}
Example #2
Source File: ExploreApiSearch.stories.tsx    From substrate-api-explorer with Apache License 2.0 6 votes vote down vote up
storiesOf('COMPONENTS|ExploreApiSearch', module).add('default', () => {
  const focusOnMountKnob = boolean('focusOnMount', true, 'props')
  const queryKnob = text('query', 'Default value', 'props')

  return (
    <div style={{ padding: '24px' }}>
      <ExploreApiSearch
        focusOnMount={focusOnMountKnob}
        query={queryKnob}
        storybookDemo
      />
    </div>
  )
})
Example #3
Source File: Search.tsx    From substrate-api-explorer with Apache License 2.0 5 votes vote down vote up
Search = ({ match }: Props) => {
  const api = useSelector(apiSelector)
  const { searchQuery } = match.params
  const [foundItems, setFoundItems] = useState<[string, string][]>([])

  const handleSearch = () => {
    const regex = new RegExp(
      '^(?=.*' +
        decodeURIComponent(searchQuery)
          .trim()
          .split(' ')
          .join(')(?=.*') +
        ').*$',
      'gi'
    )

    const foundItems = api.current.search.filter(([path, description]) => {
      return regex.test(path + description)
    })

    setFoundItems(foundItems)
  }

  useEffect(handleSearch, [searchQuery])

  return (
    <S.Wrapper>
      <S.Title>
        <S.CategoryName>Search API</S.CategoryName>
        <S.Search>
          <ExploreApiSearch focusOnMount query={searchQuery} />
        </S.Search>
      </S.Title>
      {_isEmpty(foundItems) ? (
        <S.Empty>Nothing was found ?</S.Empty>
      ) : (
        foundItems.sort().map((item, idx) => {
          const link = item[0].split('.')

          return (
            <ExploreApiLink
              key={`searchResult-${idx}`}
              to={{
                pathname: `/explore-api/${link[1]}/${link[2]}/${link[3]}`,
                state: { routeName: 'Search', search: searchQuery }
              }}
              name={item[0]}
              description={item[1]}
            />
          )
        })
      )}
    </S.Wrapper>
  )
}