@@ -1,7 +1,6 @@
|
||||
import { useEditorStore, type ToolType } from "@/pages/editor/store/editorStore";
|
||||
import { useSingleUpload } from "@/pages/uploader/hooks/useUploaderData";
|
||||
import { type ToolType } from "@/pages/editor/store/editorStore";
|
||||
import {
|
||||
ImageUpload,
|
||||
ImageGallery,
|
||||
VideoInput,
|
||||
LinkInput,
|
||||
SelectInstruction,
|
||||
@@ -18,39 +17,8 @@ type ToolInstructionsProps = {
|
||||
};
|
||||
|
||||
const ToolInstructions = ({ tool }: ToolInstructionsProps) => {
|
||||
const { addObject, setSelectedObjectId, setTool } = useEditorStore();
|
||||
const { mutateAsync: uploadFile } = useSingleUpload();
|
||||
|
||||
const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const result = await uploadFile(file);
|
||||
const imageUrl = result?.data?.url;
|
||||
if (!imageUrl) return;
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
const newImage = {
|
||||
id: `image-${Date.now()}`,
|
||||
type: "image" as ToolType,
|
||||
x: 100,
|
||||
y: 100,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
imageUrl,
|
||||
};
|
||||
addObject(newImage);
|
||||
setSelectedObjectId(newImage.id);
|
||||
setTool("select");
|
||||
};
|
||||
img.src = imageUrl;
|
||||
} catch {
|
||||
// TODO: show error toast
|
||||
}
|
||||
};
|
||||
|
||||
if (tool === "image") {
|
||||
return <ImageUpload onImageUpload={handleImageUpload} />;
|
||||
return <ImageGallery />;
|
||||
}
|
||||
|
||||
if (tool === "video") {
|
||||
|
||||
Reference in New Issue
Block a user