Skip to content

Commit

Permalink
🔧💡 Refactored height change logic for smoother expansion with trigger…
Browse files Browse the repository at this point in the history
… mechanism
  • Loading branch information
jacksonkasi1 committed Sep 30, 2024
1 parent f9055c7 commit 12fc9b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ const assetsExportTypes = [
{ value: AssetsExportType.MULTI, text: 'Multiple PDF files' },
];

const PdfExportOption = () => {
const { pdfFormatOption, setPdfFormatOption, pdfPassword, setPdfPassword } = useImageExportStore();
const { assetsExportType, setAssetsExportType } = useImageExportStore();
interface PdfExportOptionProps {
onHeightChange: () => void; // Notify parent when height changes
}

const PdfExportOption = ({ onHeightChange }: PdfExportOptionProps) => {
const { pdfFormatOption, setPdfFormatOption, pdfPassword, setPdfPassword, assetsExportType, setAssetsExportType } =
useImageExportStore();

const [vectorGradients, setVectorGradients] = useState<boolean>(false);
const [outlineLinks, setOutlineLinks] = useState<boolean>(false);
Expand Down Expand Up @@ -68,6 +72,8 @@ const PdfExportOption = () => {
if (!newValue) {
setPdfPassword('');
}
// Notify parent when password protection is toggled
onHeightChange();
};

const handleSetPassword = (event: JSX.TargetedEvent<HTMLInputElement>) => {
Expand Down
15 changes: 13 additions & 2 deletions plugin/src/pages/AssetPage/_components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { ExportAssetsHandler } from '@/types/events';
const Footer = () => {
const [isExpanded, setIsExpanded] = useState(false); // State to manage footer expansion
const [contentHeight, setContentHeight] = useState('0px');
const [heightTrigger, setHeightTrigger] = useState(false);

const contentRef = useRef<HTMLDivElement>(null);

const { isLoading, setIsLoading } = useUtilsStore();
Expand All @@ -47,7 +49,7 @@ const Footer = () => {
if (contentRef.current) {
setContentHeight(isExpanded ? `${contentRef.current.scrollHeight}px` : '0px');
}
}, [isExpanded, formatOption]);
}, [isExpanded, formatOption, heightTrigger]);

const caseOptions = Object.values(CaseOption).map((value) => ({
value,
Expand All @@ -59,6 +61,11 @@ const Footer = () => {
text: value,
}));

const handleHeightChange = () => {
// Update true or false to trigger height change
setHeightTrigger((prev) => !prev);
};

function handleCaseChange(event: JSX.TargetedEvent<HTMLInputElement>) {
const caseValue = event.currentTarget.value;

Expand Down Expand Up @@ -143,7 +150,11 @@ const Footer = () => {
</div>
</div>
<VerticalSpace space="small" />
{formatOption === FormatOption.PDF ? <PdfExportOption /> : <ImageExportOption />}
{formatOption === FormatOption.PDF ? (
<PdfExportOption onHeightChange={handleHeightChange} />
) : (
<ImageExportOption />
)}
</Container>
<VerticalSpace space="small" />
</div>
Expand Down

0 comments on commit 12fc9b4

Please sign in to comment.