Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed connection with holder issue #87

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"astro": "^2.9.0",
"axios": "^1.4.0",
"crypto-js": "^4.1.1",
"dom-to-image": "^2.6.0",
"downloadjs": "^1.4.7",
"flowbite": "^1.7.0",
"flowbite-react": "^0.4.10",
Expand All @@ -66,6 +67,7 @@
},
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/dom-to-image": "^2.6.4",
"@types/downloadjs": "^1.4.3",
"@types/eslint": "^8.21.1",
"@types/secure-random-password": "^0.2.1",
Expand Down
40 changes: 21 additions & 19 deletions src/commonComponents/QRcode.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { useRef, useState } from "react";
import QRCode from "react-qr-code";
import html2canvas from "html2canvas";
import download from "downloadjs";
import domtoimage from 'dom-to-image';

const CustomQRCode = ({ value, size }: { value: string, size: number }) => {

const inputRef = useRef<HTMLInputElement>(null);
const [isCopied, setIsCopied] = useState(false);

function copyTextVal(e: React.MouseEvent<HTMLButtonElement>) {

e.preventDefault()
const copyText = inputRef?.current;

setIsCopied(true);

Expand All @@ -24,21 +23,21 @@ const CustomQRCode = ({ value, size }: { value: string, size: number }) => {

}

const drawHtmlToCanvas = () => {
domtoimage.toJpeg(inputRef.current, { quality: 0.95 })
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'my-image-name.jpeg';
link.href = dataUrl;
link.click();
});
};

const contentRef = useRef<HTMLDivElement>(null);

const handleDownload = async () => {
if (contentRef.current) {
const canvas = await html2canvas(contentRef.current);
const dataURL = canvas.toDataURL();
download(dataURL, "downloaded_image.png", "image/png");
}
};

return (<div className="h-auto max-w-64 w-full flex flex-col items-center">
<div
ref={contentRef}
className="bg-white p-4 border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 overflow-hidden">
<div
ref={inputRef}
className="bg-white p-4 border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 overflow-hidden">

<QRCode
size={size}
Expand All @@ -62,14 +61,17 @@ const CustomQRCode = ({ value, size }: { value: string, size: number }) => {

</div>
<button
onClick={handleDownload}
className="text-sm content-center px-5 py-2.5 mt-6 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"
onClick={drawHtmlToCanvas}
className="text-sm content-center px-5 py-2.5 mt-6 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"
>
Download
</button>

</div>)

};
}


export default CustomQRCode;


3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"strictNullChecks": true,
"jsx": "react-jsx",
"jsxImportSource": "react"
"jsxImportSource": "react",
"esModuleInterop": true
}
}