"use client"; import { useDevice } from "@/lib/context/DeviceContext"; import React, { useEffect, useState } from "react"; import Post from "../../lib/components/Post"; function Mobile() { const { isAuthenticated, session } = useDevice(); const [friendsPostsData, setFriendsPosts] = useState([]); function getFriendsPosts(friendId: any) { fetch(`/api/user/${friendId}/posts`) .then((res) => res.json()) .then((data) => { if (data.posts) { setFriendsPosts([...friendsPostsData, ...data.posts]); } else { console.error("No posts found for friend ID:", friendId); } }) .catch((err) => { console.error("Error fetching friend's posts:", err); }); } // Fetch friends' posts useEffect(() => { if (isAuthenticated && session) { let friendsIds = session.friends.map((friend: any) => friend); console.log("Friends IDs:", friendsIds); // use /api/users/:id to get friend data friendsIds.forEach((friendId: any) => { fetch(`/api/user/${friendId}`) .then((res) => res.json()) .then((data) => { if (data.user) { getFriendsPosts(data.user.id); } else { console.error("No user data found for friend ID:", friendId); } }) .catch((err) => { console.error("Error fetching friend data:", err); }); }); } }, [isAuthenticated, session]); return (
Drink Happy Logo Image

{isAuthenticated ? `Welcome, ${session.username} !!` : ""}

{!isAuthenticated ? (
) : (

Activity Feed

{friendsPostsData.map((post, index) => ( console.log("Liked post:", post.id)} onWarning={() => console.log("Warned post:", post.id)} onDelete={() => {}} // No delete option for friends' posts /> ))}
)}
); } function Web() { const { isAuthenticated, session } = useDevice(); return (
Drink Happy Logo Image

{isAuthenticated ? `Welcome, ${session.username} !!` : ""}

); } export default function Home() { const { isMobile, isSafari } = useDevice(); if (isMobile && isSafari) return Mobile(); else return Mobile(); }