diff --git a/.changeset/two-cougars-allow.md b/.changeset/two-cougars-allow.md new file mode 100644 index 0000000..9ca2523 --- /dev/null +++ b/.changeset/two-cougars-allow.md @@ -0,0 +1,5 @@ +--- +"penpot-exporter": minor +--- + +Add loader when generating really large files after the page processing loader diff --git a/plugin-src/transformers/transformDocumentNode.ts b/plugin-src/transformers/transformDocumentNode.ts index 251f1c7..b860088 100644 --- a/plugin-src/transformers/transformDocumentNode.ts +++ b/plugin-src/transformers/transformDocumentNode.ts @@ -1,5 +1,6 @@ import { componentsLibrary } from '@plugin/ComponentLibrary'; import { imagesLibrary } from '@plugin/ImageLibrary'; +import { sleep } from '@plugin/utils'; import { PenpotDocument } from '@ui/types'; @@ -7,7 +8,7 @@ import { transformPageNode } from '.'; export const transformDocumentNode = async (node: DocumentNode): Promise => { const children = []; - let currentPage = 0; + let currentPage = 1; figma.ui.postMessage({ type: 'PROGRESS_TOTAL_PAGES', @@ -15,14 +16,16 @@ export const transformDocumentNode = async (node: DocumentNode): Promise { +type ExporterProgressProps = { + downloading: boolean; +}; + +export const ExporterProgress = ({ downloading }: ExporterProgressProps) => { const [currentNode, setCurrentNode] = useState(); const [totalPages, setTotalPages] = useState(); const [processedPages, setProcessedPages] = useState(); @@ -13,6 +17,7 @@ export const ExporterProgress = () => { setCurrentNode(event.data.pluginMessage.data as string); } else if (event.data.pluginMessage?.type === 'PROGRESS_TOTAL_PAGES') { setTotalPages(event.data.pluginMessage.data as number); + setProcessedPages(0); } else if (event.data.pluginMessage?.type === 'PROGRESS_PROCESSED_PAGES') { setProcessedPages(event.data.pluginMessage.data as number); } @@ -38,15 +43,25 @@ export const ExporterProgress = () => { - {processedPages} of {totalPages} pages exported 💪 - {currentNode ? ( + {!downloading ? ( <> -
- Currently exporting layer -
- {'“' + truncateText(currentNode, 40) + '”'} + {processedPages} of {totalPages} pages exported 💪 + {currentNode ? ( + <> +
+ Currently exporting layer +
+ {'“' + truncateText(currentNode, 35) + '”'} + + ) : undefined} - ) : undefined} + ) : ( + <> + Generating Penpot file 🚀 +
+ Please wait, this process might take a while... + + )}
); diff --git a/ui-src/components/PenpotExporter.tsx b/ui-src/components/PenpotExporter.tsx index 2ac40d6..4061d34 100644 --- a/ui-src/components/PenpotExporter.tsx +++ b/ui-src/components/PenpotExporter.tsx @@ -16,18 +16,19 @@ export const PenpotExporter = () => { const [needsReload, setNeedsReload] = useState(false); const [loading, setLoading] = useState(true); const [exporting, setExporting] = useState(false); + const [downloading, setDownloading] = useState(false); const methods = useForm(); methods.getValues(); const onMessage = (event: MessageEvent<{ pluginMessage: { type: string; data: unknown } }>) => { if (event.data.pluginMessage?.type == 'PENPOT_DOCUMENT') { + setDownloading(true); + const document = event.data.pluginMessage.data as PenpotDocument; const file = parse(document); file.export(); - - setExporting(false); } else if (event.data.pluginMessage?.type == 'CUSTOM_FONTS') { setMissingFonts(event.data.pluginMessage.data as string[]); setLoading(false); @@ -72,7 +73,7 @@ export const PenpotExporter = () => { if (loading) return ; - if (exporting) return ; + if (exporting) return ; if (needsReload) { return (