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

🐛 Fix import of large fonts #357

Merged
merged 1 commit into from
Apr 25, 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
9 changes: 4 additions & 5 deletions src/components/pdf/MyDocument.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Document, Page, Text, StyleSheet, Font } from "@react-pdf/renderer";
import { Document, Font, Page, StyleSheet, Text } from "@react-pdf/renderer";

Font.register({
family: "Roboto,SourceHanSansCN",
Expand Down Expand Up @@ -27,11 +27,10 @@ const styles = StyleSheet.create({
},
});

interface MyDocumentProps {
// NOTE: This should only ever be imported dynamically to reduce load times
const MyDocument: React.FC<{
content: string;
}

const MyDocument: React.FC<MyDocumentProps> = ({ content }) => (
}> = ({ content }) => (
<Document>
<Page size="A4" style={styles.page}>
<Text style={styles.section}>{content}</Text>
Expand Down
11 changes: 7 additions & 4 deletions src/components/pdf/PDFButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import WindowButton from "../WindowButton";
import { FaFilePdf } from "react-icons/fa";
import { pdf } from "@react-pdf/renderer";
import React, { memo } from "react";
import MyDocument from "./MyDocument";
import type { Message } from "../../types/agentTypes";

import { useTranslation } from "react-i18next";
Expand All @@ -17,6 +16,10 @@ const PDFButton = ({
const content = getContent(messages);

const downloadPDF = async () => {
const MyDocument = (await import("./MyDocument")).default as React.FC<{
content: string;
}>;

const blob = await pdf(<MyDocument content={content} />).toBlob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
Expand All @@ -41,15 +44,15 @@ const PDFButton = ({
};

const getContent = (messages: Message[]): string => {
const [ t ] = useTranslation();
const [t] = useTranslation();
// Note "Thinking" messages have no `value` so they show up as new lines
return messages
.map((message) => {
if (message.type == "goal") {
return `${t('Goal: ')}${message.value}`;
return `${t("Goal: ")}${message.value}`;
}
if (message.type == "task") {
return `${t('Adding Task: ')}${message.value}`;
return `${t("Adding Task: ")}${message.value}`;
}
return message.value;
})
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"noUncheckedIndexedAccess": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs", "**/*.js"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "venv"]
}