-
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
35 changed files
with
530 additions
and
267 deletions.
There are no files selected for viewing
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...oard/components/dreams/DreamsProvider.tsx → ...ams)/components/dreams/DreamsProvider.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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
10 changes: 5 additions & 5 deletions
10
...ams/containers/CurrentDreamsContainer.tsx → ...ams/containers/CurrentDreamsContainer.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
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...nents/dreams/containers/PastDreamItem.tsx → ...nents/dreams/containers/PastDreamItem.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
95 changes: 95 additions & 0 deletions
95
...)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer.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,95 @@ | ||
"use client" | ||
|
||
import {FC, Fragment, useMemo} from "react"; | ||
import DreamContainer | ||
from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/DreamContainer"; | ||
import {useDreamsData} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider"; | ||
import {Dream} from "@prisma/client"; | ||
import {useEndOfDay} from "@/app/(site)/hooks/time-hooks"; | ||
import PastDreamItem from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamItem"; | ||
import DreamCardSkeleton | ||
from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCardSkeleton"; | ||
import {Divider} from "@nextui-org/divider"; | ||
import Card from "@/app/(site)/components/Card"; | ||
import {CardBody} from "@nextui-org/card"; | ||
import {useRouter} from "next/navigation"; | ||
import CloudIcon from "@/app/(site)/components/icons/CloudIcon"; | ||
import useDayDreams from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDayDreams"; | ||
|
||
export type GroupedDreams = { | ||
[K: string]: Dream[] | ||
} | ||
|
||
export type DayDreams = { | ||
timestamp: number, | ||
dreams: Dream[] | ||
} | ||
|
||
const NUMBER_OF_DAYS = 7 | ||
|
||
const PastDreamsContainer: FC = () => { | ||
const router = useRouter() | ||
const {dreams, tags, characters} = useDreamsData() | ||
const latestDate = useEndOfDay({ | ||
dayOffset: -1 | ||
}) | ||
|
||
const pastDreams = useDayDreams({ | ||
dreams: dreams.data, | ||
sortMode: "descending", | ||
dayCount: NUMBER_OF_DAYS, | ||
latestDate | ||
}) | ||
|
||
|
||
const dreamItems = useMemo(() => pastDreams.map(dream => ( | ||
<PastDreamItem | ||
key={dream.timestamp} | ||
dream={dream} | ||
allTags={tags.data} | ||
allCharacters={characters.data} | ||
/> | ||
)), [characters.data, pastDreams, tags.data]) | ||
|
||
|
||
return ( | ||
<DreamContainer | ||
containerClassName="!py-12" | ||
title="Previous Dreams" | ||
> | ||
{dreams.loading ? ( | ||
<Fragment> | ||
<DreamCardSkeleton/> | ||
<DreamCardSkeleton/> | ||
<DreamCardSkeleton/> | ||
</Fragment> | ||
) : (dreamItems.length ? | ||
<Fragment> | ||
{dreamItems} | ||
<Divider className="my-3"/> | ||
<Card | ||
onPress={() => router.push("/dashboard/calendar")} | ||
isPressable | ||
isBlurred | ||
classNames={{ | ||
base: "hover:scale-105", | ||
body: "bg-secondary py-8" | ||
}} | ||
> | ||
<CardBody> | ||
<div className="flex gap-4"> | ||
<CloudIcon width={32}/> | ||
<p className="font-semibold text-lg phone:text-medium self-center">View All Dreams</p> | ||
</div> | ||
</CardBody> | ||
</Card> | ||
</Fragment> | ||
: | ||
<h3 className="text-center font-light text-3xl tablet:text-xl text-subtext/30 py-6">You have no previous | ||
dreams for the past week...</h3>) | ||
} | ||
</DreamContainer> | ||
) | ||
} | ||
|
||
export default PastDreamsContainer |
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
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
2 changes: 1 addition & 1 deletion
2
...onents/dreams/forms/log/LogDreamModal.tsx → ...onents/dreams/forms/log/LogDreamModal.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
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDayDreams.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 @@ | ||
import {Dream} from "@prisma/client"; | ||
import { | ||
DayDreams, GroupedDreams | ||
} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer"; | ||
import {useEffect, useMemo} from "react"; | ||
|
||
type Args = { | ||
dreams: Dream[], | ||
latestDate?: Date, | ||
dayCount?: number, | ||
sortMode?: "ascending" | "descending" | ||
} | ||
|
||
const useDayDreams = ({dreams, latestDate, dayCount, sortMode}: Args): DayDreams[] => { | ||
const filteredDreams = useMemo<Dream[]>(() => dreams.filter(dream => latestDate ? new Date(dream.createdAt.toString()).getTime() <= latestDate.getTime() : true), [dreams, latestDate]) | ||
const sortedDreams = useMemo<Dream[]>(() => filteredDreams.sort((a, b) => { | ||
const aDate = new Date(a.createdAt.toString()) | ||
const bDate = new Date(b.createdAt.toString()) | ||
return sortMode === "descending" ? bDate.getTime() - aDate.getTime() : aDate.getTime() - bDate.getTime() | ||
}), [filteredDreams, sortMode]) | ||
|
||
const dreamCreationDates = useMemo(() => ( | ||
sortedDreams.map(dream => { | ||
const creationDate = new Date(dream.createdAt.toString()) | ||
creationDate.setHours(0, 0, 0, 0) | ||
return creationDate.getTime() | ||
}) | ||
// Remove duplicates | ||
.filter((creationTime, i, arr) => arr.indexOf(creationTime) === i) | ||
), [sortedDreams]) | ||
|
||
const groupedDreams = useMemo<GroupedDreams>(() => ( | ||
dreamCreationDates.reduce<GroupedDreams>((prev, curr, i, arr) => { | ||
const endDate = new Date(arr[i]) | ||
endDate.setHours(23, 59, 59, 999) | ||
|
||
const dreams = sortedDreams.filter(dream => { | ||
const dreamDate = new Date(dream.createdAt) | ||
return dreamDate.getTime() >= curr && dreamDate <= endDate | ||
}) | ||
|
||
return ({ | ||
...prev, | ||
[curr]: dreams | ||
}) | ||
}, {}) | ||
), [dreamCreationDates, sortedDreams]) | ||
|
||
|
||
const pastDreamsArr = useMemo<DayDreams[]>(() => Object.keys(groupedDreams) | ||
.filter(timestamp => groupedDreams[timestamp].length) | ||
.map(timestamp => { | ||
const dreamsForDay = groupedDreams[timestamp] | ||
return ({ | ||
timestamp: Number(timestamp), | ||
dreams: dreamsForDay | ||
}) | ||
}), [groupedDreams]) | ||
|
||
return dayCount && dayCount > 0 && pastDreamsArr.length ? pastDreamsArr.slice(0, Math.min(pastDreamsArr.length, dayCount)) : pastDreamsArr | ||
} | ||
|
||
export default useDayDreams |
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/app/(site)/(internal)/dashboard/page.tsx → ...nternal)/dashboard/(your-dreams)/page.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
Oops, something went wrong.