image-converter-client/app/routes/_index.tsx

64 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-11-02 15:47:17 +00:00
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/cloudflare";
import DragableBox from "./DragableBox";
import { useEffect, useState } from "react";
import { useLoaderData, useSearchParams } from "@remix-run/react";
2024-10-30 22:11:22 +00:00
export const meta: MetaFunction = () => {
return [
2024-11-02 15:47:17 +00:00
{ title: "Convert images for the web!" },
{ name: "image converter", content: "Image conversion service" },
2024-10-30 22:11:22 +00:00
];
};
export default function Index() {
2024-11-02 15:47:17 +00:00
const [searchParams] = useSearchParams();
const [selectorHeight, setSelectorHeight] = useState(0);
const [selectorWidth, setSelectorWidth] = useState(0);
const [selectorTop, setSelectorTop] = useState(0);
const [selectorLeft, setSelectorLeft] = useState(0);
2024-11-02 17:25:14 +00:00
const [firstDragable, setFirstDragable] = useState({
x: 0,
y: 0
})
2024-11-02 15:47:17 +00:00
2024-11-02 17:25:14 +00:00
const [secondDragable, setSecondDragable] = useState({
x: 0,
y: 0
})
2024-11-02 15:47:17 +00:00
// Use useEffect to calculate dimensions and position
useEffect(() => {
// Calculate width
2024-11-02 17:25:14 +00:00
const width = Math.abs(secondDragable.x - firstDragable.x);
2024-11-02 15:47:17 +00:00
setSelectorWidth(width);
2024-11-02 17:25:14 +00:00
2024-11-02 15:47:17 +00:00
// Calculate height
2024-11-02 17:25:14 +00:00
const height = Math.abs(secondDragable.y - firstDragable.y);
2024-11-02 15:47:17 +00:00
setSelectorHeight(height);
2024-11-02 17:25:14 +00:00
2024-11-02 15:47:17 +00:00
// Calculate top position (minimum of y coordinates)
2024-11-02 17:25:14 +00:00
setSelectorTop(Math.min(firstDragable.y, secondDragable.y));
2024-11-02 15:47:17 +00:00
// Calculate left position (minimum of x coordinates)
2024-11-02 17:25:14 +00:00
setSelectorLeft(Math.min(firstDragable.x, secondDragable.x));
}, [firstDragable, secondDragable]);
2024-11-02 15:47:17 +00:00
2024-10-30 22:11:22 +00:00
return (
2024-11-02 15:47:17 +00:00
<div className="flex h-screen w-screen justify-center items-center">
<div className="relative w-1/3 h-1/3 border-black border">
<div
className="border border-black absolute"
style={{
top: `${selectorTop}px`,
left: `${selectorLeft}px`,
height: `${selectorHeight}px`,
width: `${selectorWidth}px`,
}}
/>
2024-11-02 17:25:14 +00:00
<DragableBox initialX={0} initialY={0} setter={setFirstDragable} />
<DragableBox initialX={100} initialY={100} setter={setSecondDragable} />
2024-11-02 15:47:17 +00:00
</div>
</div>
);
2024-10-30 22:11:22 +00:00
}