Skip to content

Commit 9a576df

Browse files
committed
courseTable 大枠
1 parent e75f265 commit 9a576df

File tree

4 files changed

+97
-33
lines changed

4 files changed

+97
-33
lines changed

common/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const DAY_TO_JAPANESE_MAP = new Map<Day, string>([
1010
["sun", "日"],
1111
]);
1212

13-
export const ACTIVE_DAYS = ["mon", "tue", "wed", "thu", "fri", "sat"] as const;
13+
export const ACTIVE_DAYS = ["mon", "tue", "wed", "thu", "fri"] as const;
1414

1515
export const sortSlots = (
1616
slots: {

web/components/Card.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ const CardBack = ({ displayedUser, currentUser }: CardProps) => {
183183
<div className="flex justify-center">
184184
<p className="font-bold text-lg">{displayedUser?.name}</p>
185185
</div>
186-
<NonEditableCoursesTable
187-
userId={displayedUser.id}
188-
comparisonUserId={currentUser.id}
189-
/>
186+
<div className="flex-1">
187+
<NonEditableCoursesTable
188+
userId={displayedUser.id}
189+
comparisonUserId={currentUser.id}
190+
/>
191+
</div>
190192
<div className="mt-4 flex justify-center">
191193
<ThreeSixtyIcon className="text-3xl" />
192194
</div>

web/components/course/components/CoursesTableCore/index.tsx

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,43 @@ export default function CoursesTableCore(props: Props) {
8787
}, [props.courses, props.comparisonCourses, transformCoursesToRows]);
8888

8989
return (
90-
<table className={styles.table}>
91-
<thead>
92-
<tr>
93-
<th />
94-
{ACTIVE_DAYS.map((activeDay) => (
95-
<th align="center" key={`header-${activeDay}`}>
96-
{DAY_TO_JAPANESE_MAP.get(activeDay as Day)}
97-
</th>
90+
<div className="flex h-full flex-col">
91+
<div
92+
className="grid h-[3vh] grid-rows-1 gap-1"
93+
style={{
94+
gridTemplateColumns: `3vh repeat(${ACTIVE_DAYS.length}, minmax(0, 1fr))`,
95+
}}
96+
>
97+
<span className="rounded-sm bg-gray-100" />
98+
{ACTIVE_DAYS.map((activeDay) => (
99+
<span
100+
key={`header-${activeDay}`}
101+
className="inline-flex items-center justify-center rounded-sm bg-gray-100 text-center text-xs"
102+
>
103+
{DAY_TO_JAPANESE_MAP.get(activeDay as Day)}
104+
</span>
105+
))}
106+
</div>
107+
<div className="mt-1 flex flex-1 gap-1">
108+
<div className="flex h-full w-[3vh] flex-col gap-1">
109+
{Array.from({ length: 6 }, (_, i) => (
110+
<span
111+
key={`period-${i + 1}`}
112+
className="inline-flex flex-1 items-center justify-center rounded-sm bg-gray-100 text-xs"
113+
>
114+
{i + 1}
115+
</span>
98116
))}
99-
</tr>
100-
</thead>
101-
<tbody>
102-
{rows.map((row, rowIndex) => (
103-
<tr key={`period-${rowIndex + 1}`}>
104-
<th key={`header-period-${rowIndex + 1}`}>{rowIndex + 1}</th>
105-
{ACTIVE_DAYS.map((day) => (
117+
</div>
118+
<div
119+
className="grid flex-1 grid-rows-6 gap-1"
120+
style={{
121+
gridTemplateColumns: `repeat(${ACTIVE_DAYS.length}, minmax(0, 1fr))`,
122+
}}
123+
>
124+
{/* TODO: grid-auto-flow: column; で縦方向に流すほうが余計な変形ロジックが減りそう */}
125+
{rows.map((row, rowIndex) =>
126+
ACTIVE_DAYS.map((day) => (
106127
<Cell
107128
key={`cell-${day}-${rowIndex.toString()}`}
108129
courseName={row[day]?.name ?? null}
@@ -115,11 +136,44 @@ export default function CoursesTableCore(props: Props) {
115136
: undefined
116137
}
117138
/>
139+
)),
140+
)}
141+
</div>
142+
</div>
143+
{/* <table className={styles.table}>
144+
<thead>
145+
<tr>
146+
<th />
147+
{ACTIVE_DAYS.map((activeDay) => (
148+
<th align="center" key={`header-${activeDay}`}>
149+
{DAY_TO_JAPANESE_MAP.get(activeDay as Day)}
150+
</th>
118151
))}
119152
</tr>
120-
))}
121-
</tbody>
122-
</table>
153+
</thead>
154+
<tbody>
155+
{rows.map((row, rowIndex) => (
156+
<tr key={`period-${rowIndex + 1}`}>
157+
<th key={`header-period-${rowIndex + 1}`}>{rowIndex + 1}</th>
158+
{ACTIVE_DAYS.map((day) => (
159+
<Cell
160+
key={`cell-${day}-${rowIndex.toString()}`}
161+
courseName={row[day]?.name ?? null}
162+
teacherName={row[day]?.teacher ?? null}
163+
isOverlapping={row[day]?.isOverlapping}
164+
isButton={props.isButton}
165+
onClick={
166+
props.isButton
167+
? () => props.onCellClick(rowIndex, day, row[day] ?? null)
168+
: undefined
169+
}
170+
/>
171+
))}
172+
</tr>
173+
))}
174+
</tbody>
175+
</table> */}
176+
</div>
123177
);
124178
}
125179

@@ -138,7 +192,7 @@ function Cell({
138192
}) {
139193
const content = (
140194
<>
141-
<p
195+
<span
142196
style={{
143197
margin: 0,
144198
overflow: "hidden",
@@ -150,8 +204,8 @@ function Cell({
150204
}}
151205
>
152206
{courseName ? truncateStr(courseName ?? "", 16) : ""}
153-
</p>
154-
<p
207+
</span>
208+
<span
155209
style={{
156210
margin: 0,
157211
overflow: "hidden",
@@ -163,12 +217,20 @@ function Cell({
163217
}}
164218
>
165219
{teacherName ? truncateStr(teacherName ?? "", 6) : ""}
166-
</p>
220+
</span>
167221
</>
168222
);
169223

170224
return (
171-
<td align="center">
225+
<span
226+
className={`inline-flex flex-1 items-center justify-center rounded-sm text-xs ${
227+
!courseName
228+
? "bg-transparent"
229+
: isOverlapping
230+
? "bg-[#FFF1BF]"
231+
: "bg-[#F7FCFF]"
232+
}`}
233+
>
172234
{isButton ? (
173235
<button
174236
type="button"
@@ -184,7 +246,7 @@ function Cell({
184246
{content}
185247
</button>
186248
) : (
187-
<div
249+
<span
188250
className={
189251
isOverlapping
190252
? styles.overlapped
@@ -194,8 +256,8 @@ function Cell({
194256
}
195257
>
196258
{content}
197-
</div>
259+
</span>
198260
)}
199-
</td>
261+
</span>
200262
);
201263
}

web/components/course/components/CoursesTableCore/styles.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.table {
1+
/* .table {
22
width: 100%;
33
table-layout: fixed;
44
border-collapse: collapse;
@@ -61,4 +61,4 @@
6161
6262
.spaceAround {
6363
justify-content: space-around;
64-
}
64+
} */

0 commit comments

Comments
 (0)