Skip to content

Commit f2fd87f

Browse files
feat: prettier
1 parent f5c7665 commit f2fd87f

File tree

1 file changed

+93
-54
lines changed

1 file changed

+93
-54
lines changed

packages/ui/lib/pdf-utils.tsx

Lines changed: 93 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
// @ts-ignore - Type conflicts with React 19 RC
3-
import {
4-
Document,
5-
Page,
6-
Text,
7-
View,
8-
StyleSheet,
9-
pdf
3+
import {
4+
Document,
5+
Page,
6+
Text,
7+
View,
8+
StyleSheet,
9+
pdf,
1010
} from '@react-pdf/renderer';
1111
import { Message } from '@openassistantgpt/react';
1212
import { ChatbotConfig } from '../src/chatbot';
@@ -119,75 +119,112 @@ function cleanMessageContent(content: string): string {
119119
// Function to generate and download PDF
120120
export async function generatePDFTranscript(
121121
messages: Message[],
122-
chatbot: ChatbotConfig
122+
chatbot: ChatbotConfig,
123123
): Promise<void> {
124124
try {
125125
// @ts-ignore - Working around React 19 RC type conflicts
126-
const PDFDocument = React.createElement(Document as any, {},
126+
const PDFDocument = React.createElement(
127+
Document as any,
128+
{},
127129
// @ts-ignore
128-
React.createElement(Page as any, { size: 'A4', style: styles.page },
130+
React.createElement(
131+
Page as any,
132+
{ size: 'A4', style: styles.page },
129133
// Header
130134
// @ts-ignore
131-
React.createElement(Text as any, { style: styles.header }, 'Chat Transcript'),
135+
React.createElement(
136+
Text as any,
137+
{ style: styles.header },
138+
'Chat Transcript',
139+
),
132140
// @ts-ignore
133-
React.createElement(Text as any, { style: styles.subtitle },
134-
`Generated: ${new Date().toLocaleString()}`
141+
React.createElement(
142+
Text as any,
143+
{ style: styles.subtitle },
144+
`Generated: ${new Date().toLocaleString()}`,
135145
),
136146
// @ts-ignore
137147
React.createElement(View as any, { style: styles.divider }),
138-
148+
139149
// Welcome Message - styled like assistant bubble
140-
...(chatbot.welcomeMessage ? [
141-
// @ts-ignore
142-
React.createElement(View as any, {
143-
style: [styles.messageRow, styles.assistantRow],
144-
key: 'welcome'
145-
},
146-
// @ts-ignore
147-
React.createElement(View as any, { style: styles.assistantBubble },
150+
...(chatbot.welcomeMessage
151+
? [
148152
// @ts-ignore
149-
React.createElement(Text as any, { style: styles.assistantLabel }, 'Assistant:'),
150-
// @ts-ignore
151-
React.createElement(Text as any, { style: styles.assistantText },
152-
cleanMessageContent(chatbot.welcomeMessage)
153-
)
154-
)
155-
)
156-
] : []),
157-
153+
React.createElement(
154+
View as any,
155+
{
156+
style: [styles.messageRow, styles.assistantRow],
157+
key: 'welcome',
158+
},
159+
// @ts-ignore
160+
React.createElement(
161+
View as any,
162+
{ style: styles.assistantBubble },
163+
// @ts-ignore
164+
React.createElement(
165+
Text as any,
166+
{ style: styles.assistantLabel },
167+
'Assistant:',
168+
),
169+
// @ts-ignore
170+
React.createElement(
171+
Text as any,
172+
{ style: styles.assistantText },
173+
cleanMessageContent(chatbot.welcomeMessage),
174+
),
175+
),
176+
),
177+
]
178+
: []),
179+
158180
// Messages with bubble layout
159181
...messages.map((message, index) => {
160182
const isUser = message.role === 'user';
161183
// @ts-ignore
162-
return React.createElement(View as any, {
163-
style: [styles.messageRow, isUser ? styles.userRow : styles.assistantRow],
164-
key: index.toString()
165-
},
166-
// @ts-ignore
167-
React.createElement(View as any, {
168-
style: isUser ? styles.userBubble : styles.assistantBubble
184+
return React.createElement(
185+
View as any,
186+
{
187+
style: [
188+
styles.messageRow,
189+
isUser ? styles.userRow : styles.assistantRow,
190+
],
191+
key: index.toString(),
169192
},
193+
// @ts-ignore
194+
React.createElement(
195+
View as any,
196+
{
197+
style: isUser ? styles.userBubble : styles.assistantBubble,
198+
},
170199
// @ts-ignore
171-
React.createElement(Text as any, {
172-
style: isUser ? styles.userLabel : styles.assistantLabel
173-
}, isUser ? 'You:' : 'Assistant:'),
200+
React.createElement(
201+
Text as any,
202+
{
203+
style: isUser ? styles.userLabel : styles.assistantLabel,
204+
},
205+
isUser ? 'You:' : 'Assistant:',
206+
),
174207
// @ts-ignore
175-
React.createElement(Text as any, {
176-
style: isUser ? styles.userText : styles.assistantText
177-
}, cleanMessageContent(message.content))
178-
)
208+
React.createElement(
209+
Text as any,
210+
{
211+
style: isUser ? styles.userText : styles.assistantText,
212+
},
213+
cleanMessageContent(message.content),
214+
),
215+
),
179216
);
180217
}),
181-
218+
182219
// Footer
183220
// @ts-ignore
184221
React.createElement(Text as any, {
185222
style: styles.footer,
186-
render: ({ pageNumber, totalPages }: any) =>
223+
render: ({ pageNumber, totalPages }: any) =>
187224
`Page ${pageNumber} of ${totalPages}`,
188-
fixed: true
189-
})
190-
)
225+
fixed: true,
226+
}),
227+
),
191228
);
192229

193230
// Generate PDF blob
@@ -198,17 +235,19 @@ export async function generatePDFTranscript(
198235
const url = URL.createObjectURL(blob);
199236
const link = document.createElement('a');
200237
link.href = url;
201-
link.download = `chat-transcript-${new Date().toISOString().split('T')[0]}.pdf`;
202-
238+
link.download = `chat-transcript-${
239+
new Date().toISOString().split('T')[0]
240+
}.pdf`;
241+
203242
// Trigger download
204243
document.body.appendChild(link);
205244
link.click();
206-
245+
207246
// Cleanup
208247
document.body.removeChild(link);
209248
URL.revokeObjectURL(url);
210249
} catch (error) {
211250
console.error('Error generating PDF:', error);
212251
throw new Error('Failed to generate PDF transcript');
213252
}
214-
}
253+
}

0 commit comments

Comments
 (0)