fix: apply bugfix agent improvements to src/app/dashboard/posts/[id]/edit/page.tsx
This commit is contained in:
parent
40f8c1cb5a
commit
1a0508bba5
|
|
@ -0,0 +1,61 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useContentStore } from "@/store/contentStore";
|
||||
import PostEditor from "@/components/posts/PostEditor";
|
||||
import type { Post } from "@/types";
|
||||
|
||||
export default function EditPostPage() {
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const { getPostById } = useContentStore();
|
||||
const [post, setPost] = useState<Post | null>(null);
|
||||
const [notFound, setNotFound] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const id = params?.id as string;
|
||||
if (!id) {
|
||||
setNotFound(true);
|
||||
return;
|
||||
}
|
||||
const found = getPostById(id);
|
||||
if (found) {
|
||||
setPost(found);
|
||||
} else {
|
||||
setNotFound(true);
|
||||
}
|
||||
}, [params, getPostById]);
|
||||
|
||||
if (notFound) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-20 gap-4">
|
||||
<p className="text-gray-500 text-lg">Post not found.</p>
|
||||
<button
|
||||
onClick={() => router.push("/dashboard/posts")}
|
||||
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 text-sm font-medium"
|
||||
>
|
||||
Back to Posts
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!post) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-20">
|
||||
<div className="w-8 h-8 border-4 border-primary-500 border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Edit Post</h1>
|
||||
<p className="text-gray-500 mt-1">Update your post content and settings.</p>
|
||||
</div>
|
||||
<PostEditor post={post} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue