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

feat: adds capability to export user qr-code into wallpaper #10115

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akash19coder
Copy link
Contributor

@akash19coder akash19coder commented Jan 9, 2024

Fixes Issue

Closes #9115

Changes proposed

  • Created a component called QRcodeWallpaper.js. We are using inline-style in the component instead of Tailwind CSS because the tailwind style to place the QR code and Biodrop logo at appropriate position(please refer screenshot attached in the screenshot section) was not reflecting in the corresponding image.
function QRcodeWallpaper({ BASE_URL, data }) {
  const fallbackImageSize = 120;

  return (
    <div style={{ marginTop: "50%", marginLeft: "16%" }}>
      <QRCodeSVG
        className="border border-white"
        value={`${BASE_URL}/${data.username}`}
        size={fallbackImageSize * 6}
      />
      <div style={{ marginLeft: "7rem", marginTop: "5rem" }}>
        <LogoWide width={512} />
      </div>
    </div>
  );
}
  • The newly created component will be transformed into HTML String with the following function. The renderToString() function used below is coming from import { renderToString } from "react-dom/server";
const renderQRCodeWallpaperToString = (BASE_URL, data) => {
  const qrCodeElement = React.createElement(QRcodeWallpaper, {
    BASE_URL: BASE_URL,
    data: data,
  });

  const qrCodeString = renderToString(qrCodeElement);

  return qrCodeString;
};
  • The HTML String is then converted into image using a library called html-to-image library on a button click that is added into UserProfile.js. On button click following function is executed
const downloadWallpaper = async () => {
    try {
      const qrCodeString = renderQRCodeWallpaperToString(BASE_URL, data);

      const container = document.createElement("div");
      container.innerHTML = qrCodeString;

      const dataUrl = await toPng(container, {
        cacheBust: false,
        backgroundColor: "#122640",
        width: 1080,
        height: 1920,
      });

      saveAs(dataUrl, `Biodrop-Wallpaper-${data.username}.png`);
    } catch (e) {
      console.error(e);
    }
  };

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

Screenshots

Note to reviewers

  • The pull request feat: exports qr-code as wallpaper for lock-screen #9535 serves the same purpose but different implementation. Please click the PR to compare implementations.
  • Upon usage of logger in the place of console in downloadWallpaper function I been getting ADMIN_USER_NOT_FOUND error hence I have place console for the time being.
  • The Link to the library Click Here

@github-actions github-actions bot added dependencies Pull requests that update a dependency file issue linked Pull Request has issue linked labels Jan 9, 2024
@akash19coder
Copy link
Contributor Author

@eddiejaoude a gentle reminder for review. please take a glance when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file issue linked Pull Request has issue linked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] QR Code as Mobile Wallpaper
1 participant