Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Coming Soon to Blogs #245

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 69 additions & 68 deletions src/client/routes/blogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,79 +78,80 @@ export const Route = createFileRoute("/blogs")({
setError(null);
};

if (blogs.isLoading) return <div>Loading blogs...</div>;
if (blogs.isError) return <div>Error loading blogs: {blogs.error.message}</div>;
// if (blogs.isLoading) return <div>Loading blogs...</div>;
// if (blogs.isError) return <div>Error loading blogs: {blogs.error.message}</div>;

return (
<div className="container mx-auto p-4">
<h1 className="mb-6 text-3xl font-bold">Blogs</h1>
<p>Coming Soon!</p>
// <div className="container mx-auto p-4">
// <h1 className="mb-6 text-3xl font-bold">Blogs</h1>

{isAuthenticated && !isCreating && !isEditing && (
<Button onClick={() => setIsCreating(true)} className="mb-4">
Create New Blog Post
</Button>
)}
// {isAuthenticated && !isCreating && !isEditing && (
// <Button onClick={() => setIsCreating(true)} className="mb-4">
// Create New Blog Post
// </Button>
// )}

{(isCreating || isEditing) && (
<div className="mb-8 rounded-lg bg-white p-6 shadow-md">
<h2 className="mb-4 text-2xl font-bold">{isCreating ? "Create New Blog Post" : "Edit Blog Post"}</h2>
<div className="space-y-4">
<div>
<label className="mb-1 block text-sm font-medium text-gray-700">Title</label>
<Input value={newBlogTitle} onChange={(e) => setNewBlogTitle(e.target.value)} placeholder="Enter blog title" className="w-full" />
</div>
<div>
<label className="mb-1 block text-sm font-medium text-gray-700">Content</label>
<Textarea
value={newBlogContent}
onChange={(e) => setNewBlogContent(e.target.value)}
placeholder="Enter blog content"
className="min-h-[200px] w-full"
/>
</div>
<div>
<label className="mb-1 block text-sm font-medium text-gray-700">Tags</label>
<Input
value={newBlogTags}
onChange={(e) => setNewBlogTags(e.target.value)}
placeholder="Enter tags (comma-separated)"
className="w-full"
/>
</div>
</div>
<div className="mt-4 space-x-2">
<Button onClick={isCreating ? handleCreateBlog : handleUpdateBlog}>{isCreating ? "Create Post" : "Update Post"}</Button>
<Button
variant="secondary"
onClick={() => {
setIsCreating(false);
setIsEditing(false);
setCurrentBlog(null);
resetForm();
}}
>
Cancel
</Button>
</div>
{error && <div className="mt-2 text-red-500">{error}</div>}
</div>
)}
// {(isCreating || isEditing) && (
// <div className="mb-8 rounded-lg bg-white p-6 shadow-md">
// <h2 className="mb-4 text-2xl font-bold">{isCreating ? "Create New Blog Post" : "Edit Blog Post"}</h2>
// <div className="space-y-4">
// <div>
// <label className="mb-1 block text-sm font-medium text-gray-700">Title</label>
// <Input value={newBlogTitle} onChange={(e) => setNewBlogTitle(e.target.value)} placeholder="Enter blog title" className="w-full" />
// </div>
// <div>
// <label className="mb-1 block text-sm font-medium text-gray-700">Content</label>
// <Textarea
// value={newBlogContent}
// onChange={(e) => setNewBlogContent(e.target.value)}
// placeholder="Enter blog content"
// className="min-h-[200px] w-full"
// />
// </div>
// <div>
// <label className="mb-1 block text-sm font-medium text-gray-700">Tags</label>
// <Input
// value={newBlogTags}
// onChange={(e) => setNewBlogTags(e.target.value)}
// placeholder="Enter tags (comma-separated)"
// className="w-full"
// />
// </div>
// </div>
// <div className="mt-4 space-x-2">
// <Button onClick={isCreating ? handleCreateBlog : handleUpdateBlog}>{isCreating ? "Create Post" : "Update Post"}</Button>
// <Button
// variant="secondary"
// onClick={() => {
// setIsCreating(false);
// setIsEditing(false);
// setCurrentBlog(null);
// resetForm();
// }}
// >
// Cancel
// </Button>
// </div>
// {error && <div className="mt-2 text-red-500">{error}</div>}
// </div>
// )}

<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{blogs.data && blogs.data.length > 0 ? (
blogs.data.map((blog: Blog) => (
<div key={blog.id} className="rounded-lg bg-white p-6 shadow-md">
<h2 className="mb-2 text-xl font-bold">{blog.title}</h2>
<p className="mb-4 text-gray-600">{blog.content.substring(0, 100)}...</p>
{/* {blog.tags && <p className="mb-2 text-sm text-gray-500">Tags: {blog.tags.join(", ")}</p>} */}
{isAuthenticated && <Button onClick={() => handleEditBlog(blog)}>Edit</Button>}
</div>
))
) : (
<p>No blogs found.</p>
)}
</div>
</div>
// <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
// {blogs.data && blogs.data.length > 0 ? (
// blogs.data.map((blog: Blog) => (
// <div key={blog.id} className="rounded-lg bg-white p-6 shadow-md">
// <h2 className="mb-2 text-xl font-bold">{blog.title}</h2>
// <p className="mb-4 text-gray-600">{blog.content.substring(0, 100)}...</p>
// {/* {blog.tags && <p className="mb-2 text-sm text-gray-500">Tags: {blog.tags.join(", ")}</p>} */}
// {isAuthenticated && <Button onClick={() => handleEditBlog(blog)}>Edit</Button>}
// </div>
// ))
// ) : (
// <p>No blogs found.</p>
// )}
// </div>
// </div>
);
},
});
Loading