Skip to content

Commit

Permalink
Merge pull request #244 from PapillonApp/lesson-document-fix
Browse files Browse the repository at this point in the history
feat(ui): Add Screen type to LessonDocument component
  • Loading branch information
tryon-dev authored Oct 1, 2024
2 parents 3ec2c03 + d46a3bc commit d56980e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/views/account/Lessons/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useLayoutEffect, useState } from "react";
import {View, ScrollView, Text, TouchableOpacity, Alert} from "react-native";
import { Homework, HomeworkReturnType } from "@/services/shared/Homework";
import { getSubjectData } from "@/services/shared/Subject";
import { Screen } from "@/router/helpers/types";

import { formatDistance } from "date-fns";
import { fr } from "date-fns/locale";
Expand All @@ -23,17 +24,18 @@ const getDuration = (minutes: number): string => {
return `${durationHours}h ${lz(durationRemainingMinutes)} min`;
};

const LessonDocument = ({ route, navigation }) => {
const LessonDocument: Screen<"LessonDocument"> = ({ route, navigation }) => {
const theme = useTheme();

const lesson: TimetableClass = route.params.lesson || {};
const lesson = route.params.lesson as unknown as TimetableClass;

const [subjectData, setSubjectData] = useState({
color: "#888888", pretty: "Matière inconnue", emoji: "❓",
});

const fetchSubjectData = () => {
const data = getSubjectData(lesson.subject);
console.log("Fetching subject data for", lesson);
const data = getSubjectData(lesson.title || "");
setSubjectData(data);
};

Expand Down Expand Up @@ -62,13 +64,13 @@ const LessonDocument = ({ route, navigation }) => {
locale: fr,
}
) + " (à " + new Date(lesson.startTimestamp).toLocaleTimeString("fr-FR", {hour: "2-digit", minute: "2-digit", hour12: false}) + ")",
enabled: lesson.startTimestamp !== null,
enabled: lesson.startTimestamp != null,
},
{
icon: <Hourglass />,
text: "Durée du cours",
value: getDuration(Math.round((lesson.endTimestamp - lesson.startTimestamp) / 60000)),
enabled: lesson.endTimestamp !== null,
enabled: lesson.endTimestamp != null,
}
]
},
Expand All @@ -79,13 +81,13 @@ const LessonDocument = ({ route, navigation }) => {
icon: <DoorOpen />,
text: "Salle de classe",
value: lesson.room,
enabled: lesson.room !== null,
enabled: lesson.room != null,
},
{
icon: <PersonStanding />,
text: "Professeur",
value: lesson.teacher,
enabled: lesson.teacher !== null,
enabled: lesson.teacher != null,
},
]
},
Expand All @@ -96,7 +98,7 @@ const LessonDocument = ({ route, navigation }) => {
icon: <Info />,
text: "Statut",
value: lesson.status,
enabled: lesson.status !== null,
enabled: lesson.status != null,
},
]
}
Expand Down

0 comments on commit d56980e

Please sign in to comment.