Spaces:
Sleeping
Sleeping
Create CourseInfoHeader.tsx
Browse files
web/src/components/CourseInfoHeader.tsx
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useMemo } from "react";
|
| 2 |
+
|
| 3 |
+
type Person = { name: string; email: string };
|
| 4 |
+
|
| 5 |
+
export type CourseInfo = {
|
| 6 |
+
id: string;
|
| 7 |
+
name: string;
|
| 8 |
+
instructor: Person;
|
| 9 |
+
teachingAssistant: Person;
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
function buildMailto(email: string, subject: string, body?: string) {
|
| 13 |
+
const s = encodeURIComponent(subject);
|
| 14 |
+
const b = body ? `&body=${encodeURIComponent(body)}` : "";
|
| 15 |
+
return `mailto:${encodeURIComponent(email)}?subject=${s}${b}`;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export function CourseInfoHeader({
|
| 19 |
+
course,
|
| 20 |
+
className,
|
| 21 |
+
}: {
|
| 22 |
+
course: CourseInfo;
|
| 23 |
+
className?: string;
|
| 24 |
+
}) {
|
| 25 |
+
const instructorMailto = useMemo(() => {
|
| 26 |
+
return buildMailto(
|
| 27 |
+
course.instructor.email,
|
| 28 |
+
`[Clare] Question about ${course.name}`,
|
| 29 |
+
`Hi ${course.instructor.name},\n\nI have a question about ${course.name}:\n\n(Write your question here)\n\nThanks,\n`
|
| 30 |
+
);
|
| 31 |
+
}, [course]);
|
| 32 |
+
|
| 33 |
+
const taMailto = useMemo(() => {
|
| 34 |
+
return buildMailto(
|
| 35 |
+
course.teachingAssistant.email,
|
| 36 |
+
`[Clare] Help request for ${course.name}`,
|
| 37 |
+
`Hi ${course.teachingAssistant.name},\n\nI need help with ${course.name}:\n\n(Write your question here)\n\nThanks,\n`
|
| 38 |
+
);
|
| 39 |
+
}, [course]);
|
| 40 |
+
|
| 41 |
+
return (
|
| 42 |
+
<div className={className ?? "px-4 pt-4 pb-3"}>
|
| 43 |
+
<div className="space-y-1">
|
| 44 |
+
<div className="text-base font-semibold text-foreground truncate">
|
| 45 |
+
{course.name}
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<div className="text-sm text-muted-foreground">
|
| 49 |
+
Instructor:{" "}
|
| 50 |
+
<a
|
| 51 |
+
href={instructorMailto}
|
| 52 |
+
className="text-primary hover:underline"
|
| 53 |
+
title={`Email ${course.instructor.name}`}
|
| 54 |
+
onClick={(e) => e.stopPropagation()}
|
| 55 |
+
>
|
| 56 |
+
{course.instructor.name}
|
| 57 |
+
</a>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<div className="text-sm text-muted-foreground">
|
| 61 |
+
TA:{" "}
|
| 62 |
+
<a
|
| 63 |
+
href={taMailto}
|
| 64 |
+
className="text-primary hover:underline"
|
| 65 |
+
title={`Email ${course.teachingAssistant.name}`}
|
| 66 |
+
onClick={(e) => e.stopPropagation()}
|
| 67 |
+
>
|
| 68 |
+
{course.teachingAssistant.name}
|
| 69 |
+
</a>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
);
|
| 74 |
+
}
|