|
6 | 6 | MoreHorizontal, |
7 | 7 | FolderInput, |
8 | 8 | Paperclip, |
| 9 | + Printer, |
9 | 10 | } from 'lucide-react'; |
10 | 11 | import { Button } from '@/components/ui/button'; |
11 | 12 | import { |
@@ -176,6 +177,53 @@ export default function Index({ |
176 | 177 | [userId] |
177 | 178 | ); |
178 | 179 |
|
| 180 | + const handlePrint = useCallback(() => { |
| 181 | + if (!note) return; |
| 182 | + |
| 183 | + const printWindow = window.open('', '_blank'); |
| 184 | + if (!printWindow) return; |
| 185 | + |
| 186 | + const printContent = ` |
| 187 | + <!DOCTYPE html> |
| 188 | + <html> |
| 189 | + <head> |
| 190 | + <title>${note.title || 'Untitled Note'}</title> |
| 191 | + <style> |
| 192 | + body { |
| 193 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
| 194 | + line-height: 1.6; |
| 195 | + max-width: 800px; |
| 196 | + margin: 0 auto; |
| 197 | + padding: 20px; |
| 198 | + color: #333; |
| 199 | + } |
| 200 | + h1 { color: #2d3748; margin-bottom: 0.5rem; } |
| 201 | + h2 { color: #4a5568; } |
| 202 | + h3 { color: #718096; } |
| 203 | + pre { background: #f7fafc; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; } |
| 204 | + code { background: #edf2f7; padding: 0.2rem 0.4rem; border-radius: 0.25rem; } |
| 205 | + blockquote { border-left: 4px solid #e2e8f0; margin: 1rem 0; padding-left: 1rem; color: #4a5568; } |
| 206 | + ul, ol { margin: 1rem 0; } |
| 207 | + @media print { |
| 208 | + body { margin: 0; padding: 1cm; } |
| 209 | + .no-print { display: none; } |
| 210 | + } |
| 211 | + </style> |
| 212 | + </head> |
| 213 | + <body> |
| 214 | + <h1>${note.title || 'Untitled Note'}</h1> |
| 215 | + ${note.content} |
| 216 | + </body> |
| 217 | + </html> |
| 218 | + `; |
| 219 | + |
| 220 | + printWindow.document.write(printContent); |
| 221 | + printWindow.document.close(); |
| 222 | + printWindow.focus(); |
| 223 | + printWindow.print(); |
| 224 | + printWindow.close(); |
| 225 | + }, [note]); |
| 226 | + |
179 | 227 |
|
180 | 228 | const formatDate = (date: Date) => { |
181 | 229 | return new Intl.DateTimeFormat('en-US', { |
@@ -262,6 +310,10 @@ export default function Index({ |
262 | 310 | <FolderInput className="mr-2 h-4 w-4" /> |
263 | 311 | Move |
264 | 312 | </DropdownMenuItem> |
| 313 | + <DropdownMenuItem onClick={handlePrint}> |
| 314 | + <Printer className="mr-2 h-4 w-4" /> |
| 315 | + Print |
| 316 | + </DropdownMenuItem> |
265 | 317 | <DropdownMenuItem onClick={() => onArchiveNote(note.id)}> |
266 | 318 | <Archive className="mr-2 h-4 w-4" /> |
267 | 319 | Archive |
|
0 commit comments