components#ExploreApiLink TypeScript Examples
The following examples show how to use
components#ExploreApiLink.
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: Category.tsx From substrate-api-explorer with Apache License 2.0 | 6 votes |
Category = ({ api, match }: Props) => {
const { category } = match.params
return (
<S.Wrapper>
<S.Title>
<S.CategoryName>
<strong>{category}</strong>
<S.SearchPlaceholder />
</S.CategoryName>
<ExploreApiBreadcrumbs match={match} />
</S.Title>
{_isEmpty(api.description[category]) ? (
<S.Empty>There's nothing in here ?</S.Empty>
) : (
Object.entries(api.description[category].categories)
.sort((a: [string, Method], b: [string, Method]) => {
return a[0] < b[0] ? -1 : 1
})
.map((item: [string, Method], idx) => (
<ExploreApiLink
key={`exploreApi-subcategory-${idx}`}
to={`${match.url}/${item[0]}`}
name={item[0]}
description={item[1].description}
/>
))
)}
</S.Wrapper>
)
}
Example #2
Source File: Main.tsx From substrate-api-explorer with Apache License 2.0 | 6 votes |
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'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 #3
Source File: ExploreApiLink.stories.tsx From substrate-api-explorer with Apache License 2.0 | 6 votes |
storiesOf('COMPONENTS|ExploreApiLink', module)
.addDecorator(story => (
<MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
))
.add('default', () => {
const nameKnob = text('name', 'fooBar', 'props')
const descriptionKnob = text(
'description',
'This is the description',
'props'
)
return (
<div style={{ maxWidth: 800, padding: '24px' }}>
<ExploreApiLink name={nameKnob} description={descriptionKnob} />
</div>
)
})
Example #4
Source File: Subcategory.tsx From substrate-api-explorer with Apache License 2.0 | 5 votes |
Subcategory = ({ api, match }: Props) => {
const { category, subcategory } = match.params
return (
<S.Wrapper>
<S.Title>
<S.CategoryName>
<div>
<strong>{subcategory}</strong>
<span>
Available {category === 'consts' ? 'consts' : 'methods'}:
</span>
</div>
</S.CategoryName>
<ExploreApiBreadcrumbs match={match} />
</S.Title>
{/* We have to disable ESLint here because it doesn't
play nicely with Prettier */}
{/* eslint-disable indent */}
{_isEmpty(api.description[category]?.categories[subcategory]?.methods) ? (
<S.Empty>There's nothing in here ?</S.Empty>
) : (
Object.entries(
api.description[category]?.categories[subcategory]?.methods
)
.sort((a: [string, Method], b: [string, Method]) => {
return a[0] < b[0] ? -1 : 1
})
.map((item: [string, Method], idx) =>
category === 'consts' ? (
<ExploreApiConst
key={`exploreApi-const-${idx}`}
name={item[0]}
path={`api.consts.${subcategory}.${item[0]}`}
type={item[1].type}
description={item[1].description}
value={JSON.stringify(
api.promise[category][subcategory][item[0]]
)}
/>
) : (
<ExploreApiLink
key={`exploreApi-subcategory-${idx}`}
to={`${match.url}/${item[0]}`}
name={item[0]}
params={item[1].params}
description={item[1].description}
/>
)
)
)}
{/* eslint-enable indent */}
</S.Wrapper>
)
}
Example #5
Source File: Search.tsx From substrate-api-explorer with Apache License 2.0 | 5 votes |
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>
)
}