fix(image Name): switched index of image with Date().getTime()

This commit is contained in:
Laurian-Dufrechou
2023-03-31 16:40:23 +02:00
parent ae33f29c94
commit 2dfe2cac7b
+13 -14
View File
@@ -143,19 +143,15 @@ export default function ModalModifyImages(props) {
<GridItem key={index}> <GridItem key={index}>
<Flex direction={"column"} gap={"1rem"}> <Flex direction={"column"} gap={"1rem"}>
<Image src={image} /> <Image src={image} />
{index === listImage.length - 1 ? ( <Button
<Button id={"" + index}
id={"" + index} colorScheme={"red"}
colorScheme={"red"} onClick={(e) => {
onClick={(e) => { deleteImage(`${listImage[index]}`);
deleteImage(`${listImage[index]}`); }}
}} >
> Supprimer l'image
Supprimer l'image </Button>
</Button>
) : (
<></>
)}
</Flex> </Flex>
</GridItem> </GridItem>
))} ))}
@@ -166,11 +162,14 @@ export default function ModalModifyImages(props) {
height={"100%"} height={"100%"}
accept={"image/png, image/jpeg, image/webp"} accept={"image/png, image/jpeg, image/webp"}
onInput={({ target }) => { onInput={({ target }) => {
const date = new Date();
const time = date.getTime();
const file = target.files[0]; const file = target.files[0];
const extension = file.name.split(".").pop(); const extension = file.name.split(".").pop();
const newFile = new File( const newFile = new File(
[file], [file],
`${user.id}_${listImage.length}.${extension}`, `${user.id}_${time}.${extension}`,
{ {
type: file.type, type: file.type,
} }