update fonction de texte
This commit is contained in:
@@ -10,7 +10,7 @@ h1 {
|
|||||||
color: #315397 !important;
|
color: #315397 !important;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
p,
|
||||||
h2,
|
h2,
|
||||||
h3,
|
h3,
|
||||||
h4,
|
h4,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function EditPost() {
|
|||||||
try {
|
try {
|
||||||
const post = await getPostById(id);
|
const post = await getPostById(id);
|
||||||
setTitle(post.title.rendered);
|
setTitle(post.title.rendered);
|
||||||
setContent(post.content.rendered.replace(/(<([^>]+)>)/gi, ""));
|
setContent(post.content.rendered);
|
||||||
setImageUrl(post?.jetpack_featured_media_url || null); // preview actuelle
|
setImageUrl(post?.jetpack_featured_media_url || null); // preview actuelle
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Erreur chargement article :", err);
|
console.error("Erreur chargement article :", err);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useParams, useNavigate } from "react-router-dom";
|
|||||||
import api from "../api";
|
import api from "../api";
|
||||||
|
|
||||||
const PostDetails = () => {
|
const PostDetails = () => {
|
||||||
const { slug } = useParams(); // ✅ Utilisation correcte du slug
|
const { slug } = useParams();
|
||||||
const [post, setPost] = useState(null);
|
const [post, setPost] = useState(null);
|
||||||
const [image, setImage] = useState(null);
|
const [image, setImage] = useState(null);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -18,16 +18,13 @@ const PostDetails = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`📢 Requête API pour le slug : ${slug}`);
|
console.log(`📢 Requête API pour le slug : ${slug}`);
|
||||||
|
|
||||||
// ✅ Requête API correcte
|
|
||||||
const response = await api.get(`wp/v2/posts?slug=${slug}&_fields=id,title,content,featured_media,date`);
|
const response = await api.get(`wp/v2/posts?slug=${slug}&_fields=id,title,content,featured_media,date`);
|
||||||
|
|
||||||
if (response.data.length > 0) {
|
if (response.data.length > 0) {
|
||||||
const article = response.data[0]; // ✅ Récupération du premier article trouvé
|
const article = response.data[0];
|
||||||
setPost(article);
|
setPost(article);
|
||||||
console.log("✅ Article trouvé :", article);
|
console.log("✅ Article trouvé :", article);
|
||||||
|
|
||||||
// ✅ Récupération de l'image en vedette si elle existe
|
|
||||||
if (article.featured_media) {
|
if (article.featured_media) {
|
||||||
console.log(`📢 Récupération de l'image ID : ${article.featured_media}`);
|
console.log(`📢 Récupération de l'image ID : ${article.featured_media}`);
|
||||||
const mediaResponse = await api.get(`wp/v2/media/${article.featured_media}`);
|
const mediaResponse = await api.get(`wp/v2/media/${article.featured_media}`);
|
||||||
@@ -42,7 +39,7 @@ const PostDetails = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchPost();
|
fetchPost();
|
||||||
}, [slug]); // ✅ Dépendance correcte
|
}, [slug]);
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
return <CircularProgress sx={{ display: "block", margin: "auto", mt: 5 }} />;
|
return <CircularProgress sx={{ display: "block", margin: "auto", mt: 5 }} />;
|
||||||
@@ -50,12 +47,10 @@ const PostDetails = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ padding: "40px 20px", display: "flex", flexDirection: "column" }}>
|
<Box sx={{ padding: "40px 20px", display: "flex", flexDirection: "column" }}>
|
||||||
{/* ✅ Bouton Retour */}
|
|
||||||
<Button onClick={() => navigate(-1)} variant="contained" sx={{ mt: 5, mb: 3, maxWidth: "200px" }}>
|
<Button onClick={() => navigate(-1)} variant="contained" sx={{ mt: 5, mb: 3, maxWidth: "200px" }}>
|
||||||
⬅ Retour
|
⬅ Retour
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{/* ✅ Titre de l'article */}
|
|
||||||
<Typography
|
<Typography
|
||||||
variant="h1"
|
variant="h1"
|
||||||
sx={{
|
sx={{
|
||||||
@@ -68,7 +63,6 @@ const PostDetails = () => {
|
|||||||
{post.title.rendered}
|
{post.title.rendered}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{/* ✅ Image + Contenu */}
|
|
||||||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "40px 20px", margin: "auto" }}>
|
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "40px 20px", margin: "auto" }}>
|
||||||
{image && (
|
{image && (
|
||||||
<Box
|
<Box
|
||||||
@@ -78,7 +72,18 @@ const PostDetails = () => {
|
|||||||
sx={{ width: "100%", maxHeight: "400px", objectFit: "cover", borderRadius: "8px", mb: 3 }}
|
sx={{ width: "100%", maxHeight: "400px", objectFit: "cover", borderRadius: "8px", mb: 3 }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Typography variant="body1" sx={{ maxWidth: "800px", mx: "auto" }} dangerouslySetInnerHTML={{ __html: post.content.rendered }} />
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
maxWidth: "800px",
|
||||||
|
mx: "auto",
|
||||||
|
"& h2": { color: "#315397", mt: 4, mb: 2 },
|
||||||
|
"& h3": { color: "#315397", mt: 3, mb: 1 },
|
||||||
|
"& h4": { color: "#315397", mt: 2, mb: 1 },
|
||||||
|
"& p": { mb: 2 },
|
||||||
|
}}
|
||||||
|
dangerouslySetInnerHTML={{ __html: post.content.rendered }}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
+4949
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user