@@ -10,13 +10,14 @@ import {
10
10
Trash ,
11
11
UserCircle ,
12
12
Users ,
13
+ X ,
13
14
} from 'phosphor-react'
14
15
import * as React from 'react'
15
16
import { HomePageFeedUpdateType } from 'src/pages'
16
17
import { DateTime } from 'luxon'
17
18
import { useMutation , useQuery , useQueryClient } from 'react-query'
18
19
import classNames from 'classnames'
19
- import { useState , useRef } from 'react'
20
+ import { useState , useRef , useEffect } from 'react'
20
21
import { signIn , useSession } from 'next-auth/client'
21
22
import { User } from 'src/pages/members'
22
23
import useFollowUser from './profile/useFollowUser'
@@ -332,6 +333,7 @@ export default function HomePageFeed({
332
333
} ) {
333
334
const [ session , loading ] = useSession ( )
334
335
const [ goalId , setgoalId ] = useState ( '' )
336
+ const [ isGoalPreviewOpen , setIsGoalPreviewOpen ] = useState ( false )
335
337
return (
336
338
< div className = "min-h-screen bg-gray-100 flex flex-col" >
337
339
< header className = "bg-white shadow-sm sticky top-0 z-10" >
@@ -379,15 +381,22 @@ export default function HomePageFeed({
379
381
< HomePageFeedUpdate
380
382
update = { update }
381
383
key = { update . id }
382
- setGoalId = { ( ) => setgoalId ( update . goal . id ) }
384
+ setGoalId = { ( ) => {
385
+ setIsGoalPreviewOpen ( true )
386
+ setgoalId ( update . goal . id )
387
+ } }
383
388
/>
384
389
) ) }
385
390
</ ul >
386
391
</ div >
387
392
</ div >
388
393
</ main >
389
394
< aside className = "hidden lg:block lg:col-span-5 xl:col-span-4" >
390
- < HomePageAside goalId = { goalId } />
395
+ < HomePageAside
396
+ goalId = { goalId }
397
+ isGoalPreviewOpen = { isGoalPreviewOpen }
398
+ setIsGoalPreviewOpen = { setIsGoalPreviewOpen }
399
+ />
391
400
</ aside >
392
401
</ div >
393
402
</ div >
@@ -534,8 +543,15 @@ function FollowButton({ user }: { user: User }) {
534
543
)
535
544
}
536
545
537
- function HomePageAside ( { goalId } : { goalId : string } ) {
538
- const [ session ] = useSession ( )
546
+ function GoalPreview ( {
547
+ goalId,
548
+ isOpen,
549
+ setIsOpen,
550
+ } : {
551
+ goalId : string
552
+ isOpen : boolean
553
+ setIsOpen : ( open : boolean ) => void
554
+ } ) {
539
555
const { isLoading, isError, data } = useQuery < { response : GoalResponse } > (
540
556
[ '/api/fauna/recent-updates' , goalId ] ,
541
557
( ) => {
@@ -558,6 +574,93 @@ function HomePageAside({ goalId }: { goalId: string }) {
558
574
} )
559
575
}
560
576
)
577
+ const shouldShowRecentUpdates =
578
+ Boolean ( goalId ) && goalId !== '' && ! isLoading && ! isError
579
+
580
+ const goal : GoalResponse = data ?. response
581
+
582
+ if ( ! isOpen ) {
583
+ return < > </ >
584
+ }
585
+ return (
586
+ < section
587
+ aria-labelledby = "trending-heading"
588
+ className = "max-h-150 overflow-y-auto"
589
+ >
590
+ < div className = "bg-white rounded-lg shadow" >
591
+ < div className = "absolute top-0 right-0 pt-4 pr-4" >
592
+ < button
593
+ type = "button"
594
+ className = "bg-white rounded-md text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
595
+ onClick = { ( ) => setIsOpen ( false ) }
596
+ >
597
+ < span className = "sr-only" > Close</ span >
598
+ < svg
599
+ className = "h-6 w-6"
600
+ xmlns = "http://www.w3.org/2000/svg"
601
+ fill = "none"
602
+ viewBox = "0 0 24 24"
603
+ stroke = "currentColor"
604
+ aria-hidden = "true"
605
+ >
606
+ < path
607
+ strokeLinecap = "round"
608
+ strokeLinejoin = "round"
609
+ strokeWidth = "2"
610
+ d = "M6 18L18 6M6 6l12 12"
611
+ />
612
+ </ svg >
613
+ </ button >
614
+ </ div >
615
+ < div className = "p-6" >
616
+ { isLoading && < p > loading...</ p > }
617
+ { isError && < p > Something went wrong!!!</ p > }
618
+ { shouldShowRecentUpdates && (
619
+ < >
620
+ < Goal . Title createdBy = { goal . createdBy } showEditButton = { false } >
621
+ { goal . title }
622
+ </ Goal . Title >
623
+ < Goal . Description > { goal . description } </ Goal . Description >
624
+ < Goal . Updates >
625
+ < Goal . UpdatesList >
626
+ { goal . updates . data . map ( ( update , index ) => (
627
+ < Goal . Update
628
+ postedBy = { update . postedBy }
629
+ key = { update . id }
630
+ postedOn = { DateTime . fromMillis ( update . createdAt ) }
631
+ isLastUpdate = { index === goal . updates . data . length - 1 }
632
+ >
633
+ { update . description }
634
+ </ Goal . Update >
635
+ ) ) }
636
+ </ Goal . UpdatesList >
637
+ </ Goal . Updates >
638
+ < div className = "mt-6" >
639
+ < A
640
+ href = { `/${ goal . createdBy . username } ` }
641
+ 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"
642
+ >
643
+ View more details
644
+ </ A >
645
+ </ div >
646
+ </ >
647
+ ) }
648
+ </ div >
649
+ </ div >
650
+ </ section >
651
+ )
652
+ }
653
+
654
+ function HomePageAside ( {
655
+ isGoalPreviewOpen,
656
+ setIsGoalPreviewOpen,
657
+ goalId,
658
+ } : {
659
+ goalId : string
660
+ isGoalPreviewOpen : boolean
661
+ setIsGoalPreviewOpen : ( open : boolean ) => void
662
+ } ) {
663
+ const [ session ] = useSession ( )
561
664
const {
562
665
isLoading : isWhoToFollowLoading ,
563
666
isError : isWhoToFollowError ,
@@ -566,61 +669,15 @@ function HomePageAside({ goalId }: { goalId: string }) {
566
669
return fetch ( `/api/fauna/who-to-follow` ) . then ( ( res ) => res . json ( ) )
567
670
} )
568
671
569
- const shouldShowRecentUpdates =
570
- Boolean ( goalId ) && goalId !== '' && ! isLoading && ! isError
571
- const goal : GoalResponse = data ?. response
572
-
573
672
return (
574
673
< >
575
674
< div className = "sticky top-20 space-y-4" >
576
- { Boolean ( goalId ) && (
577
- < section
578
- aria-labelledby = "trending-heading"
579
- className = "max-h-150 overflow-y-auto"
580
- >
581
- < div className = "bg-white rounded-lg shadow" >
582
- < div className = "p-6" >
583
- { isLoading && < p > loading...</ p > }
584
- { isError && < p > Something went wrong!!!</ p > }
585
- { shouldShowRecentUpdates && (
586
- < >
587
- < Goal . Title
588
- createdBy = { goal . createdBy }
589
- showEditButton = { false }
590
- >
591
- { goal . title }
592
- </ Goal . Title >
593
- < Goal . Description > { goal . description } </ Goal . Description >
594
- < Goal . Updates >
595
- < Goal . UpdatesList >
596
- { goal . updates . data . map ( ( update , index ) => (
597
- < Goal . Update
598
- postedBy = { update . postedBy }
599
- key = { update . id }
600
- postedOn = { DateTime . fromMillis ( update . createdAt ) }
601
- isLastUpdate = {
602
- index === goal . updates . data . length - 1
603
- }
604
- >
605
- { update . description }
606
- </ Goal . Update >
607
- ) ) }
608
- </ Goal . UpdatesList >
609
- </ Goal . Updates >
610
- < div className = "mt-6" >
611
- < A
612
- href = { `/${ goal . createdBy . username } ` }
613
- 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"
614
- >
615
- View more details
616
- </ A >
617
- </ div >
618
- </ >
619
- ) }
620
- </ div >
621
- </ div >
622
- </ section >
623
- ) }
675
+ < GoalPreview
676
+ isOpen = { isGoalPreviewOpen }
677
+ setIsOpen = { setIsGoalPreviewOpen }
678
+ goalId = { goalId }
679
+ />
680
+
624
681
{ ! isWhoToFollowLoading &&
625
682
! isWhoToFollowError &&
626
683
whoToFollowResponse . users . length > 0 && (
0 commit comments