feat: move search to save state between tabs
This commit is contained in:
parent
41c1079767
commit
8a5afe16e4
|
@ -10,6 +10,8 @@ import './ManagementTable.css'
|
|||
|
||||
type ManagementTableProps = {
|
||||
tab: string
|
||||
searchValue: string
|
||||
changeSearchValue: (value: string) => void
|
||||
}
|
||||
|
||||
type Validator = {
|
||||
|
@ -41,9 +43,8 @@ const isValidNumberOrAddress = (
|
|||
return false
|
||||
}
|
||||
|
||||
const ManagementTable = ({ tab }: ManagementTableProps) => {
|
||||
const ManagementTable = ({ tab, searchValue, changeSearchValue }: ManagementTableProps) => {
|
||||
const [validators, setValidators] = useState<Validator[]>([])
|
||||
const [searchValue, setSearchValue] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
setValidators(VALIDATORS_DATA)
|
||||
|
@ -55,10 +56,6 @@ const ManagementTable = ({ tab }: ManagementTableProps) => {
|
|||
.filter(validator => isValidNumberOrAddress(validator.number, validator.address, searchValue))
|
||||
}, [validators, tab, searchValue])
|
||||
|
||||
const changeSearchValue = (value: string) => {
|
||||
setSearchValue(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<YStack>
|
||||
<XStack space={'$3'} justifyContent="space-between" alignItems="center">
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
import { Tabs } from '@status-im/components'
|
||||
import { Stack } from 'tamagui'
|
||||
import { useState } from 'react'
|
||||
|
||||
import ManagementTable from './ManagementTable/ManagementTable'
|
||||
import { VALIDATOR_TABS } from '../../constants'
|
||||
|
||||
const ManagementTabs = () => {
|
||||
const [searchValue, setSearchValue] = useState('')
|
||||
|
||||
const changeSearchValue = (value: string) => {
|
||||
setSearchValue(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ width: '100%' }}>
|
||||
<Tabs defaultValue={VALIDATOR_TABS[0]}>
|
||||
|
@ -19,7 +26,11 @@ const ManagementTabs = () => {
|
|||
</Stack>
|
||||
{VALIDATOR_TABS.map(tab => (
|
||||
<Tabs.Content key={tab} value={tab} style={{ marginTop: '8px' }}>
|
||||
<ManagementTable tab={tab} />
|
||||
<ManagementTable
|
||||
tab={tab}
|
||||
searchValue={searchValue}
|
||||
changeSearchValue={changeSearchValue}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
))}
|
||||
</Tabs>
|
||||
|
|
Loading…
Reference in New Issue