Extract project header, share link, exports, and auth status
- ProjectHeader component replaces the headerButtons JSX in context; it owns the export menu and share panel state. - useShareLink (share status/enable/revoke/copy) and useSharedView (?share= read-only view, now used directly by the router). - utils/projectExport: HTML/Markdown/DOCX download and print-to-PDF. - AuthStatus component replaces the authStatus JSX in context. - Pages import wordStudy helpers directly instead of via context. - Remove dead copyPronunciationGuide (PronunciationPage has its own). - Tests: Markdown export, enabling a share link, the ?share= view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
365fb1b567
commit
4b14b3fbe6
14 files changed
+425
-393
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// File exports of a study project: HTML, Markdown, DOCX, and print-to-PDF.
|
||||
import { buildExportHtml } from './bibleUtils.jsx';
|
||||
import { buildMarkdownExport } from './exportBuilders.js';
|
||||
import { buildChapterSummary } from './projectStorage.js';
|
||||
|
||||
function downloadBlob(blob, filename) {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
const fileBase = (project) => `${project.title.replace(/\s+/g, '-')}-study`;
|
||||
|
||||
export function exportProjectHtml(project) {
|
||||
const html = buildExportHtml(project);
|
||||
downloadBlob(new Blob([html], { type: 'text/html;charset=utf-8' }), `${fileBase(project)}.html`);
|
||||
}
|
||||
|
||||
export function exportProjectMarkdown(project) {
|
||||
const markdown = buildMarkdownExport(project);
|
||||
downloadBlob(new Blob([markdown], { type: 'text/markdown;charset=utf-8' }), `${fileBase(project)}.md`);
|
||||
}
|
||||
|
||||
export async function exportProjectDocx(project) {
|
||||
// docx is large, so it's only downloaded when someone actually exports.
|
||||
const { buildStudyDocxBlob } = await import('./docxExport.js');
|
||||
const blob = await buildStudyDocxBlob(project, buildChapterSummary(project));
|
||||
downloadBlob(blob, `${fileBase(project)}.docx`);
|
||||
}
|
||||
|
||||
export function printProjectPdf(project) {
|
||||
const html = buildExportHtml(project);
|
||||
const printWindow = window.open('', '_blank');
|
||||
if (!printWindow) {
|
||||
alert('Please allow pop-ups for this site to print or save as PDF.');
|
||||
return;
|
||||
}
|
||||
printWindow.document.write(html);
|
||||
printWindow.document.close();
|
||||
printWindow.onload = () => {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user