diff --git a/app/(page)/create-news/create-news.tsx b/app/(page)/create-news/create-news.tsx new file mode 100644 index 0000000..bfbfb37 --- /dev/null +++ b/app/(page)/create-news/create-news.tsx @@ -0,0 +1,277 @@ +"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 { AdminHeaderPage } from '@/app/components/layout/admin/header'; +import { AdminSideBar } from '@/app/components/layout/admin/sidebar'; +// 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 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); + + // // 👉 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) */} +
+ +