Skip to content

Commit ec71dbb

Browse files
committed
🐛 update UI interaction
1 parent 1349ebe commit ec71dbb

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

components/LaunchPad/Sale/CreateTokenSale.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1515
*/
1616

17-
import React, { useContext, useState } from 'react'
17+
import React, { useContext, useEffect, useState } from 'react'
1818
import { CreatorAddress } from '../CreatorAddress'
1919
import { Note } from '../note'
2020

@@ -68,9 +68,7 @@ export const CreateTokenSale = () => {
6868
setFormData({ ...formData, [e.target.name]: e.target.value })
6969
}
7070

71-
const onSearchAsset = (e) => {
72-
const searchValue = e.target.value
73-
setFormData({ ...formData, [e.target.name]: searchValue })
71+
const fetchUserAssets = () => {
7472
setAssetList([
7573
{
7674
assetId: 7789624,
@@ -121,18 +119,19 @@ export const CreateTokenSale = () => {
121119
createdAt: new Date().toLocaleString()
122120
}
123121
])
124-
setShowTable(true)
125122
}
126123

124+
useEffect(() => {
125+
fetchUserAssets()
126+
}, [])
127+
127128
const onSubmit = async (e) => {
128129
e.preventDefault()
129130

130131
setLoading(true)
131132
setLoading(false)
132133
}
133134

134-
135-
136135
return (
137136
<>
138137
<Typography variant="subtitle1" sx={styles.title}>
@@ -167,10 +166,16 @@ export const CreateTokenSale = () => {
167166
placeholder="ASA Asset ID"
168167
name="assetId"
169168
value={assetId}
170-
onChange={(e) => onSearchAsset(e)}
169+
onChange={(e) => onChange(e)}
170+
onFocus={() => setShowTable(true)}
171171
sx={styles.input}
172172
/>
173-
<SearchTable columns={columns} rowData={assetList} showTable={showTable} />
173+
<SearchTable
174+
columns={columns}
175+
rowData={assetList}
176+
showTable={showTable}
177+
setShowTable={setShowTable}
178+
/>
174179
</Box>
175180
</Box>
176181

components/LaunchPad/Sale/SearchTable.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useState } from 'react'
1+
import React, { useEffect, useMemo, useRef, useState } from 'react'
22

33
//MUI components
44
import Paper from '@mui/material/Paper'
@@ -40,12 +40,15 @@ type columnType = {
4040
export const SearchTable = ({
4141
columns,
4242
rowData,
43-
showTable
43+
showTable,
44+
setShowTable
4445
}: {
4546
columns: Array<columnType>
4647
rowData: Array<unknown>
4748
showTable: boolean
49+
setShowTable: (v: boolean) => void
4850
}) => {
51+
const dropdownRef = useRef(null)
4952
const [order, setOrder] = useState<'asc' | 'desc'>('desc')
5053
const [orderBy, setOrderBy] = useState('assetName')
5154

@@ -63,6 +66,20 @@ export const SearchTable = ({
6366
}
6467
}, [rowData, order, orderBy])
6568

69+
const handleClickOutside = (event) => {
70+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
71+
setShowTable(false)
72+
}
73+
}
74+
75+
useEffect(() => {
76+
document.addEventListener('click', handleClickOutside, true)
77+
return () => {
78+
document.removeEventListener('click', handleClickOutside, true)
79+
}
80+
// eslint-disable-next-line react-hooks/exhaustive-deps
81+
}, [])
82+
6683
if (rowData.length === 0 || !showTable) {
6784
return null
6885
}

0 commit comments

Comments
 (0)