mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 17:33:59 +01:00
refactor: remove unused code (jspdf
, downloadPDF
) and add code comments (#274)
This commit is contained in:
parent
4cfbdac7d6
commit
6a56dd0231
|
@ -1,8 +1,7 @@
|
||||||
import html2canvas from 'html2canvas';
|
import html2canvas from 'html2canvas';
|
||||||
// import jsPDF from 'jspdf';
|
|
||||||
import { ChatInterface } from '@type/chat';
|
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) => {
|
export const htmlToImg = async (html: HTMLDivElement) => {
|
||||||
const needResize = window.innerWidth >= 1024;
|
const needResize = window.innerWidth >= 1024;
|
||||||
const initialWidth = html.style.width;
|
const initialWidth = html.style.width;
|
||||||
|
@ -15,6 +14,7 @@ export const htmlToImg = async (html: HTMLDivElement) => {
|
||||||
return dataURL;
|
return dataURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function to download the image as a file
|
||||||
export const downloadImg = (imgData: string, fileName: string) => {
|
export const downloadImg = (imgData: string, fileName: string) => {
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = imgData;
|
link.href = imgData;
|
||||||
|
@ -23,42 +23,7 @@ export const downloadImg = (imgData: string, fileName: string) => {
|
||||||
link.remove();
|
link.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const downloadPDF = (
|
// Function to convert a chat object to markdown format
|
||||||
// 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);
|
|
||||||
// };
|
|
||||||
|
|
||||||
export const chatToMarkdown = (chat: ChatInterface) => {
|
export const chatToMarkdown = (chat: ChatInterface) => {
|
||||||
let markdown = `# ${chat.title}\n\n`;
|
let markdown = `# ${chat.title}\n\n`;
|
||||||
chat.messages.forEach((message) => {
|
chat.messages.forEach((message) => {
|
||||||
|
@ -67,6 +32,7 @@ export const chatToMarkdown = (chat: ChatInterface) => {
|
||||||
return markdown;
|
return markdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function to download the markdown content as a file
|
||||||
export const downloadMarkdown = (markdown: string, fileName: string) => {
|
export const downloadMarkdown = (markdown: string, fileName: string) => {
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
const markdownFile = new Blob([markdown], { type: 'text/markdown' });
|
const markdownFile = new Blob([markdown], { type: 'text/markdown' });
|
||||||
|
|
Loading…
Reference in a new issue