From 38313f634030e04b27c2dc248f70bf65d9946c65 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 9 Jun 2026 08:29:05 +0000 Subject: [PATCH] Changes from server by Mohan --- app/(defaults)/(blog)/create-blog/page.tsx | 119 ++++++++++++--------- 1 file changed, 70 insertions(+), 49 deletions(-) diff --git a/app/(defaults)/(blog)/create-blog/page.tsx b/app/(defaults)/(blog)/create-blog/page.tsx index a2cbd80..2ace063 100644 --- a/app/(defaults)/(blog)/create-blog/page.tsx +++ b/app/(defaults)/(blog)/create-blog/page.tsx @@ -1,52 +1,28 @@ "use client"; + import IconTrashLines from "@/components/icon/icon-trash-lines"; -import React, { useState } from "react"; -import ReactQuill from "react-quill"; +import dynamic from "next/dynamic"; +import React, { useMemo, useState } from "react"; import "react-quill/dist/quill.snow.css"; -// Custom toolbar options -const modules = { - toolbar: { - container: [ - [{ header: [1, 2, 3, false] }], - ["bold", "italic", "underline", "strike"], - [{ list: "ordered" }, { list: "bullet" }], - ["blockquote", "code-block"], - [{ align: [] }], - ["link", "image", "video"], - ["clean"], - ], - handlers: { - image: function () { - const input = document.createElement("input"); - input.setAttribute("type", "file"); - input.setAttribute("accept", "image/*"); - input.click(); - - input.onchange = async () => { - const file = input.files?.[0]; - if (file) { - const reader = new FileReader(); - reader.onload = () => { - const quill = this.quill; - const range = quill.getSelection(); - quill.insertEmbed(range.index, "image", reader.result); - }; - reader.readAsDataURL(file); - } - }; - }, - }, - }, -}; +const ReactQuill = dynamic(() => import("react-quill"), { + ssr: false, +}); const formats = [ "header", - "bold", "italic", "underline", "strike", - "blockquote", "code-block", - "list", "bullet", + "bold", + "italic", + "underline", + "strike", + "blockquote", + "code-block", + "list", + "bullet", "align", - "link", "image", "video", + "link", + "image", + "video", ]; const PostForm = () => { @@ -57,8 +33,55 @@ const PostForm = () => { description: "", }); + const modules = useMemo( + () => ({ + toolbar: { + container: [ + [{ header: [1, 2, 3, false] }], + ["bold", "italic", "underline", "strike"], + [{ list: "ordered" }, { list: "bullet" }], + ["blockquote", "code-block"], + [{ align: [] }], + ["link", "image", "video"], + ["clean"], + ], + handlers: { + image: function (this: any) { + const input = document.createElement("input"); + input.setAttribute("type", "file"); + input.setAttribute("accept", "image/*"); + input.click(); + + input.onchange = async () => { + const file = input.files?.[0]; + + if (file) { + const reader = new FileReader(); + + reader.onload = () => { + const quill = this.quill; + const range = quill.getSelection(true); + + quill.insertEmbed( + range.index, + "image", + reader.result + ); + }; + + reader.readAsDataURL(file); + } + }; + }, + }, + }, + }), + [] + ); + const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; + setFormData((prev) => ({ ...prev, [name]: value, @@ -67,6 +90,7 @@ const PostForm = () => { const handleImageChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] || null; + setFormData((prev) => ({ ...prev, coverImage: file, @@ -93,9 +117,11 @@ const PostForm = () => { const data = new FormData(); data.append("title", formData.title); data.append("slug", formData.slug); + if (formData.coverImage) { data.append("coverImage", formData.coverImage); } + data.append("description", formData.description); console.log("FormData prepared:", { @@ -112,7 +138,7 @@ const PostForm = () => { className="space-y-5 max-w-4xl mx-auto p-6 bg-white rounded shadow-md" >

Create Blog

- {/* Blog Title */} +
{ />
- {/* Slug */}
{ name="slug" value={formData.slug} onChange={handleChange} - placeholder="Enter slug (e.g. my-first-blog)" + placeholder="Enter slug" className="w-full border rounded-md px-3 py-2 focus:ring-2 focus:ring-green-500 outline-none" />
- {/* Cover Image Upload */}
{ />
- {/* Show Image Preview */} {formData.coverImage && (

Preview:

@@ -170,7 +193,6 @@ const PostForm = () => {
)} - {/* Description (ReactQuill) */}
{ />
- {/* Submit Button */}