Skip to content

Commit 99f1929

Browse files
authored
Added name query parameter handling (#175)
* Added `name` query parameter handling Added a `name` query parameter handling code to the `Filters.tsx` component. This handler will set a filter on the `Name` column of a table (either opcodes or precompiles) with the value of the query parameter. In example, `evm.codes/precompiled?name=ec` will yield a search on the precompiles table for precompiles containing the sequence `ec` (ecrecover, ecpairing). On the other hand, `evm.codes/?name=self` will yield a search on the opcodes table for opcodes containing the sequence `self` (SELFDESTRUCT, SELFBALANCE). * lint fixes (OMG...)
1 parent ac9e797 commit 99f1929

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

components/Reference/Filters.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { useState, useMemo } from 'react'
1+
import { useState, useMemo, useEffect } from 'react'
22

33
import debounce from 'lodash.debounce'
4+
import { useRouter } from 'next/router'
45
import Select, { OnChangeValue } from 'react-select'
56

67
import { Input } from 'components/ui'
@@ -13,6 +14,7 @@ type Props = {
1314
}
1415

1516
const Filters = ({ onSetFilter, isPrecompiled = false }: Props) => {
17+
const router = useRouter()
1618
const [searchKeyword, setSearchKeyword] = useState('')
1719
const [searchFilter, setSearchFilter] = useState({
1820
value: 'name',
@@ -43,6 +45,20 @@ const Filters = ({ onSetFilter, isPrecompiled = false }: Props) => {
4345
setSearchFilter(option)
4446
}
4547

48+
// Change filter and search opcode according to query param
49+
useEffect(() => {
50+
const query = router.query
51+
52+
if ('name' in query) {
53+
// Change the filter type to Name
54+
handleSearchFilterChange({ label: 'Name', value: 'name' })
55+
setSearchKeyword(query.name as string)
56+
handleKeywordChange(query.name as string)
57+
router.push(router)
58+
}
59+
// eslint-disable-next-line react-hooks/exhaustive-deps
60+
}, [router.isReady])
61+
4662
return (
4763
<div className="flex items-center md:justify-end">
4864
<span className="hidden md:inline-block text-sm text-gray-400 mr-3">

0 commit comments

Comments
 (0)