"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'; import Keycloak from "keycloak-js"; // Importe o componente que criámos (ajuste o caminho se necessário) import MultiAspectEditor from '../../components/MultiAspectEditor'; import dynamic from "next/dynamic"; const Editor = dynamic( () => import("@tinymce/tinymce-react").then((mod) => mod.Editor), { ssr: false } ); const keycloak = new Keycloak({ url: "https://keycloak.petermaquiran.xyz", realm: "tvone", // ✅ IMPORTANT clientId: "tvone-web", // must match Keycloak client }); interface GoogleAuthResponse { access_token: string; token_type: string; expires_in: number; scope: string; authuser?: string; prompt?: string; } interface KeycloakTokenResponse { access_token: string; expires_in: number; refresh_expires_in: number; refresh_token: string; token_type: string; id_token?: string; "not-before-policy": number; session_state: string; scope: string; } 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 fileInputRef = useRef(null); // 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); const res = await fetch("http://localhost:3001/profile/", { headers: { Authorization: `Bearer ${token}`, }, }); const profile = await res.json(); setUser(profile); console.log("Profile:", profile); } }); }, []); return (
{/* --- MODAL DO EDITOR (Renderiza fora do fluxo quando ativo) --- */} {isEditorOpen && tempImage && ( setIsEditorOpen(false)} onExport={(data) => { setFinalCrops(data); // Aqui tens o objeto com hero, news, square em Base64 setIsEditorOpen(false); console.log("Imagens prontas para envio:", data); }} /> )} {/* Sidebar Lateral */} {/* Main Content Area */}

{user?.name ?? "Loading..."}

Editor

User

Criar Nova Notícia

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

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