From 814d5c1f1e4a6ff263dc32915863581c3a236102 Mon Sep 17 00:00:00 2001 From: GamerBoss101 Date: Sun, 13 Apr 2025 07:43:11 -0400 Subject: [PATCH] Update App --- src/app/(app)/page.tsx | 65 ++++++++++++++++++++++++++-- src/app/(app)/posts/page.tsx | 1 - src/app/api/user/[id]/posts/route.ts | 42 ++++++++++++++++++ src/app/manifest.ts | 40 +++++++++-------- src/app/metadata.ts | 25 ++++++++++- src/lib/components/Post.tsx | 53 +++++++++++------------ 6 files changed, 174 insertions(+), 52 deletions(-) create mode 100644 src/app/api/user/[id]/posts/route.ts diff --git a/src/app/(app)/page.tsx b/src/app/(app)/page.tsx index 6db7566..f4142ff 100644 --- a/src/app/(app)/page.tsx +++ b/src/app/(app)/page.tsx @@ -1,9 +1,50 @@ "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/users/${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?.friends) { + let friendsIds = session.friends.map((friend: any) => friend.id); + + // use /api/users/:id to get friend data + friendsIds.forEach((friendId: any) => { + fetch(`/api/users/${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?.friends]); return (
@@ -24,7 +65,25 @@ function Mobile() { Log in - ) : null} + ) : ( +
+

+ 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 + /> + ))} +
+
+ )}
); } @@ -48,6 +107,6 @@ function Web() { export default function Home() { const { isMobile, isSafari } = useDevice(); - if (isMobile && isSafari) return Mobile(); - else return Web(); + if (isMobile && isSafari) return ; + else return ; } diff --git a/src/app/(app)/posts/page.tsx b/src/app/(app)/posts/page.tsx index 056129d..c1777c4 100644 --- a/src/app/(app)/posts/page.tsx +++ b/src/app/(app)/posts/page.tsx @@ -201,7 +201,6 @@ export default function PostsPage() { allowReactions={false} key={index} post={post} - userReactions={userReactions[index] || { liked: false, warned: false }} onLike={() => handleLike(index)} onWarning={() => handleWarning(index)} onDelete={() => handleDelete(index)} // Pass the delete handler diff --git a/src/app/api/user/[id]/posts/route.ts b/src/app/api/user/[id]/posts/route.ts new file mode 100644 index 0000000..e4639ac --- /dev/null +++ b/src/app/api/user/[id]/posts/route.ts @@ -0,0 +1,42 @@ +import { NextResponse } from "next/server"; +import { auth0 } from "../../../../../lib/scripts/auth0"; +import { db } from "@/lib/scripts/db"; + +async function authenticateUser() { + const session = await auth0.getSession(); + + if (!session) { + return NextResponse.json({ message: "No session found" }, { status: 401 }); + } + + const sessionUser = session.user; + let userData = await db.users.findByEmail(sessionUser.email as string); + if (!userData) return NextResponse.json({ message: "User not found" }, { status: 404 }); + + return userData != null; +} + +export async function GET(req: Request, { params }: any) { + try { + if (!(await authenticateUser())) return; + + const { id } = params; + + // Find the user by ID + const user = await db.users.findById(id); + if (!user) { + return NextResponse.json({ message: "User not found" }, { status: 404 }); + } + + // Fetch all posts for the user + const posts = await db.posts.getAllByUserId(id); + if (!posts || posts.length === 0) { + return NextResponse.json({ message: "No posts found for this user" }, { status: 404 }); + } + + return NextResponse.json({ posts }, { status: 200 }); + } catch (error) { + console.error("Error fetching user posts:", error); + return NextResponse.json({ message: "Internal server error" }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/manifest.ts b/src/app/manifest.ts index 7d8dfe4..6e8eb13 100644 --- a/src/app/manifest.ts +++ b/src/app/manifest.ts @@ -1,23 +1,25 @@ import type { MetadataRoute } from "next"; - - export default function manifest(): MetadataRoute.Manifest { - return { - name: "Healthify", - short_name: "Healthify", - description: - "Healthy APP", - start_url: "/", - display: "standalone", - background_color: "#000000", - theme_color: "#000000", - icons: [ - { - src: "/vercel.svg", - sizes: "192x192", - type: "image/svg", - }, - ], - }; + return { + name: "Drink Happy", + short_name: "Drink Happy", + description: "Track your drinks, earn points, and improve your health with Drink Happy!", + start_url: "/", + display: "standalone", + background_color: "#1E293B", // Matches the app's dark theme + theme_color: "#1E293B", // Matches the app's dark theme + icons: [ + { + src: "/cappylogosmall.png", + sizes: "192x192", + type: "image/png", + }, + { + src: "/cappylogosmall.png", + sizes: "512x512", + type: "image/png", + }, + ], + }; } diff --git a/src/app/metadata.ts b/src/app/metadata.ts index 70d30af..95b6438 100644 --- a/src/app/metadata.ts +++ b/src/app/metadata.ts @@ -1,6 +1,27 @@ import type { Metadata } from "next"; export const metadata: Metadata = { - title: "Drinkify", - description: "Drinkify health check app / game", + title: "Drink Happy - Health Check & Game", + description: "Drink Happy is a fun and engaging app to track your drink choices, earn points, and improve your health!", + keywords: ["Drink Happy", "Health", "Game", "Drink Tracker", "Healthy Lifestyle"], + themeColor: "#1E293B", // Matches the app's dark theme + appleWebApp: { + title: "Drink Happy", + statusBarStyle: "black-translucent", + capable: true, + }, + manifest: "/manifest.json", + openGraph: { + title: "Drink Happy - Health Check & Game", + description: "Drink Happy is a fun and engaging app to track your drink choices, earn points, and improve your health!", + siteName: "Drink Happy", + images: [ + { + url: "/cappylogosmall.png", + width: 512, + height: 512, + alt: "Drink Happy Logo", + }, + ], + }, }; \ No newline at end of file diff --git a/src/lib/components/Post.tsx b/src/lib/components/Post.tsx index 313e9f6..222eec2 100644 --- a/src/lib/components/Post.tsx +++ b/src/lib/components/Post.tsx @@ -14,7 +14,6 @@ interface PostProps { onLike: () => void; onWarning: () => void; onDelete: () => void; // Callback for deleting the post - userReactions: { liked: boolean; warned: boolean }; allowReactions: boolean; // New property to toggle reactions } @@ -23,10 +22,12 @@ export default function Post({ onLike, onWarning, onDelete, - userReactions, allowReactions, }: PostProps) { - const [userData, setUserData] = useState<{ username: string; avatar: number } | null>({username: "Loading...", avatar: 1}); + const [userData, setUserData] = useState<{ username: string; avatar: number } | null>({ + username: "Loading...", + avatar: 1, + }); useEffect(() => { // Fetch the username and avatar based on the userId @@ -89,30 +90,28 @@ export default function Post({ {/* Post Actions */}
- {allowReactions && ( - <> - - - - )} + +