From 3d827f47072e523f868b63c7081dd5738fb23a23 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 18 Oct 2025 04:40:13 +0000 Subject: [PATCH] Add like/comment handlers to Feed and wire FeedItemCard props cgen-0044c75cff994810aa9f40ce114c2c2e --- client/pages/Feed.tsx | 57 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/client/pages/Feed.tsx b/client/pages/Feed.tsx index 666b1698..9d2f59a7 100644 --- a/client/pages/Feed.tsx +++ b/client/pages/Feed.tsx @@ -3,6 +3,7 @@ import Layout from "@/components/Layout"; import LoadingScreen from "@/components/LoadingScreen"; import PostComposer from "@/components/social/PostComposer"; import { FeedItemCard } from "@/components/social/FeedItemCard"; +import { communityService } from "@/lib/supabase-service"; import { ensureDemoSeed, getDemoPosts } from "@/lib/demo-feed"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; @@ -218,9 +219,13 @@ export default function Feed() { text: "Check out this post on AeThex", url, }); - } else { - await navigator.clipboard.writeText(url); - toast({ description: "Link copied to clipboard" }); + } else if (typeof window !== "undefined") { + const intent = `https://twitter.com/intent/tweet?text=${encodeURIComponent( + "Check out this post on AeThex", + )}&url=${encodeURIComponent(url)}`; + window.open(intent, "_blank", "noopener,noreferrer"); + await navigator.clipboard.writeText(url).catch(() => undefined); + toast({ description: "Share link opened (copied to clipboard)" }); } } catch (error) { console.warn("Share cancelled", error); @@ -229,6 +234,50 @@ export default function Feed() { [toast], ); + const handleLike = useCallback( + async (postId: string) => { + if (!user?.id) { + toast({ description: "Please sign in to like posts." }); + return; + } + try { + const newCount = await communityService.likePost(postId, user.id); + setItems((prev) => + prev.map((it) => + it.id === postId && typeof newCount === "number" + ? { ...it, likes: newCount } + : it, + ), + ); + } catch (e) { + console.warn("Like failed", e); + } + }, + [toast, user?.id], + ); + + const handleComment = useCallback( + async (postId: string) => { + if (!user?.id) { + toast({ description: "Please sign in to comment." }); + return; + } + const content = prompt("Add a comment:")?.trim(); + if (!content) return; + try { + const created = await communityService.addComment(postId, user.id, content); + if (created) { + setItems((prev) => + prev.map((it) => (it.id === postId ? { ...it, comments: it.comments + 1 } : it)), + ); + } + } catch (e) { + console.warn("Comment failed", e); + } + }, + [toast, user?.id], + ); + const filteredItems = useMemo(() => { if (activeFilter === "following") { return items.filter( @@ -475,6 +524,8 @@ export default function Feed() { isFollowing={isFollowingAuthor(item.authorId)} onToggleFollow={toggleFollow} onShare={handleShare} + onLike={handleLike} + onComment={handleComment} /> ))}