"use client"; import React, { useState, useRef, useEffect } from 'react'; import Image from 'next/image'; import { LayoutDashboard, Newspaper, Users, BarChart3, Settings, HelpCircle, Image as ImageIcon, Type, Calendar, Clock, Tag, User, Save, Eye, Send } from 'lucide-react'; // Importe o componente que criámos (ajuste o caminho se necessário) import MultiAspectEditor from '../../../components/MultiAspectEditor'; import dynamic from "next/dynamic"; import { getTree, type Category } from "@/lib/categories.api"; // import { keycloak } from '@/app/feature/auth/keycloak-config'; const Editor = dynamic( () => import("@tinymce/tinymce-react").then((mod) => mod.Editor), { ssr: false } ); export const CreateNewsPage = () => { // Configuração do Design do Editor para combinar com seu layout const editorConfig = { height: 500, menubar: false, plugins: [ 'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview', 'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen', 'insertdatetime', 'media', 'table', 'code', 'help', 'wordcount' ], // Adicionei 'blockquote' na toolbar toolbar: 'undo redo | blocks | ' + 'bold italic forecolor | alignleft aligncenter ' + 'alignright alignjustify | bullist numlist | ' + 'blockquote link image | removeformat | help', // Customização do aspeto da citação dentro do editor content_style: ` body { font-family: Inter, Helvetica, Arial, sans-serif; font-size: 14px; color: #334155; line-height: 1.6; } blockquote { border-left: 4px solid #2563eb; /* Azul da TVone */ padding-left: 1.5rem; color: #475569; font-style: italic; margin: 1.5rem 0; background: #f8fafc; padding: 1rem 1.5rem; border-radius: 0 8px 8px 0; } `, skin: 'oxide', promotion: false, // Remove o botão "Upgrade" do Tiny branding: false, // Remove o "Powered by Tiny" }; // 1. Estados para o Crop const [tempImage, setTempImage] = useState(null); const [isEditorOpen, setIsEditorOpen] = useState(false); const [finalCrops, setFinalCrops] = useState(null); // Guarda os Base64 finais const [content, setContent] = useState(''); const [user, setUser] = useState<{ email?: string; name?: string; picture?: string; } | null>(null); const [categories, setCategories] = useState([]); const [categoriesLoading, setCategoriesLoading] = useState(true); const [categoryId, setCategoryId] = useState(""); const [subCategoryId, setSubCategoryId] = useState(""); const [showSubCategoryError, setShowSubCategoryError] = useState(false); const fileInputRef = useRef(null); useEffect(() => { let cancelled = false; (async () => { setCategoriesLoading(true); try { const list = await getTree(); if (!cancelled) setCategories(list); } catch { if (!cancelled) setCategories([]); } finally { if (!cancelled) setCategoriesLoading(false); } })(); return () => { cancelled = true; }; }, []); const parentCategories = categories.filter((c) => !c.parentId); const selectedParentCategory = parentCategories.find((c) => c.id === categoryId); const subCategories = selectedParentCategory?.children ?? []; const isSubCategoryRequired = Boolean(categoryId) && subCategories.length > 0; const handleCategoryChange = (value: string) => { setCategoryId(value); setSubCategoryId(""); setShowSubCategoryError(false); }; const handlePublish = () => { if (isSubCategoryRequired && !subCategoryId) { setShowSubCategoryError(true); return; } setShowSubCategoryError(false); // TODO: ligar ao endpoint de publicar quando o fluxo de submissão estiver pronto. }; // 2. Lógica de Upload const handleFileChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { const reader = new FileReader(); reader.readAsDataURL(e.target.files[0]); reader.onload = () => { setTempImage(reader.result as string); setIsEditorOpen(true); }; } }; const triggerUpload = () => { fileInputRef.current?.click(); }; // Avoid hydration mismatch by waiting for mount // useEffect(() => { // keycloak.init({ // onLoad: "check-sso", // pkceMethod: "S256", // }).then(async (authenticated) => { // if (authenticated) { // const token = keycloak.token!; // localStorage.setItem("token", token); // // 👉 send token to Next.js backend // fetch("/api/session", { // method: "POST", // body: JSON.stringify({ token }), // }); // const res = await fetch("http://localhost:3001/profile/", { // headers: { // //Authorization: `Bearer ${token}`, // }, // }); // const profile = await res.json(); // var keycloakData : { // email: string, // email_verified: boolean, // name: string, // picture: string, // roles: string[] // } = profile.keycloak // setUser(keycloakData); // console.log("Profile:", keycloakData); // } // }); // }, []); return (

Criar Nova Notícia

{/* Coluna Principal */}
{/* Título */}

{/* TinyMCE Editor */}
{/* setContent(newContent)} /> */}
{/* Resumo (Lead) */}