Skip to content

Commit aa9451c

Browse files
committed
add dark mode support for weekly grid
1 parent 437de8c commit aa9451c

2 files changed

Lines changed: 100 additions & 45 deletions

File tree

src/components/CommunityPortal/Calendar/CommunityCalendar.jsx

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,12 @@ function CommunityCalendar() {
174174
function WeeklyTimeGrid({ events, selectedDate, onEventClick, darkMode }) {
175175
const hours = Array.from({ length: 24 }, (_, i) => i);
176176

177-
// Find the Sunday of the currently selected week
178177
const startOfWeek = useMemo(() => {
179178
const d = new Date(selectedDate);
180-
const day = d.getDay(); // 0 (Sun) to 6 (Sat)
181-
d.setDate(d.getDate() - day);
179+
d.setDate(d.getDate() - d.getDay());
182180
return d;
183181
}, [selectedDate]);
184182

185-
// Create an array of 7 Date objects for the header
186183
const weekDays = useMemo(() => {
187184
return Array.from({ length: 7 }, (_, i) => {
188185
const day = new Date(startOfWeek);
@@ -192,25 +189,27 @@ function CommunityCalendar() {
192189
}, [startOfWeek]);
193190

194191
return (
195-
<div className={`${styles.weekGridContainer} ${darkMode ? styles.weekGridDark : ''}`}>
196-
{/* HEADER: Day Names and Numbers */}
197-
<div className={styles.weekGridHeader}>
198-
<div className={styles.timeGutter}></div>
192+
<div
193+
className={`${styles.weekGridContainer} ${darkMode ? styles.weekGridContainerDark : ''}`}
194+
>
195+
<div className={`${styles.weekGridHeader} ${darkMode ? styles.weekGridHeaderDark : ''}`}>
196+
<div className={styles.timeGutter} />
199197
{weekDays.map(date => (
200198
<div key={date.toString()} className={styles.dayColumnHeader}>
201-
<div className={styles.dayLabel}>
199+
<div className={`${styles.dayLabel} ${darkMode ? styles.dayLabelDark : ''}`}>
202200
{date.toLocaleDateString('en-US', { weekday: 'short' })}
203201
</div>
204-
<div className={styles.dateLabel}>{date.getDate()}</div>
202+
<div className={`${styles.dateLabel} ${darkMode ? styles.dateLabelDark : ''}`}>
203+
{date.getDate()}
204+
</div>
205205
</div>
206206
))}
207207
</div>
208208

209-
{/* BODY: Time Rows */}
210209
<div className={styles.weekGridBody}>
211210
{hours.map(hour => (
212-
<div key={hour} className={styles.hourRow}>
213-
<div className={styles.timeLabel}>
211+
<div key={hour} className={`${styles.hourRow} ${darkMode ? styles.hourRowDark : ''}`}>
212+
<div className={`${styles.timeLabel} ${darkMode ? styles.timeLabelDark : ''}`}>
214213
{hour === 0
215214
? '12 AM'
216215
: hour > 12
@@ -219,36 +218,47 @@ function CommunityCalendar() {
219218
? '12 PM'
220219
: `${hour} AM`}
221220
</div>
221+
222222
{weekDays.map(date => {
223-
// Filter events that happen on THIS day at THIS hour
224223
const cellEvents = events.filter(e => {
225224
const eventDate = new Date(e.date);
226-
// Check if date matches and if the hour in "10:00 AM" matches our current row
227-
const eventHour = parseInt(e.time.split(':')[0]);
225+
const [hStr] = e.time.split(':');
226+
let h = parseInt(hStr, 10);
228227
const isPM = e.time.toLowerCase().includes('pm');
229-
const normalizedEventHour =
230-
isPM && eventHour !== 12
231-
? eventHour + 12
232-
: !isPM && eventHour === 12
233-
? 0
234-
: eventHour;
235-
236-
return (
237-
eventDate.toDateString() === date.toDateString() && normalizedEventHour === hour
238-
);
228+
const isAM = e.time.toLowerCase().includes('am');
229+
if (isPM && h !== 12) h += 12;
230+
if (isAM && h === 12) h = 0;
231+
232+
return eventDate.toDateString() === date.toDateString() && h === hour;
239233
});
240234

241235
return (
242-
<div key={date.toString()} className={styles.gridCell}>
243-
{cellEvents.map(event => (
236+
<div
237+
key={date.toString()}
238+
className={`${styles.gridCell} ${darkMode ? styles.gridCellDark : ''}`}
239+
>
240+
{cellEvents.map(ev => (
244241
<button
245-
key={event.id}
242+
key={ev.id}
246243
type="button"
247-
className={styles.gridEvent}
248-
onClick={() => onEventClick(event)}
244+
className={`${styles.gridEvent} ${darkMode ? styles.gridEventDark : ''}`}
245+
onClick={() => onEventClick(ev)}
246+
aria-label={`Open event ${ev.title} at ${ev.time}`}
249247
>
250-
<div className={styles.gridEventTime}>{event.time}</div>
251-
<div className={styles.gridEventTitle}>{event.title}</div>
248+
<div
249+
className={`${styles.gridEventTime} ${
250+
darkMode ? styles.gridEventTimeDark : ''
251+
}`}
252+
>
253+
{ev.time}
254+
</div>
255+
<div
256+
className={`${styles.gridEventTitle} ${
257+
darkMode ? styles.gridEventTitleDark : ''
258+
}`}
259+
>
260+
{ev.title}
261+
</div>
252262
</button>
253263
))}
254264
</div>

src/components/CommunityPortal/Calendar/CommunityCalendar.module.css

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@
10961096
margin-bottom: 20px;
10971097
}
10981098

1099+
.weekGridBody {
1100+
flex: 1;
1101+
overflow-y: scroll;
1102+
background: #ffffff;
1103+
}
1104+
10991105
.weekGridHeader {
11001106
display: grid;
11011107
grid-template-columns: 80px repeat(7, 1fr);
@@ -1123,12 +1129,6 @@
11231129
color: #1e293b;
11241130
}
11251131

1126-
.weekGridBody {
1127-
flex: 1;
1128-
overflow-y: scroll;
1129-
background-color: #fff;
1130-
}
1131-
11321132
.hourRow {
11331133
display: grid;
11341134
grid-template-columns: 80px repeat(7, 1fr);
@@ -1176,11 +1176,56 @@
11761176
text-overflow: ellipsis;
11771177
}
11781178

1179-
.weekGridDark {
1179+
/* Dark Mode Support */
1180+
.weekGridContainerDark {
1181+
background: #1a2332;
1182+
border-color: #2d3748;
1183+
}
1184+
1185+
.weekGridContainerDark .weekGridBody {
11801186
background: #0f172a;
1181-
border-color: #1e293b;
11821187
}
1183-
.weekGridDark .weekGridHeader { background: #1e293b; border-bottom-color: #334155; }
1184-
.weekGridDark .dateLabel { color: #f1f5f9; }
1185-
.weekGridDark .hourRow { border-bottom-color: #1e293b; }
1186-
.weekGridDark .timeLabel { border-right-color: #334155; }
1188+
1189+
.weekGridHeaderDark {
1190+
background: #232d3f;
1191+
border-bottom-color: #2d3748;
1192+
}
1193+
1194+
.dayLabelDark {
1195+
color: #a0aec0;
1196+
}
1197+
1198+
.dateLabelDark {
1199+
color: #ffffff;
1200+
}
1201+
1202+
.hourRowDark {
1203+
border-bottom-color: #2d3748;
1204+
}
1205+
1206+
.timeLabelDark {
1207+
color: #718096;
1208+
border-right-color: #2d3748;
1209+
}
1210+
1211+
.gridCellDark {
1212+
border-left-color: #2d3748;
1213+
}
1214+
1215+
.gridCellDark:hover {
1216+
background-color: rgba(255, 255, 255, 0.03);
1217+
}
1218+
1219+
.gridEventDark {
1220+
background: #064e3b;
1221+
border-left: 4px solid #10b981;
1222+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
1223+
}
1224+
1225+
.gridEventTitleDark {
1226+
color: #d1fae5;
1227+
}
1228+
1229+
.gridEventTimeDark {
1230+
color: #a7f3d0;
1231+
}

0 commit comments

Comments
 (0)