Skip to content

Commit

Permalink
fix: Add clear for uploaded raw tx json
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Jul 25, 2024
1 parent fe3f421 commit 18d9a2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/neuron/src/pages/tools/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/neuron/src/pages/tools/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
backdrop-filter: blur(40px);

.upload {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -56,6 +57,13 @@
align-items: center;
justify-content: center;
}

.clear {
position: absolute;
top: 16px;
right: 16px;
cursor: pointer;
}
}

.node {
Expand Down
27 changes: 21 additions & 6 deletions packages/neuron/src/pages/tools/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { GetStaticProps, type NextPage } from 'next'
import { useTranslation } from 'next-i18next'
import Image from 'next/image'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { ChangeEventHandler, DragEventHandler, useCallback, useState } from 'react'
import { ChangeEventHandler, DragEventHandler, useCallback, useRef, useState } from 'react'
import ImgNeuronLogo from './neuron-logo.png'
import ToolsIcon from './tools.png'
import UploadSvg from './upload.svg'
import FileSvg from './file.svg'
import RefreshSvg from './refresh.svg'
import DownloadSvg from './download.svg'
import CloseSvg from './close.svg'
import { Page } from '../../components/Page'
import styles from './index.module.scss'
import { Button } from '../../components/Button'
Expand All @@ -23,6 +24,17 @@ const Download: NextPage<PageProps> = () => {
const [processFile, setProcessFile] = useState<File | undefined>()
const [processedJSON, setProcessedJSON] = useState<object | undefined>()
const [err, setErr] = useState<string | undefined>()
const inputRef = useRef<HTMLInputElement | null>(null)
const onClearFile = useCallback((e: Event) => {
e.stopPropagation()
e.preventDefault()
setProcessFile(undefined)
setProcessedJSON(undefined)
setErr(undefined)
if (inputRef.current) {
inputRef.current.value = ''
}
}, [])
const onDrag: DragEventHandler<HTMLLabelElement> = useCallback(
e => {
e.preventDefault()
Expand Down Expand Up @@ -119,12 +131,15 @@ const Download: NextPage<PageProps> = () => {
<div>{t('Raw_Transaction_Conversion')}</div>
<div>{t('Raw_Transaction_Conversion_Tip')}</div>
<label className={styles.upload} onDrop={onDrag} onDragOver={onDrag}>
<input type="file" accept=".json" onChange={onChooseFile} />
<input type="file" accept=".json" onChange={onChooseFile} ref={inputRef} />
{processFile ? (
<div className={styles.file}>
<FileSvg />
{processFile.name}
</div>
<>
<CloseSvg className={styles.clear} onClick={onClearFile} />
<div className={styles.file}>
<FileSvg />
{processFile.name}
</div>
</>
) : (
<>
<UploadSvg />
Expand Down

0 comments on commit 18d9a2f

Please sign in to comment.