Skip to content

Commit

Permalink
more cleanup and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
t3dotgg committed Nov 11, 2024
1 parent fc28e23 commit abba7df
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
15 changes: 6 additions & 9 deletions src/app/(tools)/rounded-border/rounded-tool.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use client";
import { usePlausible } from "next-plausible";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { useLocalStorage } from "@/hooks/use-local-storage";
import React from "react";
import { UploadBox } from "@/components/shared/upload-box";
import { OptionSelector } from "@/components/shared/option-selector";
import { BorderRadiusSelector } from "@/components/border-radius-selector";
Expand Down Expand Up @@ -82,14 +81,14 @@ interface ImageRendererProps {
background: BackgroundOption;
}

const ImageRenderer: React.FC<ImageRendererProps> = ({
const ImageRenderer = ({
imageContent,
radius,
background,
}) => {
const containerRef = React.useRef<HTMLDivElement>(null);
}: ImageRendererProps) => {
const containerRef = useRef<HTMLDivElement>(null);

React.useEffect(() => {
useEffect(() => {
if (containerRef.current) {
const imgElement = containerRef.current.querySelector("img");
if (imgElement) {
Expand Down Expand Up @@ -125,9 +124,7 @@ function SaveAsPngButton({
background: BackgroundOption;
imageMetadata: { width: number; height: number; name: string };
}) {
const [canvasRef, setCanvasRef] = React.useState<HTMLCanvasElement | null>(
null,
);
const [canvasRef, setCanvasRef] = useState<HTMLCanvasElement | null>(null);
const { convertToPng, canvasProps } = useImageConverter({
canvas: canvasRef,
imageContent,
Expand Down
4 changes: 2 additions & 2 deletions src/app/(tools)/square-image/square-tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function SquareToolCore(props: { fileUploaderProps: FileUploaderResult }) {
);
}

export const SquareTool: React.FC = () => {
export function SquareTool() {
const fileUploaderProps = useFileUploader();

return (
Expand All @@ -149,4 +149,4 @@ export const SquareTool: React.FC = () => {
<SquareToolCore fileUploaderProps={fileUploaderProps} />
</FileDropzone>
);
};
}
4 changes: 2 additions & 2 deletions src/app/(tools)/svg-to-png/svg-tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface SVGRendererProps {
svgContent: string;
}

const SVGRenderer: React.FC<SVGRendererProps> = ({ svgContent }) => {
function SVGRenderer({ svgContent }: SVGRendererProps) {
const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
Expand All @@ -94,7 +94,7 @@ const SVGRenderer: React.FC<SVGRendererProps> = ({ svgContent }) => {
}, [svgContent]);

return <div ref={containerRef} />;
};
}

function SaveAsPngButton({
svgContent,
Expand Down
6 changes: 3 additions & 3 deletions src/components/shared/file-dropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ interface FileDropzoneProps {
setCurrentFile: (file: File) => void;
}

export const FileDropzone: React.FC<FileDropzoneProps> = ({
export function FileDropzone({
children,
acceptedFileTypes,
dropText,
setCurrentFile,
}) => {
}: FileDropzoneProps) {
const [isDragging, setIsDragging] = useState(false);
const dragCounter = useRef(0);

Expand Down Expand Up @@ -93,4 +93,4 @@ export const FileDropzone: React.FC<FileDropzoneProps> = ({
{children}
</div>
);
};
}
8 changes: 3 additions & 5 deletions src/components/shared/upload-box.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client";

import React from "react";

interface UploadBoxProps {
Expand All @@ -10,13 +8,13 @@ interface UploadBoxProps {
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

export const UploadBox: React.FC<UploadBoxProps> = ({
export function UploadBox({
title,
subtitle,
description,
accept,
onChange,
}) => {
}: UploadBoxProps) {
return (
<div className="flex flex-col items-center justify-center gap-4 p-4">
<div className="flex flex-col items-center gap-2">
Expand Down Expand Up @@ -55,4 +53,4 @@ export const UploadBox: React.FC<UploadBoxProps> = ({
</div>
</div>
);
};
}

0 comments on commit abba7df

Please sign in to comment.