From 06184ea166ba088db8dfc810182fc84f11218274 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 9 Dec 2025 22:04:52 -0500 Subject: [PATCH] update frontend --- src/components/Posts/PostCard.jsx | 39 +++++++++++++++++ src/components/Posts/PostList.jsx | 70 +++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/components/Posts/PostCard.jsx create mode 100644 src/components/Posts/PostList.jsx diff --git a/src/components/Posts/PostCard.jsx b/src/components/Posts/PostCard.jsx new file mode 100644 index 0000000..52ca087 --- /dev/null +++ b/src/components/Posts/PostCard.jsx @@ -0,0 +1,39 @@ +import React from "react"; + +function getKmFromPost(post) { + return ( + post.km ?? + post.distance_km ?? + post.distanceKm ?? + post.dist_km ?? + null + ); +} + +export default function PostCard({ post, selected, onSelect }) { + const title = post.title || post.name || "Post"; + + const fullBody = + post.body || post.content || post.text || ""; + + // texte court dans le Sociowall + const body = + fullBody.length > 80 ? fullBody.slice(0, 77) + "..." : fullBody; + + const km = getKmFromPost(post); + + function handleClick() { + if (onSelect) onSelect(post); + } + + return ( +
+

{title}

+

{body}

+ {km != null && {km} km} +
+ ); +} diff --git a/src/components/Posts/PostList.jsx b/src/components/Posts/PostList.jsx new file mode 100644 index 0000000..e7fba56 --- /dev/null +++ b/src/components/Posts/PostList.jsx @@ -0,0 +1,70 @@ +import React, { useState, useMemo } from "react"; +import PostCard from "./PostCard"; + +function getKmFromPost(post) { + return ( + post.km ?? + post.distance_km ?? + post.distanceKm ?? + post.dist_km ?? + null + ); +} + +export default function PostList({ + posts, + loading, + error, + selectedPost, + onSelectPost, +}) { + const [kmFilter, setKmFilter] = useState(1000); + + const filtered = useMemo( + () => + posts.filter((p) => { + const km = getKmFromPost(p); + if (km == null) return true; + return km <= kmFilter; + }), + [posts, kmFilter] + ); + + return ( +
+
+
+ + setKmFilter(Number(e.target.value))} + /> +
+
+ + {loading &&

Chargement...

} + {error &&

{error}

} + + {filtered.map((p) => ( + + ))} + + {!loading && filtered.length === 0 && ( +

Aucun post dans ce rayon.

+ )} +
+ ); +}