Reset cover image on metadata storage method change
This commit is contained in:
parent
6a80af95c2
commit
5e253f24b7
@ -19,11 +19,13 @@ import { uid } from 'utils/random'
|
||||
|
||||
import { TextInput } from '../forms/FormInput'
|
||||
import type { UploadMethod } from './OffChainMetadataUploadDetails'
|
||||
import type { MetadataStorageMethod } from './OpenEditionMinterCreator'
|
||||
|
||||
interface CollectionDetailsProps {
|
||||
onChange: (data: CollectionDetailsDataProps) => void
|
||||
uploadMethod: UploadMethod
|
||||
coverImageUrl: string
|
||||
metadataStorageMethod: MetadataStorageMethod
|
||||
}
|
||||
|
||||
export interface CollectionDetailsDataProps {
|
||||
@ -37,7 +39,12 @@ export interface CollectionDetailsDataProps {
|
||||
updatable: boolean
|
||||
}
|
||||
|
||||
export const CollectionDetails = ({ onChange, uploadMethod, coverImageUrl }: CollectionDetailsProps) => {
|
||||
export const CollectionDetails = ({
|
||||
onChange,
|
||||
uploadMethod,
|
||||
metadataStorageMethod,
|
||||
coverImageUrl,
|
||||
}: CollectionDetailsProps) => {
|
||||
const [coverImage, setCoverImage] = useState<File | null>(null)
|
||||
const [timestamp, setTimestamp] = useState<Date | undefined>()
|
||||
const [explicit, setExplicit] = useState<boolean>(false)
|
||||
@ -45,6 +52,8 @@ export const CollectionDetails = ({ onChange, uploadMethod, coverImageUrl }: Col
|
||||
|
||||
const initialRender = useRef(true)
|
||||
|
||||
const coverImageInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const nameState = useInputState({
|
||||
id: 'name',
|
||||
name: 'name',
|
||||
@ -119,6 +128,12 @@ export const CollectionDetails = ({ onChange, uploadMethod, coverImageUrl }: Col
|
||||
reader.readAsArrayBuffer(event.target.files[0])
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setCoverImage(null)
|
||||
// empty the element so that the same file can be selected again
|
||||
coverImageInputRef.current!.value = ''
|
||||
}, [metadataStorageMethod])
|
||||
|
||||
useEffect(() => {
|
||||
if (initialRender.current) {
|
||||
initialRender.current = false
|
||||
@ -171,6 +186,7 @@ export const CollectionDetails = ({ onChange, uploadMethod, coverImageUrl }: Col
|
||||
)}
|
||||
id="cover-image"
|
||||
onChange={selectCoverImage}
|
||||
ref={coverImageInputRef}
|
||||
type="file"
|
||||
/>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user