refactor(create): update location state to keep latest selected files
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 43s
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 43s
This commit is contained in:
parent
abea8dcd15
commit
1827a20755
@ -79,7 +79,7 @@ import {
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { getSigitFile, SigitFile } from '../../utils/file.ts'
|
||||
import { generateTimestamp } from '../../utils/opentimestamps.ts'
|
||||
import { Autocomplete } from '@mui/lab'
|
||||
import { Autocomplete } from '@mui/material'
|
||||
import _, { truncate } from 'lodash'
|
||||
import * as React from 'react'
|
||||
import { AvatarIconButton } from '../../components/UserAvatarIconButton'
|
||||
@ -99,7 +99,7 @@ export const CreatePage = () => {
|
||||
|
||||
const [title, setTitle] = useState(`sigit_${formatTimestamp(Date.now())}`)
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([])
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([...uploadedFiles])
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const handleUploadButtonClick = () => {
|
||||
if (fileInputRef.current) {
|
||||
@ -378,12 +378,6 @@ export const CreatePage = () => {
|
||||
})
|
||||
}, [metadata, users])
|
||||
|
||||
useEffect(() => {
|
||||
if (uploadedFiles) {
|
||||
setSelectedFiles([...uploadedFiles])
|
||||
}
|
||||
}, [uploadedFiles])
|
||||
|
||||
useEffect(() => {
|
||||
if (usersPubkey) {
|
||||
setUsers((prev) => {
|
||||
@ -561,11 +555,16 @@ export const CreatePage = () => {
|
||||
const files = Array.from(event.target.files)
|
||||
|
||||
// Remove duplicates based on the file.name
|
||||
setSelectedFiles((p) =>
|
||||
[...p, ...files].filter(
|
||||
setSelectedFiles((p) => {
|
||||
const unique = [...p, ...files].filter(
|
||||
(file, i, array) => i === array.findIndex((t) => t.name === file.name)
|
||||
)
|
||||
)
|
||||
navigate('.', {
|
||||
state: { uploadedFiles: unique },
|
||||
replace: true
|
||||
})
|
||||
return unique
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -579,9 +578,14 @@ export const CreatePage = () => {
|
||||
) => {
|
||||
event.stopPropagation()
|
||||
|
||||
setSelectedFiles((prevFiles) =>
|
||||
prevFiles.filter((file) => file.name !== fileToRemove.name)
|
||||
)
|
||||
setSelectedFiles((prevFiles) => {
|
||||
const files = prevFiles.filter((file) => file.name !== fileToRemove.name)
|
||||
navigate('.', {
|
||||
state: { uploadedFiles: files },
|
||||
replace: true
|
||||
})
|
||||
return files
|
||||
})
|
||||
}
|
||||
|
||||
// Validate inputs before proceeding
|
||||
@ -1038,7 +1042,6 @@ export const CreatePage = () => {
|
||||
try {
|
||||
return JSON.parse(event.content)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user