@@ -7,12 +7,16 @@ import GridContainer from '@/components/GridContainer';
77import { unstable_noStore as noStore } from 'next/cache' ;
88import Header from '@/components/Header' ;
99
10- const sleep = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
11-
1210export default async function Home ( ) {
1311 noStore ( ) ;
14- await connectDb ( ) ;
15- const recenetProfiles = await RecentProfiles . find ( { } ) . sort ( { updatedAt : 'desc' } ) . limit ( 8 ) ;
12+ let recenetProfiles = [ ] ;
13+
14+ try {
15+ await connectDb ( ) ;
16+ recenetProfiles = await RecentProfiles . find ( { } ) . sort ( { updatedAt : 'desc' } ) . limit ( 8 ) ;
17+ } catch ( error ) {
18+ console . log ( 'An error occurred in Home Page while fetching recent profiles' ) ;
19+ }
1620
1721 const formAction = async formData => {
1822 'use server' ;
@@ -25,7 +29,7 @@ export default async function Home() {
2529 < Header />
2630
2731 < main className = "px-4" >
28- < div className = "mx-auto max-w-screen-md text-center pt-[10vh]" >
32+ < div className = "mx-auto max-w-screen-md pt-[10vh] text-center " >
2933 < h1 className = "text-gradient text-4xl font-bold md:text-7xl" > Git Glance</ h1 >
3034 < p className = "text-gradient mb-16 mt-2 text-xl font-medium md:text-3xl " >
3135 Visualize Your GitHub Profile
@@ -34,57 +38,36 @@ export default async function Home() {
3438 < SearchBox formAction = { formAction } />
3539 </ div >
3640
37- { /* <div className="mx-auto mt-28 max-w-screen-xl text-left md:mt-40">
38- <h2 className="text-gradient text-xl font-semibold md:text-3xl">Recent Profiles</h2>
39-
40- <div className="mt-4 grid grid-cols-1 gap-4 md:grid-cols-4">
41- {recenetProfiles.map(profile => (
42- <Link
43- key={profile._id}
44- href={`/${profile.username}`}
45- className="box grid grid-cols-[3rem_1fr] items-center gap-5 text-left"
41+ { recenetProfiles . length > 0 && (
42+ < div className = "mx-auto mt-32 max-w-screen-xl md:mt-36" >
43+ < GridContainer
44+ className = { 'grid-cols-1 gap-3 md:grid-cols-4' }
45+ name = { 'Recent Profiles' }
46+ description = { 'Profiles that have been viewed recently' }
4647 >
47- <img
48- src={profile.avatarUrl}
49- // src="https://github.com/devxprite.png"
50- alt={profile.username}
51- className="mx-auto size-12 rounded-full"
52- />
53- <div>
54- <p className="text-base font-semibold md:text-lg">{profile.name ?? profile.username}</p>
55- <p className="text-sm text-gray-400 md:text-base">@{profile.username}</p>
56- </div>
57- </Link>
58- ))}
59- </div>
60- </div> */ }
61- < div className = "mx-auto mt-32 max-w-screen-xl md:mt-36" >
62- < GridContainer
63- className = { 'grid-cols-1 gap-3 md:grid-cols-4' }
64- name = { 'Recent Profiles' }
65- description = { 'Profiles that have been viewed recently' }
66- >
67- { recenetProfiles . map ( profile => (
68- < Link
69- key = { profile . _id }
70- href = { `/${ profile . username } ` }
71- className = "box flex items-center gap-3 text-left md:gap-5"
72- >
73- < img
74- src = { profile . avatarUrl }
75- alt = { profile . username }
76- className = "size-10 grow-0 rounded-full md:size-12"
77- />
78- < div >
79- < p className = "text-base font-semibold md:text-lg" >
80- { profile . name ?? profile . username }
81- </ p >
82- < p className = "-mt-1 text-sm text-gray-400 md:text-base" > @{ profile . username } </ p >
83- </ div >
84- </ Link >
85- ) ) }
86- </ GridContainer >
87- </ div >
48+ { recenetProfiles . map ( profile => (
49+ < Link
50+ key = { profile . _id }
51+ href = { `/${ profile . username } ` }
52+ prefetch = { false }
53+ className = "box flex items-center gap-3 text-left md:gap-5"
54+ >
55+ < img
56+ src = { profile . avatarUrl }
57+ alt = { profile . username }
58+ className = "size-10 grow-0 rounded-full md:size-12"
59+ />
60+ < div >
61+ < p className = "text-base font-semibold md:text-lg" >
62+ { profile . name ?? profile . username }
63+ </ p >
64+ < p className = "-mt-1 text-sm text-gray-400 md:text-base" > @{ profile . username } </ p >
65+ </ div >
66+ </ Link >
67+ ) ) }
68+ </ GridContainer >
69+ </ div >
70+ ) }
8871 </ main >
8972 </ >
9073 ) ;
0 commit comments