Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/events/ClientEventTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client';
//import react
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary import and comment

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos

return (
<span>
{localStartTime} - {localEndTime}
</span>
);
};
//export it
export default ClientEventTime;
29 changes: 13 additions & 16 deletions src/components/events/EventCard.tsx
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';
Expand All @@ -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,
Expand Down Expand Up @@ -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 */}
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Expand Down Expand Up @@ -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>
Expand Down