How to integrate download image logic for mobile devices

7 Views Asked by At

Currently, logic works fine for laptops / desktops – image gets downloaded when handleDownload gets executed when clicked. However, image isn't being download when I try w/ mobile devices. Is there a way to fix the function below?

  const handleDownload = async () => {
const imageEl = ref.current?.querySelector('#share-graphic-preview')
if (ref.current === null || !imageEl) {
  return
}
// code for downloading image, if necessary
const canvas = await html2canvas(imageEl as HTMLElement, {
  scale: 10,
})

const data = canvas.toDataURL()

const link = document.createElement('a')

if (typeof link.download === 'string') {
  const date = new Date()
  link.href = data
  link.download = `${marketName}-${date.toLocaleDateString()}.png`

  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
  commonActions.handleConfettiOpen()
} else {
  window.open(data)
}

}

0

There are 0 best solutions below