Skip to content

Commit

Permalink
Merge pull request #512 from JyhuKo/FixLessonContext
Browse files Browse the repository at this point in the history
Fix Lesson Context
  • Loading branch information
ecnivtwelve authored Dec 26, 2024
2 parents a024fe2 + 248eb01 commit c64422b
Showing 1 changed file with 53 additions and 54 deletions.
107 changes: 53 additions & 54 deletions src/views/account/Lessons/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
fontFamily: "medium",
fontSize: 16,
lineHeight: 22,
}
},
});

const lesson = route.params.lesson as unknown as TimetableClass;
Expand All @@ -69,7 +69,7 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
const openUrl = (url: string) => {
if (
account.service === AccountService.EcoleDirecte &&
Platform.OS === "ios"
Platform.OS === "ios"
) {
getAndOpenFile(account, url);
} else {
Expand All @@ -85,10 +85,10 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
subjects.subjects.filter(
(b) =>
new Date(b.date).getDate() ===
new Date(lesson.startTimestamp).getDate() &&
new Date(b.date).getMonth() ===
new Date(lesson.startTimestamp).getMonth() &&
lesson.subject === b.subject,
new Date(lesson.startTimestamp).getDate() &&
new Date(b.date).getMonth() ===
new Date(lesson.startTimestamp).getMonth() &&
lesson.subject === b.subject,
) ?? [],
);
}, []);
Expand Down Expand Up @@ -122,17 +122,17 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
icon: <Clock />,
text: "Début du cours",
value:
formatDistance(new Date(lesson.startTimestamp), new Date(), {
addSuffix: true,
locale: fr,
}) +
" (à " +
new Date(lesson.startTimestamp).toLocaleTimeString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
}) +
")",
formatDistance(new Date(lesson.startTimestamp), new Date(), {
addSuffix: true,
locale: fr,
}) +
" (à " +
new Date(lesson.startTimestamp).toLocaleTimeString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
}) +
")",
enabled: lesson.startTimestamp != null,
},
{
Expand All @@ -154,7 +154,7 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
value: lesson.url,
enabled: lesson.url != null,
},
]
],
},
{
title: "Contexte",
Expand All @@ -163,25 +163,25 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
icon: <Building />,
text: lesson.building?.includes(",") ? "Bâtiments" : "Bâtiment",
value: lesson.building,
enabled: lesson.building != null,
enabled: Boolean(lesson.building?.trim()), // Check if lesson.building exists, is not null, and not empty
},
{
icon: <DoorOpen />,
text: lesson.room?.includes(",") ? "Salles de classe" : "Salle de classe",
value: lesson.room?.split(", ").join("\n"),
enabled: lesson.room != null,
enabled: Boolean(lesson.room?.trim()), // Check if lesson.room exists, is not null, and not empty
},
{
icon: <PersonStanding />,
text: lesson.teacher?.includes(",") ? "Professeurs" : "Professeur",
value: lesson.teacher || "Aucun",
enabled: lesson.teacher != null,
enabled: Boolean(lesson.teacher?.trim()), // Check if lesson.teacher exists, is not null, and not empty.
},
{
icon: <Users />,
text: lesson.group?.includes(",") ? "Groupes" : "Groupe",
value: lesson.group?.replace(/\[|\]/g, ""),
enabled: lesson.group != null
enabled: Boolean(lesson.group?.trim()), // Check if lesson.group exists, is not null, and not empty
},
],
},
Expand All @@ -207,11 +207,7 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
height={110}
>
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
<View
style={{
marginRight: 4,
}}
>
<View style={{ marginRight: 4 }}>
<Text
style={{
fontSize: 28,
Expand Down Expand Up @@ -252,18 +248,20 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
return (
<View key={index}>
<NativeListHeader label={info.title} key={index} />

<NativeList>
{info.informations.map((item, index) => {
if (!item.enabled) {
return null;
}

return (
<NativeItem
key={index}
icon={item.icon}
onPress={item.value && item.value.startsWith("http") ? () => Linking.openURL(item.value!) : void 0}
onPress={
item.value && item.value.startsWith("http")
? () => Linking.openURL(item.value!)
: void 0
}
>
<NativeText variant="subtitle">{item.text}</NativeText>
<NativeText variant="default">{item.value}</NativeText>
Expand All @@ -278,30 +276,31 @@ const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
<View>
<NativeListHeader label="Contenu de séance" />
<NativeList>
{classSubjects.map((subject, index) => {
return (
<>
<NativeItem key={index}>
<HTMLView value={`<body>${subject.content}</body>`} stylesheet={stylesText} />
{subject.attachments.map((attachment, index) => (
<NativeItem
key={index}
onPress={() =>
openUrl(
`${attachment.name}\\${attachment.id}\\${attachment.kind}`,
)
}
icon={<FileText />}
>
<NativeText variant="title" numberOfLines={2}>
{attachment.name}
</NativeText>
</NativeItem>
))}
</NativeItem>
</>
);
})}
{classSubjects.map((subject, index) => (
<>
<NativeItem key={index}>
<HTMLView
value={`<body>${subject.content}</body>`}
stylesheet={stylesText}
/>
{subject.attachments.map((attachment, idx) => (
<NativeItem
key={idx}
onPress={() =>
openUrl(
`${attachment.name}\\${attachment.id}\\${attachment.kind}`,
)
}
icon={<FileText />}
>
<NativeText variant="title" numberOfLines={2}>
{attachment.name}
</NativeText>
</NativeItem>
))}
</NativeItem>
</>
))}
</NativeList>
</View>
)}
Expand Down

0 comments on commit c64422b

Please sign in to comment.