-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ClientEventTime #245
base: develop
Are you sure you want to change the base?
add ClientEventTime #245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client'; | ||
//import react | ||
import React from 'react'; | ||
import { format } from 'date-fns'; | ||
|
||
//ensures startTime and endTime are Date types | ||
interface ClientEventTimeProps { | ||
startTime: Date; // start time of event in UTC | ||
endTime: Date; // end time of event in UTC | ||
} | ||
|
||
const ClientEventTime: React.FC<ClientEventTimeProps> = ({ | ||
startTime, | ||
endTime, | ||
}) => { | ||
//convert the startTime from UTC to the users local time with the Date object | ||
//tolocalestring gives the date and time formatted according to users local time | ||
const localStartTime = new Date(startTime).toLocaleString(undefined, { | ||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
//same | ||
const localEndTime = new Date(endTime).toLocaleString(undefined, { | ||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
Comment on lines
+18
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this is necessary since it's a client component, you can play with it once it builds on vercel. |
||
|
||
//resturn span element that dispalys local start and end time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typos |
||
return ( | ||
<span> | ||
{localStartTime} - {localEndTime} | ||
</span> | ||
); | ||
}; | ||
//export it | ||
export default ClientEventTime; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
'use server'; | ||
|
||
import { format, isSameDay } from 'date-fns'; | ||
import Image from 'next/image'; | ||
import Link from 'next/link'; | ||
|
@@ -7,6 +8,7 @@ import { type RouterOutputs } from '@src/trpc/shared'; | |
import EventLikeButton from './EventLikeButton'; | ||
import { getServerAuthSession } from '@src/server/auth'; | ||
import dynamic from 'next/dynamic'; | ||
import ClientEventTime from './ClientEventTime'; //importing new component | ||
|
||
const EventTimeAlert = dynamic(() => import('./EventTimeAlert'), { | ||
ssr: false, | ||
|
@@ -50,14 +52,14 @@ const HorizontalCard = async ({ | |
</Link>{' '} | ||
•<wbr /> | ||
<span className="text-blue-primary"> | ||
{format(event.startTime, 'E, MMM d, p')} | ||
{isSameDay(event.startTime, event.endTime) ? ( | ||
<> - {format(event.endTime, 'p')}</> | ||
) : ( | ||
<> - {format(event.endTime, 'E, MMM d, p')}</> | ||
)} | ||
{/* Use the ClientEventTime component here */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary comment |
||
<ClientEventTime | ||
startTime={event.startTime} //ClientEventTime logic | ||
endTime={event.endTime} | ||
/> | ||
</span> | ||
</h4> | ||
|
||
<p className="line-clamp-3 overflow-clip text-ellipsis text-xs font-bold"> | ||
{event.description} | ||
</p> | ||
|
@@ -112,16 +114,11 @@ const VerticalCard = async ({ | |
</Link> | ||
<div> | ||
<span className="text-blue-primary"> | ||
{format(event.startTime, 'E, MMM d, p')} | ||
{isSameDay(event.startTime, event.endTime) ? ( | ||
<> - {format(event.endTime, 'p')}</> | ||
) : ( | ||
<> | ||
{' '} | ||
- <br /> | ||
{format(event.endTime, 'E, MMM d, p')} | ||
</> | ||
)} | ||
{/* Use the ClientEventTime component here */} | ||
<ClientEventTime | ||
startTime={event.startTime} | ||
endTime={event.endTime} | ||
/> | ||
</span> | ||
</div> | ||
</h4> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary import and comment