Skip to content

Commit bc9415f

Browse files
committed
Add a dismiss button to the goal preview pane
1 parent dd66a92 commit bc9415f

File tree

1 file changed

+114
-57
lines changed

1 file changed

+114
-57
lines changed

src/components/HomePageFeed.tsx

Lines changed: 114 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import {
1010
Trash,
1111
UserCircle,
1212
Users,
13+
X,
1314
} from 'phosphor-react'
1415
import * as React from 'react'
1516
import { HomePageFeedUpdateType } from 'src/pages'
1617
import { DateTime } from 'luxon'
1718
import { useMutation, useQuery, useQueryClient } from 'react-query'
1819
import classNames from 'classnames'
19-
import { useState, useRef } from 'react'
20+
import { useState, useRef, useEffect } from 'react'
2021
import { signIn, useSession } from 'next-auth/client'
2122
import { User } from 'src/pages/members'
2223
import useFollowUser from './profile/useFollowUser'
@@ -332,6 +333,7 @@ export default function HomePageFeed({
332333
}) {
333334
const [session, loading] = useSession()
334335
const [goalId, setgoalId] = useState('')
336+
const [isGoalPreviewOpen, setIsGoalPreviewOpen] = useState(false)
335337
return (
336338
<div className="min-h-screen bg-gray-100 flex flex-col">
337339
<header className="bg-white shadow-sm sticky top-0 z-10">
@@ -379,15 +381,22 @@ export default function HomePageFeed({
379381
<HomePageFeedUpdate
380382
update={update}
381383
key={update.id}
382-
setGoalId={() => setgoalId(update.goal.id)}
384+
setGoalId={() => {
385+
setIsGoalPreviewOpen(true)
386+
setgoalId(update.goal.id)
387+
}}
383388
/>
384389
))}
385390
</ul>
386391
</div>
387392
</div>
388393
</main>
389394
<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+
/>
391400
</aside>
392401
</div>
393402
</div>
@@ -534,8 +543,15 @@ function FollowButton({ user }: { user: User }) {
534543
)
535544
}
536545

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+
}) {
539555
const { isLoading, isError, data } = useQuery<{ response: GoalResponse }>(
540556
['/api/fauna/recent-updates', goalId],
541557
() => {
@@ -558,6 +574,93 @@ function HomePageAside({ goalId }: { goalId: string }) {
558574
})
559575
}
560576
)
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()
561664
const {
562665
isLoading: isWhoToFollowLoading,
563666
isError: isWhoToFollowError,
@@ -566,61 +669,15 @@ function HomePageAside({ goalId }: { goalId: string }) {
566669
return fetch(`/api/fauna/who-to-follow`).then((res) => res.json())
567670
})
568671

569-
const shouldShowRecentUpdates =
570-
Boolean(goalId) && goalId !== '' && !isLoading && !isError
571-
const goal: GoalResponse = data?.response
572-
573672
return (
574673
<>
575674
<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+
624681
{!isWhoToFollowLoading &&
625682
!isWhoToFollowError &&
626683
whoToFollowResponse.users.length > 0 && (

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy