-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
245 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
...dashboard/components/dreams/DreamCard.tsx → ...oard/components/dreams/card/DreamCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/app/(site)/(internal)/dashboard/components/dreams/card/DreamCardSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client" | ||
|
||
import {FC} from "react"; | ||
import {CardBody, CardHeader} from "@nextui-org/card"; | ||
import Card from "@/app/(site)/components/Card"; | ||
import {Skeleton} from "@nextui-org/react"; | ||
|
||
const DreamCardSkeleton: FC = () => { | ||
return ( | ||
<Card | ||
classNames={{ | ||
header: "bg-[#0C0015] pt-6 px-8 pb-0", | ||
body: "bg-[#0C0015] px-8 pt-4", | ||
footer: "bg-[#0C0015] px-8", | ||
}}> | ||
<CardHeader className="flex justify-between"> | ||
<Skeleton className="rounded-full w-[70%] phone:w-[50%] h-6" /> | ||
<Skeleton className="rounded-full self-end h-5 w-[20%]" /> | ||
</CardHeader> | ||
<CardBody> | ||
<Skeleton className="rounded-full w-[85%] h-3 my-4" /> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
export default DreamCardSkeleton |
63 changes: 63 additions & 0 deletions
63
src/app/(site)/(internal)/dashboard/components/dreams/card/DreamModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use client" | ||
|
||
import {FC, Fragment, useEffect, useMemo} from "react"; | ||
import Modal from "@/app/(site)/components/Modal"; | ||
import {Dream} from "@prisma/client"; | ||
import useSWR from "swr"; | ||
import {calcEstimatedReadingTime, fetcher} from "@/utils/client/client-utils"; | ||
import {DreamWithRelations} from "@/app/api/me/dreams/dreams.dto"; | ||
import {Chip} from "@nextui-org/chip"; | ||
|
||
type Props = { | ||
dream: Dream, | ||
isOpen?: boolean, | ||
onClose?: () => void | ||
} | ||
|
||
const FetchFullDream = (dream: Dream, modalOpen: boolean) => { | ||
return useSWR(modalOpen && `/api/me/dreams/${dream.id}?tags=true&characters=true`, fetcher<DreamWithRelations | null>, {refreshInterval: 0}) | ||
} | ||
|
||
const DreamModal: FC<Props> = ({dream, isOpen, onClose}) => { | ||
const {data: fullDream, error: fullDreamError} = FetchFullDream(dream, isOpen ?? false) | ||
|
||
const tagChips = useMemo(() => fullDream?.tags?.map(tag => ( | ||
<Chip key={tag.id} color="primary" variant="flat"> | ||
{tag.tag} | ||
</Chip> | ||
)), [fullDream?.tags]) | ||
|
||
useEffect(() => { | ||
if (fullDreamError) | ||
console.error(fullDreamError) | ||
}, [fullDreamError]) | ||
|
||
return ( | ||
<Modal | ||
size="2xl" | ||
header={ | ||
<Fragment> | ||
{(tagChips || fullDreamError) && ( | ||
<div className="flex flex-wrap gap-2 mb-3"> | ||
{tagChips ?? (fullDreamError && | ||
<Chip color="danger" variant="flat"> | ||
Error Loading Tags | ||
</Chip> | ||
)} | ||
</div> | ||
)} | ||
<h1 className="text-4xl">{dream.title}</h1> | ||
<h3 className="text-subtext text-sm font-semibold italic">{dream.comments}</h3> | ||
<h3 className="text-subtext text-xs italic">~{calcEstimatedReadingTime(dream.description)} min. read</h3> | ||
</Fragment> | ||
} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
> | ||
<article | ||
className="text-[#EAE0FF] whitespace-pre-wrap rounded-3xl border border-primary/40 bg-[#0C0015]/50 p-6">{dream.description}</article> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default DreamModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/app/(site)/(internal)/dashboard/components/dreams/hooks/useDreamCharacters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/app/(site)/(internal)/dashboard/components/dreams/hooks/useDreamTags.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 3 additions & 12 deletions
15
src/app/(site)/(internal)/dashboard/components/dreams/hooks/useDreams.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {authenticated} from "@/app/api/utils/api-utils"; | ||
import dreamsService from "@/app/api/me/dreams/dreams.service"; | ||
|
||
export type DreamRouteContext = { | ||
params: { | ||
id: string | ||
} | ||
} | ||
|
||
const TAGS_SEARCH_PARAM = "tags" | ||
const CHARACTERS_SEARCH_PARAM = "characters" | ||
|
||
export const GET = async (request: Request, {params}: DreamRouteContext) => | ||
authenticated((session) => { | ||
const searchParams = new URL(request.url).searchParams | ||
const withTags = searchParams.get(TAGS_SEARCH_PARAM)?.toLowerCase() === "true" | ||
const withCharacters = searchParams.get(CHARACTERS_SEARCH_PARAM)?.toLowerCase() === "true" | ||
return dreamsService.fetchDream(session, params.id, {withTags, withCharacters}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.