Refactor UI components for better reusability
- Created reusable ActionButton component to handle common button behavior - Created reusable Section component for consistent section styling - Refactored App, MatchSizes, and SwapPositions to use new components - Fixed scrolling issues in the main container - Improved code organization and reduced duplication 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0cbb9c948e
commit
d09dec4706
5 files changed
+201
-178
No files matched your search
@@ -1,89 +1,59 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
Button,
|
||||
Text,
|
||||
Tooltip,
|
||||
InfoLabel,
|
||||
Card
|
||||
} from "@fluentui/react-components";
|
||||
import {
|
||||
ArrowFitInRegular,
|
||||
ArrowSortDownRegular,
|
||||
ArrowSortUpRegular
|
||||
} from "@fluentui/react-icons";
|
||||
import { ArrowFitInRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "./App";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
import ActionButton from "./ActionButton";
|
||||
|
||||
export const MatchSizes: React.FC = () => {
|
||||
const styles = useCommonStyles();
|
||||
const {
|
||||
statusMessage, setStatusMessage,
|
||||
statusType, setStatusType,
|
||||
isProcessing, setIsProcessing
|
||||
} = useStatusContext();
|
||||
const { setStatusMessage, setStatusType } = useStatusContext();
|
||||
|
||||
const matchSizeToFirstSelected = async () => {
|
||||
setIsProcessing(true);
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
// Get the selected shapes
|
||||
const shapes = context.presentation.getSelectedShapes();
|
||||
shapes.load("items");
|
||||
await context.sync();
|
||||
await PowerPoint.run(async (context) => {
|
||||
// Get the selected shapes
|
||||
const shapes = context.presentation.getSelectedShapes();
|
||||
shapes.load("items");
|
||||
await context.sync();
|
||||
|
||||
// Check if shapes are selected
|
||||
if (shapes.items.length === 0) {
|
||||
setStatusMessage("No shapes are selected. Please select shapes first.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
// Check if shapes are selected
|
||||
if (shapes.items.length === 0) {
|
||||
setStatusMessage("No shapes are selected. Please select shapes first.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if there is more than one shape selected
|
||||
if (shapes.items.length === 1) {
|
||||
setStatusMessage("Please select multiple shapes to resize.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
// Check if there is more than one shape selected
|
||||
if (shapes.items.length === 1) {
|
||||
setStatusMessage("Please select multiple shapes to resize.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the first shape's dimensions
|
||||
const firstShape = shapes.items[0];
|
||||
firstShape.load("width,height");
|
||||
await context.sync();
|
||||
// Get the first shape's dimensions
|
||||
const firstShape = shapes.items[0];
|
||||
firstShape.load("width,height");
|
||||
await context.sync();
|
||||
|
||||
// Loop through the remaining shapes and resize them
|
||||
for (let i = 1; i < shapes.items.length; i++) {
|
||||
shapes.items[i].width = firstShape.width;
|
||||
shapes.items[i].height = firstShape.height;
|
||||
}
|
||||
// Loop through the remaining shapes and resize them
|
||||
for (let i = 1; i < shapes.items.length; i++) {
|
||||
shapes.items[i].width = firstShape.width;
|
||||
shapes.items[i].height = firstShape.height;
|
||||
}
|
||||
|
||||
await context.sync();
|
||||
setStatusMessage(`Resized ${shapes.items.length - 1} shapes to match the first selected shape.`);
|
||||
setStatusType("success");
|
||||
|
||||
// Timeout is handled in App.tsx now
|
||||
});
|
||||
} catch (error) {
|
||||
setStatusMessage(`Error: ${error.message}`);
|
||||
setStatusType("error");
|
||||
console.error(error);
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
}
|
||||
await context.sync();
|
||||
setStatusMessage(`Resized ${shapes.items.length - 1} shapes to match the first selected shape.`);
|
||||
setStatusType("success");
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={styles.buttonGroup}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.actionButton}
|
||||
onClick={matchSizeToFirstSelected}
|
||||
icon={<ArrowFitInRegular />}
|
||||
disabled={isProcessing}
|
||||
>
|
||||
Match Sizes
|
||||
</Button>
|
||||
<ActionButton
|
||||
title="Match Sizes"
|
||||
icon={<ArrowFitInRegular />}
|
||||
onClick={matchSizeToFirstSelected}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user