Skip to content

Commit

Permalink
v0.3.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubaton committed Nov 13, 2023
1 parent dffce4b commit 2e6cc16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/components/BusinessCard/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ const BusinessCard = ({ name, title, company, email, phone, logo }) => {
<div className="flex flex-row items-center">
<div className="text-zinc-900 space-y-1">
<h1 className="text-lg font-bold">{company}</h1>
<p className="flex flex-row items-center gap-2 text-sm">
<BsPerson />
{name}
</p>
<p className="flex flex-row items-center gap-2 text-sm">
<BsStar />
{title}
</p>
<p className="flex flex-row items-center gap-2 text-sm">
<BsPerson />
{name}
</p>
<p className="flex flex-row items-center gap-2 text-sm">
<BsTelephone />
{phone}
Expand Down
30 changes: 19 additions & 11 deletions src/constants/ShareSVG/page.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Image from "next/image";
import React, { useRef } from "react";
import * as htmlToImage from "html-to-image";
import Share from "../../../public/assets/icons/ShareSVG.png";
import ShareIcon from "../../../public/assets/icons/ShareSVG.png";
import { toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";

Expand Down Expand Up @@ -30,13 +30,19 @@ const ShareSVG = () => {
};

const createCardImage = async () => {
const cardElement = cardRef.current;
if (!cardElement) {
return null;
}

try {
const cardBlob = await htmlToImage.toBlob(cardElement);
// This is for basic image for testing only
const canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext("2d");
context.fillStyle = "purple";
context.fillRect(0, 0, canvas.width, canvas.height);

// Convert the canvas to blob
const cardBlob = await new Promise((resolve) => {
canvas.toBlob(resolve, "image/png");
});

if (cardBlob) {
return new File([cardBlob], "business_card.png", { type: "image/png" });
Expand All @@ -45,17 +51,19 @@ const ShareSVG = () => {
return null;
}
} catch (error) {
console.error("Error creating the card image: " + error.message);
toast.error("Failed to create the business card image.");
console.error("Error creating the card image:", error);
toast.error(
"Failed to create the business card image. Check the console for details."
);
return null;
}
};

return (
<div>
<button onClick={shareBusinessCard} disabled>
<button onClick={shareBusinessCard}>
<Image
src={Share}
src={ShareIcon}
alt="Share-Icon"
priority={true}
width={52}
Expand Down

0 comments on commit 2e6cc16

Please sign in to comment.