([]);
+
+ const handleUpdateTitle = (title: string) => {
+ setGuide((prev) => ({ ...prev, title }));
+ };
+
+ const handleUpdateDescription = (description: string) => {
+ setGuide((prev) => ({ ...prev, description }));
+ };
+
+ const handleAddFrames = (newFiles: File[]) => {
+ const newFrameObjects = newFiles.map((file) => ({
+ id: crypto.randomUUID(),
+ file: file,
+ guideId: guide.id,
+ }));
+
+ setFrames((prev) => [...prev, ...newFrameObjects]);
+ };
+
+ const handleRemoveFrame = (frameId: string) => {
+ setFrames((prev) => prev.filter((frame) => frame.id !== frameId));
+ };
+
+ const handleAddSteps = (frameId: string) => {
+ setSteps((prev) => [
+ ...prev,
+ {
+ id: crypto.randomUUID(),
+ text: "",
+ frameId: frameId,
+ },
+ ]);
+ };
+
+ const handleUpdateStepText = (stepId: string, text: string) => {
+ setSteps((prev) =>
+ prev.map((step) => (step.id === stepId ? { ...step, text } : step)),
+ );
+ };
+
+ const handleRemoveStep = (stepId: string) => {
+ setSteps((prev) => prev.filter((step) => step.id !== stepId));
+ };
+
+ return {
+ guide,
+ setGuide,
+ frames,
+ setFrames,
+ steps,
+ setSteps,
+ handleUpdateTitle,
+ handleUpdateDescription,
+ handleAddFrames,
+ handleAddSteps,
+ handleRemoveFrame,
+ handleUpdateStepText,
+ handleRemoveStep,
+ };
+}
diff --git a/src/features/guides/routes/NewGuide.tsx b/src/features/guides/routes/NewGuide.tsx
index 700770d..af7377c 100644
--- a/src/features/guides/routes/NewGuide.tsx
+++ b/src/features/guides/routes/NewGuide.tsx
@@ -1,7 +1,20 @@
+import FileUpload from "../components/FileUpload";
+
export default function NewGuide() {
return (
-
New Guide
+
);
}
diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts
index 8d32928..33c8433 100644
--- a/src/lib/schemas.ts
+++ b/src/lib/schemas.ts
@@ -3,26 +3,22 @@ import { z } from "zod";
export const StepsSchema = z.object({
id: z.uuid().default(() => crypto.randomUUID()),
text: z.string().min(1, "Text is required"),
- order: z.number(),
frameId: z.uuid(),
});
export const FrameSchema = z.object({
id: z.uuid().default(() => crypto.randomUUID()),
file: z.instanceof(File),
- steps: z.array(StepsSchema).min(1, "Steps are required"),
- order: z.number(),
+ guideId: z.uuid(),
});
export const GuideSchema = z.object({
id: z.uuid().default(() => crypto.randomUUID()),
title: z.string().min(1, "Title is required"),
description: z.string().optional(),
- content: z.string().optional(),
createdAt: z.date(),
updatedAt: z.date(),
deletedAt: z.date().optional(),
- frames: z.array(FrameSchema).min(1, "Frames are required"),
});
export type Steps = z.infer;