Skip to content

Commit

Permalink
Update sorting for today dreams
Browse files Browse the repository at this point in the history
bombies committed Oct 26, 2023
1 parent 6e2fc16 commit dbd0eab
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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 => (
<DreamCard key={dream.id} dream={dream}/>
)), [dreams.data, endOfToday, startOfToday])
@@ -30,9 +31,9 @@ const CurrentDreamsContainer: FC = () => {
<LogDreamCard/>
{dreams.loading ? (
<Fragment>
<DreamCardSkeleton />
<DreamCardSkeleton />
<DreamCardSkeleton />
<DreamCardSkeleton/>
<DreamCardSkeleton/>
<DreamCardSkeleton/>
</Fragment>
) : dreamCards}
</div>
18 changes: 11 additions & 7 deletions src/app/(site)/hooks/useTodayTimeRange.tsx
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbd0eab

Please sign in to comment.