2024-05-31 04:25:32 -05:00
|
|
|
import { LoadingIndicator } from '@create-figma-plugin/ui';
|
2024-06-06 10:24:59 -05:00
|
|
|
import { JSX } from 'react';
|
2024-05-31 04:25:32 -05:00
|
|
|
|
2024-06-06 10:24:59 -05:00
|
|
|
import { Steps, useFigmaContext } from '@ui/context';
|
2024-05-31 04:25:32 -05:00
|
|
|
|
2024-06-04 08:33:55 -05:00
|
|
|
import { Stack } from './Stack';
|
2024-05-31 04:25:32 -05:00
|
|
|
|
2024-06-06 10:24:59 -05:00
|
|
|
type Messages = {
|
|
|
|
total: string;
|
|
|
|
current?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const stepMessages: Record<Steps, Messages> = {
|
|
|
|
processing: {
|
|
|
|
total: 'pages processed 💪',
|
|
|
|
current: 'Currently processing layer'
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
total: 'remote components processed 📦',
|
|
|
|
current: 'Currently processing layer'
|
|
|
|
},
|
|
|
|
images: {
|
|
|
|
total: 'images downloaded 📸'
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
total: 'images optimized 📸'
|
|
|
|
},
|
|
|
|
downloading: {
|
|
|
|
total: 'Generating Penpot file 🚀',
|
|
|
|
current: 'Please wait, this process might take a while...'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const StepProgress = (): JSX.Element | null => {
|
|
|
|
const { currentItem, totalItems, processedItems, step } = useFigmaContext();
|
2024-05-31 04:25:32 -05:00
|
|
|
|
|
|
|
const truncateText = (text: string, maxChars: number) => {
|
|
|
|
if (text.length <= maxChars) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text.slice(0, maxChars) + '...';
|
|
|
|
};
|
|
|
|
|
2024-06-06 10:24:59 -05:00
|
|
|
if (!step) return null;
|
|
|
|
|
|
|
|
const currentText = stepMessages[step].current;
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 'processing':
|
|
|
|
case 'remote':
|
|
|
|
case 'images':
|
|
|
|
case 'optimization':
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{processedItems} of {totalItems} {stepMessages[step].total}
|
|
|
|
{currentItem && currentText ? (
|
|
|
|
<>
|
|
|
|
<br />
|
|
|
|
{currentText}
|
|
|
|
<br />
|
|
|
|
{'“' + truncateText(currentItem, 35) + '”'}
|
|
|
|
</>
|
|
|
|
) : undefined}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
case 'downloading':
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{stepMessages[step].total}
|
|
|
|
<br />
|
|
|
|
{currentText}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ExporterProgress = () => {
|
2024-05-31 04:25:32 -05:00
|
|
|
return (
|
|
|
|
<Stack space="small" horizontalAlign="center">
|
|
|
|
<LoadingIndicator />
|
|
|
|
<span style={{ textAlign: 'center' }}>
|
2024-06-06 10:24:59 -05:00
|
|
|
<StepProgress />
|
2024-05-31 04:25:32 -05:00
|
|
|
</span>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|