Skip to content

Commit 189c38b

Browse files
authored
feat: calendar small screen view V1 (#7)
1 parent b3e82d0 commit 189c38b

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

frontend/components/teachingEvents/calendar/calendar.tsx

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,44 @@ export default function Calendar(props: CalendarProps) {
1313
const calendarData = getCalendarData(props.selectedEvents);
1414
return (
1515
<>
16+
{/*Small screen*/}
17+
<div className={'md:hidden flex h-screen snap-x gap-8 overflow-x-auto p-4'}>
18+
{calendarData.map((day) => (
19+
<div
20+
key={day.name}
21+
id={day.name}
22+
className={'flex min-w-full snap-center flex-col'}
23+
>
24+
<div
25+
className={
26+
'sticky left-0 self-center text-2xl text-muted-foreground'
27+
}
28+
>
29+
{day.name}
30+
</div>
31+
<div className={'grid gap-1 overflow-hidden'}>
32+
{day.events.map((event, index) => (
33+
<div
34+
key={index}
35+
className={`${positionStylesLookup['rowStart'][event.position.rowStart]} ${positionStylesLookup['rowSpan'][event.position.rowSpan]}`}
36+
>
37+
<CalendarEventCard event={event}></CalendarEventCard>
38+
</div>
39+
))}
40+
</div>
41+
</div>
42+
))}
43+
</div>
44+
{/*Large screen*/}
1645
<div
1746
className={
18-
'grid-rows-[auto_repeat(52,minmax(1fr,30px)] my-10 grid w-full grid-cols-[auto,1fr,1fr,1fr,1fr,1fr] overflow-x-auto border-r pb-2 text-left text-xl text-muted-foreground'
47+
'my-10 hidden w-full grid-cols-[56px,1fr,1fr,1fr,1fr,1fr] overflow-x-auto border-r pb-2 text-left text-xl text-muted-foreground md:visible md:grid'
1948
}
2049
>
21-
<div className={'col-span-6 col-start-2 grid grid-cols-subgrid'}>
22-
{calendarData.map((data, index) => (
23-
<div key={index} className={'pb-2 pl-2'}>
24-
{data.name}
25-
</div>
26-
))}
27-
</div>
50+
{/*Time*/}
2851
<div
2952
className={
30-
'sticky left-0 col-start-1 row-span-54 row-start-1 grid grid-rows-subgrid border-r bg-zinc-50 pr-4 dark:bg-black'
53+
'sticky left-0 col-start-1 row-span-54 grid grid-rows-subgrid border-r bg-zinc-50 pr-4 dark:bg-black'
3154
}
3255
>
3356
<div></div>
@@ -41,34 +64,38 @@ export default function Calendar(props: CalendarProps) {
4164
</div>
4265
))}
4366
</div>
67+
68+
{/*Lines*/}
4469
<div
4570
className={
46-
'col-span-6 col-start-1 row-span-54 row-start-2 grid grid-cols-subgrid grid-rows-subgrid'
71+
'col-span-6 col-start-2 row-span-54 row-start-2 grid grid-cols-subgrid grid-rows-subgrid'
4772
}
4873
>
4974
{timeIntervals.map((time, index) =>
5075
time.endsWith('00') ? (
5176
<div
5277
key={index}
53-
className={`col-span-6 col-start-2 border-t border-muted-foreground/60`}
78+
className={`col-span-6 border-t border-muted-foreground/60`}
5479
></div>
5580
) : (
56-
<div
57-
key={index}
58-
className={`col-span-6 col-start-2 border-t`}
59-
></div>
81+
<div key={index} className={`col-span-6 border-t`}></div>
6082
),
6183
)}
6284
</div>
63-
{calendarData.map((data, index) => (
85+
86+
{/*Events*/}
87+
{calendarData.map((day, index) => (
6488
<div
6589
key={index}
66-
className={`${positionStylesLookup['colStart'][index + 2]} row-span-54 row-start-2 grid grid-rows-subgrid gap-x-2 border-r px-4`}
90+
className={`${positionStylesLookup['colStart'][index + 2]} row-span-54 row-start-1 grid grid-rows-subgrid gap-x-2 border-r px-4`}
6791
>
68-
{data.events.map((event, index) => (
92+
<p className={'sticky left-14 -z-10 mb-4 pl-4 text-2xl'}>
93+
{day.name}
94+
</p>
95+
{day.events.map((event, index) => (
6996
<div
7097
key={index}
71-
className={`${positionStylesLookup['rowStart'][data.events[index].position.rowStart]} ${positionStylesLookup['rowSpan'][data.events[index].position.rowSpan]}`}
98+
className={`${positionStylesLookup['rowStart'][event.position.rowStart]} ${positionStylesLookup['rowSpan'][event.position.rowSpan]}`}
7299
>
73100
<CalendarEventCard event={event}></CalendarEventCard>
74101
</div>

frontend/components/teachingEvents/calendar/event-card.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ interface CalendarEventCardProps {
66

77
export default function CalendarEventCard(props: CalendarEventCardProps) {
88
return (
9-
<>
109
<div
11-
className={`h-full rounded p-2 ${cardStyleLookup[getEventCardStyle(props.event.types)]}`}
10+
className={`text-wrap min-w-full max-w-min md:w-auto h-full rounded p-2 ${cardStyleLookup[getEventCardStyle(props.event.types)]}`}
1211
>
1312
<p className={'text-xs font-bold'}>{props.event.title}</p>
1413
<p className={'text-xs'}>
@@ -17,7 +16,6 @@ export default function CalendarEventCard(props: CalendarEventCardProps) {
1716
<p className={'text-xs'}>{props.event.room}</p>
1817
<p className={'text-xs'}>{props.event.instructor}</p>
1918
</div>
20-
</>
2119
);
2220
}
2321

frontend/lib/teachingEvent/calendar.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function getEventRowPosition(event: EventModel) {
5454
+event.startTime.split(':')[1],
5555
];
5656
const end = [+event.endTime.split(':')[0], +event.endTime.split(':')[1]];
57-
const rowStart = (start[0] - 8) * 4 + start[1] / 15 + 1;
58-
const rowSpan = (end[0] - 8) * 4 + end[1] / 15 - rowStart + 1;
57+
const rowStart = (start[0] - 8) * 4 + start[1] / 15 + 2;
58+
const rowSpan = (end[0] - 8) * 4 + end[1] / 15 - rowStart + 2;
5959
return [rowStart, rowSpan];
6060
}
6161

0 commit comments

Comments
 (0)