Skip to content

Commit

Permalink
Use image for dimensions and use codeText to set limit
Browse files Browse the repository at this point in the history
  • Loading branch information
leowrites committed Nov 5, 2024
1 parent 34ae304 commit e785baa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions webstepper/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import CodeDisplay from "./CodeDisplay";

export default function App() {
const [step, setStep] = useState<number>(0);
const limit = 4;
const handleStep = (newStep: number) => {
setStep(Math.min(Math.max(newStep, 0), limit - 1));
};
const svgPath = `/images/snapshot-${step}.svg`;

// TODO: remove this and replace it with actual stuff lol
const codeText = `num = 123
some_string = "Hello, world"
num2 = 321
arr = [some_string, "string 123321"]`;
const limit = codeText.split("\n").length;
const handleStep = (newStep: number) => {
setStep(Math.min(Math.max(newStep, 0), limit - 1));
};
const svgPath = `/images/snapshot-${step}.svg`;

return (
<main className="container">
Expand Down
2 changes: 1 addition & 1 deletion webstepper/src/SvgDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SvgDisplay(props: SvgDisplayPropTypes) {
image.src = URL.createObjectURL(blob);
image.onload = () => {
const context = canvasRef.current.getContext("2d");
context.clearRect(0, 0, canvasWidth, canvasHeight);
context.clearRect(0, 0, image.width, image.height);
context.drawImage(image, 0, 0);
};
} catch (error) {
Expand Down

0 comments on commit e785baa

Please sign in to comment.