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

fix: css alignment of calendar component on the home page #3276

Open
wants to merge 23 commits into
base: master
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
21 changes: 13 additions & 8 deletions components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ export default function Calendar({ className = '', size }: ICalendarProps) {

const CALENDAR_URL =
'https://calendar.google.com/calendar/embed?src=c_q9tseiglomdsj6njuhvbpts11c%40group.calendar.google.com&ctz=UTC';
const eventsExist = eventsData.length > 0;
const currentDate = new Date();
const eventsExist = eventsData?.filter((event: IEvent) => moment(event.date).isAfter(currentDate)).length > 0;
Comment on lines +31 to +32
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider optimizing the date filtering logic

While the filtering logic is correct, there are a few potential improvements:

  1. Consider using the native Date API or lighter alternatives like date-fns instead of moment.js which is now considered legacy.
  2. The filtering could be memoized using useMemo to prevent unnecessary recalculations on re-renders.

Here's a suggested implementation:

-import moment from 'moment';
+import { isAfter, parseISO } from 'date-fns';
+import { useMemo } from 'react';

 export default function Calendar({ className = '', size }: ICalendarProps) {
   const { t } = useTranslation('common');
   const currentDate = new Date();
-  const eventsExist = eventsData?.filter((event: IEvent) => moment(event.date).isAfter(currentDate)).length > 0;
+  const eventsExist = useMemo(() => 
+    eventsData?.some((event: IEvent) => 
+      isAfter(parseISO(event.date), currentDate)
+    ),
+    [currentDate]
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const currentDate = new Date();
const eventsExist = eventsData?.filter((event: IEvent) => moment(event.date).isAfter(currentDate)).length > 0;
import { isAfter, parseISO } from 'date-fns';
import { useMemo } from 'react';
export default function Calendar({ className = '', size }: ICalendarProps) {
const { t } = useTranslation('common');
const currentDate = new Date();
const eventsExist = useMemo(() =>
eventsData?.some((event: IEvent) =>
isAfter(parseISO(event.date), currentDate)
),
[currentDate]
);


return (
<div className={twMerge('overflow-hidden rounded-md border border-gray-200 bg-white p-4', className)}>
<div
className={twMerge(
Copy link
Member

Choose a reason for hiding this comment

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

In the mobile/tab view, the calendar div is not in the center, rather it is slightly shifted towards the right.
Screenshot from 2024-10-07 12-15-03

It should be in the center like other cards:
Screenshot from 2024-10-07 12-15-16

'overflow-hidden rounded-md border border-gray-200 bg-white p-4 h-full flex flex-col gap-2',
className
)}
>
Comment on lines +35 to +40
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address mobile view alignment issue

While the flex container improvements help with layout, the mobile view alignment issue mentioned in the past review still needs attention. The calendar div appears shifted to the right on mobile/tab views instead of being centered like other cards.

Apply this diff to center the component on mobile views:

 <div
   className={twMerge(
-    'overflow-hidden rounded-md border border-gray-200 bg-white p-4 h-full flex flex-col gap-2',
+    'overflow-hidden rounded-md border border-gray-200 bg-white p-4 h-full flex flex-col gap-2 mx-auto w-full',
     className
   )}
 >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div
className={twMerge(
'overflow-hidden rounded-md border border-gray-200 bg-white p-4 h-full flex flex-col gap-2',
className
)}
>
<div
className={twMerge(
'overflow-hidden rounded-md border border-gray-200 bg-white p-4 h-full flex flex-col gap-2 mx-auto w-full',
className
)}
>

<Heading level={HeadingLevel.h2} typeStyle={HeadingTypeStyle.mdSemibold}>
{t('calendar.title')}
</Heading>
Expand All @@ -43,7 +49,7 @@ export default function Calendar({ className = '', size }: ICalendarProps) {
<span className='flex-1 self-center text-center'>{moment(event.date).format('D')}</span>
</div>
<div className='grow text-left sm:mt-0 sm:pl-6'>
<h2 className='title-font text-xl font-medium text-gray-900 hover:text-gray-500'>{event.title}</h2>
<h2 className='title-font font-medium text-gray-900 hover:text-gray-500'>{event.title}</h2>
<p className='text-gray-600'>
{moment(event.date).local().format('LLLL')} UTC
{moment(event.date).local().format('Z')}
Expand All @@ -53,13 +59,12 @@ export default function Calendar({ className = '', size }: ICalendarProps) {
</li>
))}
</ul>
{eventsExist ? (
<div className='pt-4' data-testid='Calendar-button'>
<div className='h-full content-center'>
{!eventsExist && <div className='font-bold text-gray-700 lg:pb-8'>{t('calendar.noMeetingsMessage')}</div>}
<div className='sm:pt-0 md:pt-2 lg:pb-8 lg:pt-0' data-testid='Calendar-button'>
<GoogleCalendarButton href={CALENDAR_URL} text={t('calendar.viewCalendarBtn')} />
</div>
) : (
<div className='mt-2 text-gray-700'>{t('calendar.noMeetingsMessage')}</div>
)}
</div>
Comment on lines +62 to +67
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify padding classes and improve accessibility

Two suggestions for improvement:

  1. The lg:pb-8 class is duplicated in both the message and button containers. Consider moving it to the parent div.
  2. The empty meetings message should be marked up as an aria-live region for better accessibility.

Here's the suggested improvement:

-      <div className='h-full content-center'>
-        {!eventsExist && <div className='font-bold text-gray-700 lg:pb-8'>{t('calendar.noMeetingsMessage')}</div>}
-        <div className='sm:pt-0 md:pt-2 lg:pb-8 lg:pt-0' data-testid='Calendar-button'>
+      <div className='h-full content-center lg:pb-8'>
+        {!eventsExist && (
+          <div 
+            className='font-bold text-gray-700'
+            role="status"
+            aria-live="polite"
+          >
+            {t('calendar.noMeetingsMessage')}
+          </div>
+        )}
+        <div className='sm:pt-0 md:pt-2 lg:pt-0' data-testid='Calendar-button'>
           <GoogleCalendarButton href={CALENDAR_URL} text={t('calendar.viewCalendarBtn')} />
         </div>
       </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className='h-full content-center'>
{!eventsExist && <div className='font-bold text-gray-700 lg:pb-8'>{t('calendar.noMeetingsMessage')}</div>}
<div className='sm:pt-0 md:pt-2 lg:pb-8 lg:pt-0' data-testid='Calendar-button'>
<GoogleCalendarButton href={CALENDAR_URL} text={t('calendar.viewCalendarBtn')} />
</div>
) : (
<div className='mt-2 text-gray-700'>{t('calendar.noMeetingsMessage')}</div>
)}
</div>
<div className='h-full content-center lg:pb-8'>
{!eventsExist && (
<div
className='font-bold text-gray-700'
role="status"
aria-live="polite"
>
{t('calendar.noMeetingsMessage')}
</div>
)}
<div className='sm:pt-0 md:pt-2 lg:pt-0' data-testid='Calendar-button'>
<GoogleCalendarButton href={CALENDAR_URL} text={t('calendar.viewCalendarBtn')} />
</div>
</div>

</div>
);
}
2 changes: 1 addition & 1 deletion pages/[lang]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function HomePage() {

<div className='mt-12 lg:flex lg:flex-row-reverse'>
<section className='mt-10 lg:mt-0 lg:flex-1'>
<Calendar size={2} className='float-left' />
<Calendar size={2} />
</section>
<section className='lg:mr-12 lg:max-w-xl lg:text-left'>
<div className='mt-5 lg:mr-12'>
Expand Down
2 changes: 1 addition & 1 deletion public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"calendar": {
"title": "Kommende Veranstaltungen",
"viewCalendarBtn": "Kalender ansehen",
"noMettingsMessage": "In den nächsten Tagen sind keine Sitzungen geplant."
"noMeetingsMessage": "In den nächsten Tagen sind keine Sitzungen geplant. Sie können bevorstehende Veranstaltungen überprüfen, indem Sie auf die Schaltfläche unten klicken."
}
}
4 changes: 2 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"calendar": {
"title": "Upcoming events",
"viewCalendarBtn": "View Calendar",
"noMettingsMessage": "There are no meetings scheduled for next few days."
"noMeetingsMessage": "There are no meetings scheduled for next few days. You can check upcoming events by clicking the button below."
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

German translation needs to be updated with the new message content

The verification revealed that while the Calendar component correctly uses the new key noMeetingsMessage, the German translation is missing the additional guidance about checking upcoming events that was added to the English version.

  • public/locales/de/common.json: Update the German translation to include the equivalent of "You can check upcoming events by clicking the button below"
🔗 Analysis chain

LGTM! Clear and helpful message text.

The expanded message provides better guidance to users by explaining how to check upcoming events.

Let's verify the related changes:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the key usage in components and German translation

# Test 1: Check if Calendar component uses the correct key
echo "Checking Calendar component for key usage..."
rg -A 2 "noMettingsMessage|noMeetingsMessage" 

# Test 2: Verify German translation
echo "Checking German translation..."
cat public/locales/de/common.json | jq '.calendar.noMeetingsMessage'

Length of output: 1134

}
}
}
2 changes: 1 addition & 1 deletion tests/build-tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jest.mock('../scripts/tools/tags-color', () => ({
}));

describe('buildTools', () => {
const testDir = path.join(os.tmpdir(), 'test_config');
const testDir = path.join(String(os.tmpdir()), 'test_config');
const toolsPath = resolve(testDir, 'tools.json');
const tagsPath = resolve(testDir, 'all-tags.json');
const automatedToolsPath = resolve(testDir, 'tools-automated.json');
Expand Down
Loading