Skip to content

Commit

Permalink
🎉 add download button to reupload modal
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Feb 14, 2025
1 parent 80c5055 commit 4647c12
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions adminSiteClient/ReuploadImageForDataInsightModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { faCheck, faSpinner } from "@fortawesome/free-solid-svg-icons"
import {
faCheck,
faDownload,
faSpinner,
} from "@fortawesome/free-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { Modal, Space } from "antd"
import { Button, Flex, Modal, Space } from "antd"
import { useContext, useState } from "react"
import {
ImageUploadResponse,
makeImageSrc,
uploadImageFromSourceUrl,
} from "./imagesHelpers"
import { AdminAppContext } from "./AdminAppContext"
import { downloadImage } from "@ourworldindata/utils"

const spinnerIcon = <FontAwesomeIcon icon={faSpinner} size="sm" spin />
const checkIcon = <FontAwesomeIcon icon={faCheck} size="sm" />
const downloadIcon = <FontAwesomeIcon icon={faDownload} size="sm" />

export function ReuploadImageForDataInsightModal({
dataInsight,
Expand Down Expand Up @@ -51,7 +57,7 @@ export function ReuploadImageForDataInsightModal({
}) {
const { admin } = useContext(AdminAppContext)

const currentImageUrl = makeImageSrc(
const existingImageUrl = makeImageSrc(
existingImage.cloudflareId,
existingImage.originalWidth
)
Expand Down Expand Up @@ -112,11 +118,28 @@ export function ReuploadImageForDataInsightModal({
</p>

<ImagePreview
imageBefore={currentImageUrl}
imageBefore={existingImageUrl}
imageAfter={sourceUrl}
isLoading={isLoadingSourceUrl}
loadingError={loadingSourceUrlError}
/>
{sourceUrl && (
<Flex justify="end">
<Button
color="default"
variant="filled"
icon={downloadIcon}
onClick={() => {
void downloadImage(
sourceUrl,
existingImage.filename
)
}}
>
Download
</Button>
</Flex>
)}
</div>
</Modal>
)
Expand Down

0 comments on commit 4647c12

Please sign in to comment.