From c25c789d01c22516cb4256c63a39a6234d67c3f3 Mon Sep 17 00:00:00 2001 From: mukimovd <41473651-mukimovd@users.noreply.replit.com> Date: Fri, 9 May 2025 11:11:52 +0000 Subject: [PATCH] Improve blog creation and editing experience for content creators Removes ComponentTest, refactors BlogCreate to use BlogEditor, and fixes tag selection in TagManager. Replit-Commit-Author: Agent Replit-Commit-Session-Id: bddfbb2b-6d6b-457b-b18c-05792cdaa035 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/0bdb145c-ca28-40e0-9c67-49f51753727e.jpg --- client/src/App.tsx | 6 - client/src/components/blog/tag-manager.tsx | 4 +- client/src/pages/blog/BlogCreate.tsx | 188 ++------------------- client/src/pages/tests/ComponentTest.tsx | 1 - 4 files changed, 13 insertions(+), 186 deletions(-) delete mode 100644 client/src/pages/tests/ComponentTest.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 01b60d5..6c73aa1 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -21,9 +21,6 @@ import { BlogList, BlogDetail, BlogCreate } from "@/pages/blog"; import Dashboard from "@/pages/dashboard/Dashboard"; import BlogManagement from "@/pages/dashboard/BlogManagement"; -// Test pages -import ComponentTest from "@/pages/tests/ComponentTest"; - function Router() { return ( @@ -46,9 +43,6 @@ function Router() { - {/* Test Routes */} - - ); diff --git a/client/src/components/blog/tag-manager.tsx b/client/src/components/blog/tag-manager.tsx index 06cf335..48386db 100644 --- a/client/src/components/blog/tag-manager.tsx +++ b/client/src/components/blog/tag-manager.tsx @@ -29,7 +29,7 @@ export function TagManager({ useEffect(() => { const formTags = form.getValues(name) || []; if (tags && formTags.length > 0) { - const initialTags = formTags.map(id => tags.find(t => t.id === id)).filter(Boolean) as Tag[]; + const initialTags = formTags.map((id: number) => tags.find(t => t.id === id)).filter(Boolean) as Tag[]; setSelectedTags(initialTags); } }, [tags, form, name]); @@ -58,7 +58,7 @@ export function TagManager({ // Update form values const currentTags = form.getValues(name) || []; - form.setValue(name, currentTags.filter(id => id !== tagId), { shouldValidate: true }); + form.setValue(name, currentTags.filter((id: number) => id !== tagId), { shouldValidate: true }); }; return ( diff --git a/client/src/pages/blog/BlogCreate.tsx b/client/src/pages/blog/BlogCreate.tsx index 63a5b48..787c106 100644 --- a/client/src/pages/blog/BlogCreate.tsx +++ b/client/src/pages/blog/BlogCreate.tsx @@ -3,12 +3,9 @@ import { Button } from "@/components/ui/button"; import { Link, useLocation } from "wouter"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; -import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; -import { Badge } from "@/components/ui/badge"; -import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select"; -import { ChevronLeft, Plus, X, Loader2 } from "lucide-react"; +import { ChevronLeft, Loader2 } from "lucide-react"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -18,6 +15,8 @@ import { useState } from "react"; import { useMutation, useQuery } from "@tanstack/react-query"; import { useToast } from "@/hooks/use-toast"; import { insertBlogPostSchema, Tag } from "@shared/schema"; +import { BlogEditor } from "@/components/blog/blog-editor"; +import { TagManager } from "@/components/blog/tag-manager"; const blogPostSchema = insertBlogPostSchema.extend({ tags: z.array(z.number()).optional(), @@ -25,49 +24,9 @@ const blogPostSchema = insertBlogPostSchema.extend({ type FormValues = z.infer; -// Simple rich text editor toolbar -function EditorToolbar() { - return ( -
- - - - - - - - - - -
- ); -} - export default function BlogCreate() { const [, navigate] = useLocation(); const { toast } = useToast(); - const [selectedTags, setSelectedTags] = useState([]); - const [selectedTagId, setSelectedTagId] = useState(""); const [publishNow, setPublishNow] = useState(true); // Fetch tags for selection @@ -120,41 +79,11 @@ export default function BlogCreate() { }, }); - // Handle tag selection - const handleAddTag = () => { - if (!selectedTagId) return; - - const tagId = parseInt(selectedTagId, 10); - const tag = tags?.find(t => t.id === tagId); - - if (tag && !selectedTags.some(t => t.id === tag.id)) { - setSelectedTags([...selectedTags, tag]); - - // Update form values - const currentTags = form.getValues("tags") || []; - form.setValue("tags", [...currentTags, tag.id]); - } - - setSelectedTagId(""); - }; - - // Handle tag removal - const handleRemoveTag = (tagId: number) => { - setSelectedTags(selectedTags.filter(tag => tag.id !== tagId)); - - // Update form values - const currentTags = form.getValues("tags") || []; - form.setValue("tags", currentTags.filter(id => id !== tagId)); - }; - // Handle form submission const onSubmit = (values: FormValues) => { createMutation.mutate(values); }; - // Preview content (would be processed markdown/html in a real app) - const previewContent = form.watch("content"); - return (
@@ -220,111 +149,16 @@ export default function BlogCreate() { )} /> -
- Tags -
- {selectedTags.map(tag => ( - - {tag.name} - - - ))} - - {selectedTags.length === 0 && ( -

- No tags selected -

- )} -
- -
- - - -
-
+ - ( - - Content - - - Write - Preview - - - - - -