From 5d5325d51d277270d8ca827c9f354cb7e9cbc283 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Sun, 3 Dec 2023 16:28:36 +0530 Subject: [PATCH] add curve fit image api --- src/components/CurveFit.js | 43 +++++++++++++++++++++++++++- src/components/ImageDownloader.js | 47 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/components/ImageDownloader.js diff --git a/src/components/CurveFit.js b/src/components/CurveFit.js index 6f76004..0395374 100644 --- a/src/components/CurveFit.js +++ b/src/components/CurveFit.js @@ -1,14 +1,55 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { FaInfoCircle } from "react-icons/fa"; +import axios from 'axios'; import './CurveFit.css'; +import ImageDownloader from './ImageDownloader'; function CurveFit({ show }) { const [showCardInfo, setShowCardInfo] = useState(false); + const [svgData, setSvgData] = useState(null); + + const fetchSvg = () => { + axios({ + method: 'get', + url: "https://asia-south1-hpos-qa.cloudfunctions.net/curvefit", + data: { + "_id": "id", + "underMedication": false, + "underTransfusion": false, + "userImageURL": "https://hpos-prod.web.app/logo.png" + }, + withCredentials: false, + secure: false, + headers: { + "Content-Type": "application/json", + // "x-client": "e16a1bd15af2ee640f5a7a18c8d8333f5f01f7c66e003bbc21ee52870f1bce27", + }, + }) + .then(response => response.data) + .then((data) => { + // setMessage(`${id} is being created`); + // setSvgData(data?.plot?.replace('\"', '').replace('\n', '').replace('"', "'")); + }) + .catch((err) => { + console.log(err); + // setMessage(`error: ${err?.message}`); + }); + } + + useEffect(() => { + if (!svgData) { + // fetchSvg(); + } + }, []); return (

Curve Fit

+ {/* ; */} + + + {/* */}
); } diff --git a/src/components/ImageDownloader.js b/src/components/ImageDownloader.js new file mode 100644 index 0000000..cfbac45 --- /dev/null +++ b/src/components/ImageDownloader.js @@ -0,0 +1,47 @@ +import React, { useState } from 'react'; + +const ImageDownloader = () => { + const [imageUrl, setImageUrl] = useState(''); + const [imageData, setImageData] = useState(null); + + const handleInputChange = (e) => { + setImageUrl(e.target.value); + }; + + const handleFetchImage = async () => { + try { + const response = await fetch(imageUrl, { mode: 'no-cors'}); + const blob = await response.blob(); + console.log(blob); + setImageData(URL.createObjectURL(blob)); + } catch (error) { + console.error('Error fetching image:', error); + } + }; + + const handleDownloadImage = () => { + const link = document.createElement('a'); + link.href = imageData; + link.download = 'downloaded_image'; + link.click(); + }; + + return ( +
+ + + + {imageData && ( +
+ Downloadable + +
+ )} +
+ ); +}; + +export default ImageDownloader;