From dbd0eab5efde6c9702717a7d3f5613e755f2873c Mon Sep 17 00:00:00 2001 From: bombies Date: Thu, 26 Oct 2023 13:55:37 -0500 Subject: [PATCH] Update sorting for today dreams --- .../dreams/CurrentDreamsContainer.tsx | 7 ++++--- src/app/(site)/hooks/useTodayTimeRange.tsx | 18 +++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/app/(site)/(internal)/dashboard/components/dreams/CurrentDreamsContainer.tsx b/src/app/(site)/(internal)/dashboard/components/dreams/CurrentDreamsContainer.tsx index 6a995dc..ad6d66a 100644 --- a/src/app/(site)/(internal)/dashboard/components/dreams/CurrentDreamsContainer.tsx +++ b/src/app/(site)/(internal)/dashboard/components/dreams/CurrentDreamsContainer.tsx @@ -14,6 +14,7 @@ const CurrentDreamsContainer: FC = () => { const creationDate = new Date(dream.createdAt.toString()); return creationDate.getTime() >= startOfToday.getTime() && creationDate.getTime() <= endOfToday.getTime() }) + .sort((a, b) => new Date(b.createdAt.toString()).getTime() - new Date(a.createdAt.toString()).getTime()) .map(dream => ( )), [dreams.data, endOfToday, startOfToday]) @@ -30,9 +31,9 @@ const CurrentDreamsContainer: FC = () => { {dreams.loading ? ( - - - + + + ) : dreamCards} diff --git a/src/app/(site)/hooks/useTodayTimeRange.tsx b/src/app/(site)/hooks/useTodayTimeRange.tsx index fd6dccc..e831f07 100644 --- a/src/app/(site)/hooks/useTodayTimeRange.tsx +++ b/src/app/(site)/hooks/useTodayTimeRange.tsx @@ -3,18 +3,22 @@ import {useMemo} from "react"; const useTodayTimeRange = () => { - const startOfToday = useMemo(() => { - const today = new Date() + return useTimeRange(new Date()) +} + +export const useTimeRange = (date: Date): [Date, Date] => { + const startOfDay = useMemo(() => { + const today = new Date(date) today.setHours(0, 0, 0, 0) return today; - }, []) - const endOfToday = useMemo(() => { - const today = new Date() + }, [date]) + const endOfDay = useMemo(() => { + const today = new Date(date) today.setHours(23, 59, 59, 999) return today; - }, []) + }, [date]) - return [startOfToday, endOfToday] + return [startOfDay, endOfDay] } export default useTodayTimeRange \ No newline at end of file