Skip to content

Commit

Permalink
create a types folder
Browse files Browse the repository at this point in the history
  • Loading branch information
VeraZab committed Jan 9, 2024
1 parent 425772d commit b663776
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 45 deletions.
22 changes: 2 additions & 20 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { ThemeProvider } from "@emotion/react";
import Box from "@mui/material/Box";
import { ChangeEvent, useRef, useState } from "react";

import { Theme } from "@mui/material";
import Canvas from "./components/Canvas";
import Controls from "./components/Controls";
import Layout from "./components/Layout";
import { theme } from "./theme";
import { Theme } from "@mui/material";
import { CanvasDimensions, ImageAttributes, TileDimensions } from "./types/appState";

export const layoutStyles = (theme: Theme) => ({
display: "flex",
Expand All @@ -19,25 +20,6 @@ export const layoutStyles = (theme: Theme) => ({
},
});

export interface CanvasDimensions {
width: number;
height: number;
}

export interface TileDimensions {
originalWidth: number;
originalHeight: number;
width: number;
height: number;
}

export interface ImageAttributes {
url: string | null;
fileName: string | null;
image: HTMLImageElement | null;
}


const App: React.FC = () => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const [canvasState, setCanvasState] = useState<CanvasDimensions>({
Expand Down
9 changes: 1 addition & 8 deletions src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Theme } from "@mui/material";
import Box from "@mui/material/Box";
import { CSSProperties, useEffect } from "react";

import { CanvasDimensions, ImageAttributes, TileDimensions } from "../App";
import { CanvasProps } from "../types/canvas";

const canvasContainerStyles = (theme: Theme) => ({
display: "flex",
Expand All @@ -22,13 +22,6 @@ const canvasStyles: CSSProperties = {
border: "1px solid grey",
}

interface CanvasProps {
canvasState: CanvasDimensions;
tileState: TileDimensions;
imageState: ImageAttributes;
canvasRef: React.RefObject<HTMLCanvasElement>;
}

const Canvas: React.FC<CanvasProps> = ({ canvasRef, tileState, imageState, canvasState }) => {
useEffect(() => {
const canvas = canvasRef.current;
Expand Down
14 changes: 2 additions & 12 deletions src/components/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import CloudUploadIcon from "@mui/icons-material/CloudUpload";
import ReplayIcon from "@mui/icons-material/Replay";
import { Box, Button, IconButton, InputAdornment, TextField } from "@mui/material";
import { Theme } from "@mui/material/styles";
import { ChangeEvent } from "react";

import { CanvasDimensions, ImageAttributes, TileDimensions } from "../App";
import { CanvasDimensions } from "../types/appState";
import { ControlsProps } from "../types/controls";
import ImageInput from "./ImageInput";

const controlsContainerStyles = (theme: Theme) => ({
Expand Down Expand Up @@ -51,16 +51,6 @@ const mainControlsContainer = {
margin: (theme: Theme) => theme.spacing(6, 0)
}

interface ControlsProps {
canvasRef: React.RefObject<HTMLCanvasElement>;
canvasState: CanvasDimensions;
setCanvasState: React.Dispatch<React.SetStateAction<CanvasDimensions>>;
tileState: TileDimensions;
setTileState: React.Dispatch<React.SetStateAction<TileDimensions>>;
imageState: ImageAttributes;
handleFileChange: (event: ChangeEvent<HTMLInputElement>) => void;
}

const Controls: React.FC<ControlsProps> = ({
canvasRef,
canvasState,
Expand Down
6 changes: 1 addition & 5 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Theme } from "@mui/material";
import React from "react";

import { LayoutProps } from "../types/layout";
import Footer from "./Footer";
import Header from "./Header";

Expand All @@ -13,11 +14,6 @@ const layoutContainerStyles = (theme: Theme) => ({
boxSizing: "border-box",
})

// Define the props for the Layout component
interface LayoutProps {
children?: React.ReactNode;
}

const Layout: React.FC<LayoutProps> = ({ children }) => {
return (
<Box
Expand Down
17 changes: 17 additions & 0 deletions src/types/appState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface CanvasDimensions {
width: number;
height: number;
}

export interface TileDimensions {
originalWidth: number;
originalHeight: number;
width: number;
height: number;
}

export interface ImageAttributes {
url: string | null;
fileName: string | null;
image: HTMLImageElement | null;
}
8 changes: 8 additions & 0 deletions src/types/canvas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CanvasDimensions, ImageAttributes, TileDimensions } from "../types/appState";

export interface CanvasProps {
canvasState: CanvasDimensions;
tileState: TileDimensions;
imageState: ImageAttributes;
canvasRef: React.RefObject<HTMLCanvasElement>;
}
13 changes: 13 additions & 0 deletions src/types/controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChangeEvent } from "react";

import { CanvasDimensions, ImageAttributes, TileDimensions } from "../types/appState";

export interface ControlsProps {
canvasRef: React.RefObject<HTMLCanvasElement>;
canvasState: CanvasDimensions;
setCanvasState: React.Dispatch<React.SetStateAction<CanvasDimensions>>;
tileState: TileDimensions;
setTileState: React.Dispatch<React.SetStateAction<TileDimensions>>;
imageState: ImageAttributes;
handleFileChange: (event: ChangeEvent<HTMLInputElement>) => void;
}
3 changes: 3 additions & 0 deletions src/types/layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface LayoutProps {
children?: React.ReactNode;
}

0 comments on commit b663776

Please sign in to comment.