-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathSheetModuleHeader.tsx
More file actions
186 lines (171 loc) · 5.39 KB
/
Copy pathSheetModuleHeader.tsx
File metadata and controls
186 lines (171 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
"use client";
import { useState, useMemo } from "react";
import Link from "next/link";
import { ArrowLeft, ArrowRight, Download, Share2, Check } from "lucide-react";
import { Badge } from "@/components/ui/badge";
interface ModuleInfo {
id: string;
name: string;
}
interface SheetModuleHeaderProps {
moduleName: string;
docContent: string;
currentModuleId?: string;
modules?: ModuleInfo[];
}
export function SheetModuleHeader({
moduleName,
docContent,
currentModuleId,
modules = [],
}: SheetModuleHeaderProps) {
const [copied, setCopied] = useState(false);
// Compute next module
const nextModule = useMemo(() => {
if (!currentModuleId || modules.length === 0) return null;
const sortedModules = [...modules].sort((a, b) => {
const aNum = parseInt(a.id.replace("module-", "")) || 0;
const bNum = parseInt(b.id.replace("module-", "")) || 0;
return aNum - bNum;
});
const currentIndex = sortedModules.findIndex(
(m) => m.id === currentModuleId
);
if (currentIndex === -1 || currentIndex >= sortedModules.length - 1) {
return null;
}
return sortedModules[currentIndex + 1];
}, [currentModuleId, modules]);
const handleShare = async () => {
try {
await navigator.clipboard.writeText(window.location.href);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy:", err);
}
};
const handleDownloadPDF = () => {
const printWindow = window.open("", "_blank");
if (!printWindow) return;
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<title>${moduleName} - Open Source Sheet</title>
<style>
body {
font-family: 'Courier New', monospace;
padding: 40px;
background: white;
color: black;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
}
h1 {
font-size: 28px;
margin-bottom: 20px;
border-bottom: 2px solid #363636;
padding-bottom: 10px;
}
h2 { font-size: 24px; margin-top: 30px; margin-bottom: 15px; }
h3 { font-size: 20px; margin-top: 25px; margin-bottom: 10px; }
p { margin-bottom: 15px; }
a { color: #9455f4; text-decoration: underline; }
ul, ol { padding-left: 20px; margin-bottom: 15px; }
li { margin-bottom: 5px; }
code {
background-color: #f5f5f5;
padding: 2px 5px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
pre {
background-color: #f5f5f5;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
margin: 20px 0;
}
blockquote {
border-left: 4px solid #9455f4;
padding-left: 15px;
color: #555;
font-style: italic;
margin: 20px 0;
}
img { max-width: 100%; height: auto; margin: 20px 0; }
.footer {
margin-top: 50px;
padding-top: 20px;
border-top: 1px solid #ddd;
font-size: 12px;
text-align: center;
color: #666;
}
</style>
</head>
<body>
<h1>${moduleName}</h1>
<div class="content">
${docContent}
</div>
<div class="footer">
<p>Generated from Open Source Sheet • opensox.ai</p>
</div>
</body>
</html>
`;
printWindow.document.write(htmlContent);
printWindow.document.close();
printWindow.focus();
setTimeout(() => {
printWindow.print();
}, 250);
};
return (
<div className="flex items-center justify-between mb-8">
<div className="flex items-center gap-4">
<Link
href="/dashboard/sheet"
className="inline-flex items-center gap-2 text-brand-purple-light hover:text-brand-purple transition-colors text-sm font-medium"
>
<ArrowLeft className="w-4 h-4" />
Back to Sheet
</Link>
{nextModule && (
<Link
href={`/sheet/${nextModule.id}`}
className="inline-flex items-center gap-2 text-brand-purple-light hover:text-brand-purple transition-colors text-sm font-medium"
>
Next: {nextModule.name}
<ArrowRight className="w-4 h-4" />
</Link>
)}
</div>
<div className="flex items-center gap-2">
{copied && (
<Badge className="bg-brand-purple text-text-primary border-0 flex items-center gap-1">
<Check className="h-3 w-3" />
Copied
</Badge>
)}
<button
onClick={handleDownloadPDF}
className="p-2 text-text-secondary hover:text-text-primary hover:bg-white/10 rounded-md transition-colors"
title="Download PDF"
>
<Download className="w-5 h-5" />
</button>
<button
onClick={handleShare}
className="p-2 text-text-secondary hover:text-text-primary hover:bg-white/10 rounded-md transition-colors"
title="Share"
>
<Share2 className="w-5 h-5" />
</button>
</div>
</div>
);
}