@@ -54,8 +54,10 @@ function reducer(state: LikeData, action: { type: string; payload?: any }) {
54
54
55
55
export function HomePageFeedUpdate ( {
56
56
update,
57
+ setGoalId,
57
58
} : {
58
59
update : HomePageFeedUpdateType
60
+ setGoalId : ( ) => void
59
61
} ) {
60
62
const [ session , loading ] = useSession ( )
61
63
const [ showComments , setShowComments ] = useState ( false )
@@ -130,11 +132,11 @@ export function HomePageFeedUpdate({
130
132
</ div >
131
133
</ div >
132
134
< div className = "mt-4 flex" >
133
- < A href = { ` ${ postedBy . username } ` } >
135
+ < button onClick = { ( ) => setGoalId ( ) } >
134
136
< span className = "inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-brand-100 text-brand-800 hover:text-brand-600" >
135
137
🚀 Goal: { goal . title }
136
138
</ span >
137
- </ A >
139
+ </ button >
138
140
</ div >
139
141
</ div >
140
142
< div className = "mt-2 text-sm text-gray-700 space-y-4" >
@@ -225,6 +227,7 @@ export default function HomePageFeed({
225
227
showGoal : boolean
226
228
} ) {
227
229
const [ session , loading ] = useSession ( )
230
+ const [ goalId , setgoalId ] = useState ( '' )
228
231
return (
229
232
< div className = "min-h-screen bg-gray-100 flex flex-col" >
230
233
< header className = "bg-white shadow-sm sticky top-0 z-10" >
@@ -233,10 +236,10 @@ export default function HomePageFeed({
233
236
{ ! loading && ! session && < Hero /> }
234
237
< div className = "py-10 flex-1" >
235
238
< div className = "max-w-3xl mx-auto sm:px-6 lg:max-w-7xl lg:px-8 lg:grid lg:grid-cols-12 lg:gap-8" >
236
- < div className = "hidden lg :block lg:col-span-3 xl:col-span-2" >
239
+ < div className = "hidden xl :block xl:col-span-2" >
237
240
< HomePageSideNavBar />
238
241
</ div >
239
- < main className = "lg:col-span-9 xl:col-span-6 px-2" >
242
+ < main className = "lg:col-span-7 xl:col-span-6 px-2" >
240
243
< div className = "space-y-3" >
241
244
{ showGoal ? (
242
245
< div className = "bg-white px-4 py-6 shadow sm:p-6 sm:rounded-lg" >
@@ -270,13 +273,19 @@ export default function HomePageFeed({
270
273
< h1 className = "sr-only" > Recent questions</ h1 >
271
274
< ul className = "space-y-4" >
272
275
{ updates . map ( ( update : HomePageFeedUpdateType ) => (
273
- < HomePageFeedUpdate update = { update } key = { update . id } />
276
+ < HomePageFeedUpdate
277
+ update = { update }
278
+ key = { update . id }
279
+ setGoalId = { ( ) => setgoalId ( update . goal . id ) }
280
+ />
274
281
) ) }
275
282
</ ul >
276
283
</ div >
277
284
</ div >
278
285
</ main >
279
- < HomePageAside updates = { updates . slice ( 0 , 3 ) } />
286
+ < aside className = "hidden lg:block lg:col-span-5 xl:col-span-4" >
287
+ < HomePageAside goalId = { goalId } />
288
+ </ aside >
280
289
</ div >
281
290
</ div >
282
291
@@ -406,62 +415,75 @@ function FollowButton({ user }: { user: User }) {
406
415
)
407
416
}
408
417
409
- function HomePageAside ( { updates } : { updates : HomePageFeedUpdateType [ ] } ) {
418
+ function HomePageAside ( { goalId } : { goalId : string } ) {
410
419
const [ session ] = useSession ( )
411
420
const { isLoading, isError, data : response } = useQuery (
412
- 'api/fauna/who-to-follow' ,
413
- ( ) => {
414
- return fetch ( `/api/fauna/who-to-follow` ) . then ( ( res ) => res . json ( ) )
415
- }
421
+ [ '/api/fauna/recent-updates' , goalId ] ,
422
+ ( ) =>
423
+ fetch ( `/api/fauna/recent-updates` , {
424
+ method : 'POST' ,
425
+ headers : {
426
+ 'Content-Type' : 'application/json' ,
427
+ } ,
428
+ body : JSON . stringify ( {
429
+ goalId,
430
+ } ) ,
431
+ } ) . then ( ( res ) => {
432
+ if ( ! res . ok ) {
433
+ throw new Error ( 'Something went wrong!!' )
434
+ }
435
+ return res . json ( )
436
+ } )
416
437
)
438
+ const {
439
+ isLoading : isWhoToFollowLoading ,
440
+ isError : isWhoToFollowError ,
441
+ data : whoToFollowResponse ,
442
+ } = useQuery ( 'api/fauna/who-to-follow' , ( ) => {
443
+ return fetch ( `/api/fauna/who-to-follow` ) . then ( ( res ) => res . json ( ) )
444
+ } )
445
+
446
+ const shouldShowRecentUpdates = Boolean ( goalId ) && goalId !== ''
417
447
418
448
return (
419
449
< >
420
- < aside className = "hidden xl:block xl:col-span -4" >
421
- < div className = "sticky top-4 space-y-4" >
450
+ < div className = "sticky top-4 space-y -4" >
451
+ { shouldShowRecentUpdates && (
422
452
< section aria-labelledby = "trending-heading" >
423
453
< div className = "bg-white rounded-lg shadow" >
424
454
< div className = "p-6" >
425
455
< h2
426
456
id = "trending-heading"
427
457
className = "text-base font-medium text-gray-900"
428
458
>
429
- Recent Updates
459
+ All Updates
430
460
</ h2 >
431
461
< div className = "mt-6 flow-root" >
432
462
< ul className = "-my-4 divide-y divide-gray-200" >
433
- { updates . map ( ( update ) => (
434
- < li className = "flex py-4 space-x-3" key = { update . id } >
435
- < div className = "flex-shrink-0" >
436
- < img
437
- className = "h-8 w-8 rounded-full"
438
- src = { update . postedBy . image }
439
- alt = ""
440
- />
441
- </ div >
442
- < div className = "min-w-0 flex-1" >
443
- < div className = "prose prose-sm max-w-none" >
444
- < Markdown > { update . description } </ Markdown >
463
+ { ! isLoading &&
464
+ ! isError &&
465
+ response . updates . map ( ( update ) => (
466
+ < li className = "flex py-4 space-x-3" key = { update . id } >
467
+ < div className = "flex-shrink-0" >
468
+ < img
469
+ className = "h-8 w-8 rounded-full"
470
+ src = { update . postedBy . image }
471
+ alt = ""
472
+ />
445
473
</ div >
446
- < div className = "mt-2 flex" >
447
- < span className = "inline-flex items-center text-sm" >
448
- < button className = "inline-flex space-x-2 text-gray-400 hover:text-gray-500" >
449
- < ChatCenteredDots className = "h-5 w-5" />
450
- < span className = "font-medium text-gray-900" >
451
- { update . comments . data . length }
452
- </ span >
453
- </ button >
454
- </ span >
474
+ < div className = "min-w-0 flex-1" >
475
+ < div className = "prose prose-sm max-w-none" >
476
+ < Markdown > { update . description } </ Markdown >
477
+ </ div >
455
478
</ div >
456
- </ div >
457
- </ li >
458
- ) ) }
479
+ </ li >
480
+ ) ) }
459
481
</ ul >
460
482
</ div >
461
483
{ session ? (
462
484
< div className = "mt-6" >
463
485
< A
464
- href = { `/${ ( session . user as User ) . username } ` }
486
+ href = { `/${ response ?. updates ?. [ 0 ] . postedBy . username } ` }
465
487
className = "w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
466
488
>
467
489
View all
@@ -480,47 +502,47 @@ function HomePageAside({ updates }: { updates: HomePageFeedUpdateType[] }) {
480
502
</ div >
481
503
</ div >
482
504
</ section >
505
+ ) }
483
506
484
- < section aria-labelledby = "who-to-follow-heading" >
485
- < div className = "bg-white rounded-lg shadow" >
486
- < div className = "p-6" >
487
- < h2
488
- id = "who-to-follow-heading"
489
- className = "text-base font-medium text-gray-900"
490
- >
491
- Who to follow
492
- </ h2 >
493
- < div className = "mt-6 flow-root" >
494
- < ul className = "-my-4 divide-y divide-gray-200" >
495
- { ! isLoading &&
496
- ! isError &&
497
- response . users . map ( ( user : User ) => (
498
- < FollowButton user = { user } key = { user . id } />
499
- ) ) }
500
- </ ul >
501
- </ div >
502
- < div className = "mt-6" >
503
- { session ? (
504
- < A
505
- href = "/members"
506
- className = "w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
507
- >
508
- View all
509
- </ A >
510
- ) : (
511
- < button
512
- onClick = { ( ) => signIn ( 'github' ) }
513
- className = "w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
514
- >
515
- Join
516
- </ button >
517
- ) }
518
- </ div >
507
+ < section aria-labelledby = "who-to-follow-heading" >
508
+ < div className = "bg-white rounded-lg shadow" >
509
+ < div className = "p-6" >
510
+ < h2
511
+ id = "who-to-follow-heading"
512
+ className = "text-base font-medium text-gray-900"
513
+ >
514
+ Who to follow
515
+ </ h2 >
516
+ < div className = "mt-6 flow-root" >
517
+ < ul className = "-my-4 divide-y divide-gray-200" >
518
+ { ! isWhoToFollowLoading &&
519
+ ! isWhoToFollowError &&
520
+ whoToFollowResponse . users . map ( ( user : User ) => (
521
+ < FollowButton user = { user } key = { user . id } />
522
+ ) ) }
523
+ </ ul >
524
+ </ div >
525
+ < div className = "mt-6" >
526
+ { session ? (
527
+ < A
528
+ href = "/members"
529
+ className = "w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
530
+ >
531
+ View all
532
+ </ A >
533
+ ) : (
534
+ < button
535
+ onClick = { ( ) => signIn ( 'github' ) }
536
+ className = "w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
537
+ >
538
+ Join
539
+ </ button >
540
+ ) }
519
541
</ div >
520
542
</ div >
521
- </ section >
522
- </ div >
523
- </ aside >
543
+ </ div >
544
+ </ section >
545
+ </ div >
524
546
</ >
525
547
)
526
548
}
0 commit comments