From 6a56dd023126c3c117f26fa653e589aa40f2a0a4 Mon Sep 17 00:00:00 2001 From: George Adams Date: Sun, 7 May 2023 11:51:36 -0400 Subject: [PATCH] refactor: remove unused code (`jspdf`, `downloadPDF`) and add code comments (#274) --- src/utils/chat.ts | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 9cc8cdd..8c06726 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -1,8 +1,7 @@ import html2canvas from 'html2canvas'; -// import jsPDF from 'jspdf'; import { ChatInterface } from '@type/chat'; -import { Theme } from '@type/theme'; +// Function to convert HTML to an image using html2canvas export const htmlToImg = async (html: HTMLDivElement) => { const needResize = window.innerWidth >= 1024; const initialWidth = html.style.width; @@ -15,6 +14,7 @@ export const htmlToImg = async (html: HTMLDivElement) => { return dataURL; }; +// Function to download the image as a file export const downloadImg = (imgData: string, fileName: string) => { const link = document.createElement('a'); link.href = imgData; @@ -23,42 +23,7 @@ export const downloadImg = (imgData: string, fileName: string) => { link.remove(); }; -// export const downloadPDF = ( -// imageData: string, -// theme: Theme, -// fileName: string -// ) => { -// const pdf = new jsPDF('p', 'mm'); -// const imageProps = pdf.getImageProperties(imageData); -// const pageHeight = pdf.internal.pageSize.getHeight(); -// const pageWidth = pdf.internal.pageSize.getWidth(); -// const imgHeight = (imageProps.height * pageWidth) / imageProps.width; -// let heightLeft = imgHeight; -// let position = 0; - -// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight); -// heightLeft -= pageHeight; - -// while (heightLeft >= 0) { -// position -= pageHeight; -// heightLeft -= pageHeight; -// pdf.addPage(); -// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight); -// } - -// if (heightLeft < 0) { -// heightLeft = -heightLeft; -// if (theme === 'dark') { -// pdf.setFillColor(52, 53, 65); -// } else { -// pdf.setFillColor(255, 255, 255); -// } -// pdf.rect(0, pageHeight - heightLeft - 3, pageWidth, heightLeft + 3, 'F'); -// } - -// pdf.save(fileName); -// }; - +// Function to convert a chat object to markdown format export const chatToMarkdown = (chat: ChatInterface) => { let markdown = `# ${chat.title}\n\n`; chat.messages.forEach((message) => { @@ -67,6 +32,7 @@ export const chatToMarkdown = (chat: ChatInterface) => { return markdown; }; +// Function to download the markdown content as a file export const downloadMarkdown = (markdown: string, fileName: string) => { const link = document.createElement('a'); const markdownFile = new Blob([markdown], { type: 'text/markdown' });