diff --git a/app/admin/blog-posts/page.tsx b/app/admin/blog-posts/page.tsx index 1db4de2d..5459b930 100644 --- a/app/admin/blog-posts/page.tsx +++ b/app/admin/blog-posts/page.tsx @@ -159,13 +159,13 @@ const BlogPostForm = ({ // ref for the content textarea const contentRef = useRef(null); - // image upload handler with auto-insert HTML tag - const handleImageUpload = async (e: React.ChangeEvent) => { + // Article image upload handler (for main blog image) + const handleArticleImageUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; const supabase = createClient(); - const filePath = `public/${Date.now()}-${file.name}`; + const filePath = `public/${Date.now()}-article-${file.name}`; // upload to supabase storage const { error } = await supabase.storage @@ -173,7 +173,7 @@ const BlogPostForm = ({ .upload(filePath, file); if (error) { - alert("Image upload failed: " + error.message); + alert("Article image upload failed: " + error.message); return; } @@ -184,7 +184,33 @@ const BlogPostForm = ({ if (publicUrlData?.publicUrl) { onFormChange({ image: publicUrlData.publicUrl }); + } + } + + // image upload handler for inserting into content + const handleContentImageUpload = async (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (!file) return; + + const supabase = createClient(); + const filePath = `public/${Date.now()}-${file.name}`; + + // upload to supabase storage + const { error } = await supabase.storage + .from('blog-images') + .upload(filePath, file); + if (error) { + alert("Image upload failed: " + error.message); + return; + } + + // Get public url + const { data: publicUrlData } = supabase.storage + .from('blog-images') + .getPublicUrl(filePath); + + if (publicUrlData?.publicUrl) { // insert html tag at cursor in content if (contentRef.current) { const textarea = contentRef.current; @@ -205,6 +231,26 @@ const BlogPostForm = ({ return (
+ {/* Article Image upload section */} +
+ + + {formData.image && ( +
+ Article Preview +
+ +
+
+ )} +
+
+ {/* Content image upload button */}