import React, { useEffect, useState } from 'react'; import { Container, Box, Typography, Button, Grid, Card, CardMedia, CardContent, CardActions, Chip, Rating, Dialog, DialogTitle, DialogContent, DialogActions, IconButton, Divider } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import AutoFixHighIcon from '@mui/icons-material/AutoFixHigh'; import CommentIcon from '@mui/icons-material/Comment'; import StarIcon from '@mui/icons-material/Star'; import HardwareIcon from '@mui/icons-material/Memory'; import ListIcon from '@mui/icons-material/List'; // Icon for "Show All" // --- PLACEHOLDER ASSETS --- const PLACEHOLDER_IMG = "https://placehold.co/600x400?text=Gaming+PC"; import { onGetHighestRankedBuilds, onCloneBuild } from './buildCards.telefunc'; import { onGetApprovedBuilds } from '../+Layout.telefunc'; import {getAuthState} from "../../server/telefunc/ctx"; // export default function HomePage() { const [data, setData] = useState(null); const [selectedBuild, setSelectedBuild] = useState(null); // For Detail Popup const [openDetailPopup, setOpenDetailPopup] = useState(false); // NEW: Popup for "All Top Ranked Builds" const [openRankedPopup, setOpenRankedPopup] = useState(false); useEffect(() => { async function loadSite(){ try{ const [ authData, highestRankedBuilds, commnityBuilds ] = await Promise.all([ getAuthState(), onGetHighestRankedBuilds({ limit: 3 }), onGetApprovedBuilds({ limit: 12 }) ]); setData({ isLoggedIn: authData.isLoggedIn, userId: authData.userId, prebuilts: highestRankedBuilds, communityBuilds: commnityBuilds }); } catch (error) { console.error("Error loading homepage data:", error); } } loadSite(); }, []); // Open Build Details const handleCardClick = (build: any) => { setSelectedBuild(build); setOpenDetailPopup(true); }; const handleClone = async () => { if (!data?.isLoggedIn) return alert("Please login to clone builds!"); if (confirm(`Clone "${selectedBuild.name}" to your dashboard?`)) { await onCloneBuild({ buildId: selectedBuild.id }); alert("Build cloned! Check your dashboard."); setOpenDetailPopup(false); } }; if (!data) return Loading Forge...; return ( Forge Your Ultimate Machine Build, share, discuss, and discover custom PC configurations. Join the community today. Hall of Fame The highest rated configurations from across the community. The Elite These 3 builds represent the pinnacle of performance and looks as voted by the PC Forge community. {data.prebuilts.map((build: any) => ( handleCardClick(build)} /> ))} {data.communityBuilds.map((build: any) => ( handleCardClick(build)} /> ))} setOpenDetailPopup(false)} maxWidth="md" fullWidth> {selectedBuild && ( <> {selectedBuild.name} By {selectedBuild.username || "Unknown"} setOpenDetailPopup(false)}> ({selectedBuild.ratingCount || 0} reviews) Build Specs {/* Placeholder */} {/* Placeholder */} Actions {data.userId === selectedBuild.userId ? ( ) : ( )} )} setOpenRankedPopup(false)} maxWidth="lg" fullWidth> Hall of Fame (All Top Ranked) setOpenRankedPopup(false)}> {data.prebuilts.concat(data.communityBuilds).map((build: any) => ( { setOpenRankedPopup(false); handleCardClick(build); }} /> ))} ); } function SectionHeader({ title, subtitle }: { title: string, subtitle: string }) { return ( {title} {subtitle} ); } function BuildCard({ build, onClick }: { build: any, onClick: () => void }) { return ( {build.name} {Number(build.avgRating || 0).toFixed(1)} {build.commentCount || 0} reviews ); } function ComponentRow({ name, value }: { name: string, value: string }) { return ( {name} {value} ); }