Skip to content

Commit

Permalink
Merge branch 'main' into feature/format-homework-content
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBnm committed Jan 20, 2025
2 parents 1e2942b + 212b9ce commit 87dee06
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/components/Global/PapillonPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface PapillonPickerProps {
delay?: number,
direction?: "left" | "right",
animated?: boolean,
onSelectionChange?: (item: string) => unknown
onSelectionChange?: any
}

const PapillonPicker: React.FC<PapillonPickerProps> = ({
Expand Down
1 change: 0 additions & 1 deletion src/services/ecoledirecte/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Period } from "@/services/shared/Period";
import {
type AverageOverview,
type Grade,
GradeInformation,
type GradeValue,
} from "@/services/shared/Grade";
import ecoledirecte, {
Expand Down
50 changes: 31 additions & 19 deletions src/services/pronote/grades.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
import type { PronoteAccount } from "@/stores/account/types";
import type { Period } from "../shared/Period";
import { ErrorServiceUnauthenticated } from "../shared/errors";
import { type AverageOverview, type Grade, GradeInformation, type GradeValue } from "../shared/Grade";
import {
type AverageOverview,
type Grade,
type GradeValue,
} from "../shared/Grade";
import { decodeAttachment } from "./attachment";
import { decodePeriod } from "./period";
import pronote from "pawnote";
import { info } from "@/utils/logger/logger";

const getTab = (account: PronoteAccount): pronote.Tab => {
if (!account.instance)
throw new ErrorServiceUnauthenticated("pronote");
if (!account.instance) throw new ErrorServiceUnauthenticated("pronote");

const tab = account.instance.user.resources[0].tabs.get(pronote.TabLocation.Grades);
const tab = account.instance.user.resources[0].tabs.get(
pronote.TabLocation.Grades
);
if (!tab)
throw new Error("Tu n'as pas accès à l'onglet 'Notes' dans PRONOTE");

return tab;
};

export const getGradesPeriods = (account: PronoteAccount): { periods: Period[], default: string } => {
export const getGradesPeriods = (
account: PronoteAccount
): { periods: Period[]; default: string } => {
const tab = getTab(account);
info("PRONOTE->getGradesPeriods(): OK", "pronote");

return {
default: tab.defaultPeriod!.name,
periods: tab.periods.map(decodePeriod)
periods: tab.periods.map(decodePeriod),
};
};

const decodeGradeValue = (value: pronote.GradeValue | undefined): GradeValue => {
const decodeGradeValue = (
value: pronote.GradeValue | undefined
): GradeValue => {
if (typeof value === "undefined")
return { value: null, disabled: true, status: "unknown" };

Expand All @@ -54,33 +63,35 @@ const decodeGradeValue = (value: pronote.GradeValue | undefined): GradeValue =>
}
};

export const getGradesAndAverages = async (account: PronoteAccount, periodName: string): Promise<{
grades: Grade[],
averages: AverageOverview
export const getGradesAndAverages = async (
account: PronoteAccount,
periodName: string
): Promise<{
grades: Grade[];
averages: AverageOverview;
}> => {
const tab = getTab(account); // Vérifie aussi la validité de `account.instance`.
const period = tab.periods.find(p => p.name === periodName);
if (!period)
throw new Error("La période sélectionnée n'a pas été trouvée.");
const period = tab.periods.find((p) => p.name === periodName);
if (!period) throw new Error("La période sélectionnée n'a pas été trouvée.");

const overview = await pronote.gradesOverview(account.instance!, period);

const averages: AverageOverview = {
classOverall: decodeGradeValue(overview.classAverage),
overall: decodeGradeValue(overview.overallAverage),
subjects: overview.subjectsAverages.map(s => ({
subjects: overview.subjectsAverages.map((s) => ({
classAverage: decodeGradeValue(s.class_average),
color: s.backgroundColor,
max: decodeGradeValue(s.max),
subjectName: s.subject.name,
id: s.subject.id ? s.subject.id.toString() : undefined,
min: decodeGradeValue(s.min),
average: decodeGradeValue(s.student),
outOf: decodeGradeValue(s.outOf)
}))
outOf: decodeGradeValue(s.outOf),
})),
};

const grades: Grade[] = overview.grades.map(g => ({
const grades: Grade[] = overview.grades.map((g) => ({
id: buildLocalID(g),
subjectName: g.subject.name,
subjectId: g.subject.id ? g.subject.id.toString() : undefined,
Expand All @@ -99,10 +110,11 @@ export const getGradesAndAverages = async (account: PronoteAccount, periodName:
student: decodeGradeValue(g.value),
average: decodeGradeValue(g.average),
max: decodeGradeValue(g.max),
min: decodeGradeValue(g.min)
min: decodeGradeValue(g.min),
}));

return { averages, grades };
};

export const buildLocalID = (g: pronote.Grade): string => `${g.subject.name}:${g.date.getTime()}/${g.comment || "none"}`;
export const buildLocalID = (g: pronote.Grade): string =>
`${g.subject.name}:${g.date.getTime()}/${g.comment || "none"}`;
4 changes: 2 additions & 2 deletions src/services/shared/Grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface GradeValue {
value: number | null;

status: string | null;

/**
* Whether the "value" should be counted
* in the average or not.
*/
disabled?: boolean

};

export interface Grade {
Expand Down
4 changes: 2 additions & 2 deletions src/services/skolengo/data/grades.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AverageOverview, Grade, GradeInformation, GradeValue } from "@/services/shared/Grade";
import { AverageOverview, Grade, GradeValue } from "@/services/shared/Grade";
import type { SkolengoAccount } from "@/stores/account/types";
import { getPeriod } from "./period";
import { ErrorServiceUnauthenticated } from "@/services/shared/errors";
import { Evaluation, EvaluationDetail } from "scolengo-api/types/models/Results";
import { Evaluation } from "scolengo-api/types/models/Results";

const SKOLENGO_DEFAULT_SCALE = 20;

Expand Down
2 changes: 1 addition & 1 deletion src/services/skolengo/data/homework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const decodeHomework = (h: HomeworkAssignment): Homework => {
subject: h.subject?.label || "",
attachments: h.attachments?.map(decodeSkoAttachment) || [],
color: h.subject?.color || "#000000",
content:htmlToText(h.html||""),
content: (h.html && htmlToText(h.html || "") !== "") ? htmlToText(h.html) : h.title ?? "",
due: h.dueDateTime ? new Date(h.dueDateTime).getTime() : -1,
done: h.done,
returnType: h.deliverWorkOnline ? HomeworkReturnType.FileUpload : HomeworkReturnType.Paper
Expand Down
4 changes: 3 additions & 1 deletion src/utils/format/format_pronote_news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function parse_news_resume (content: string): string {
const converted = convertHTML(content);
const formatted = converted.replace(/Bonjour,|Bonjour à tous|Bonjour !|Bonsoir|Bonjour|Bonjour à tous, |Bonjour , |Bonsoir, /g, "").replace(/\n/g, "");
const trimmed = formatted.trim();
return trimmed;
const decoma = (trimmed.startsWith(",") ? trimmed.slice(1) : trimmed).trim();
const uppercased = decoma.charAt(0).toUpperCase() + decoma.slice(1);
return uppercased;
}

export default parse_news_resume;
8 changes: 3 additions & 5 deletions src/views/account/Grades/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
} from "@/components/Global/NativeComponents";
import { getSubjectData } from "@/services/shared/Subject";
import { useTheme } from "@react-navigation/native";
import React, { useCallback, useEffect, useLayoutEffect, useState } from "react";
import { Image, ScrollView, Text, View, Platform, TouchableOpacity } from "react-native";
import React, { useEffect, useLayoutEffect, useState } from "react";
import { Image, ScrollView, Text, View, Platform } from "react-native";
import * as StoreReview from "expo-store-review";
import {
Asterisk,
Calculator,
Maximize2,
Scale,
School,
UserMinus,
Expand All @@ -24,7 +23,6 @@ import type { AverageDiffGrade } from "@/utils/grades/getAverages";
import { Screen } from "@/router/helpers/types";
import InsetsBottomView from "@/components/Global/InsetsBottomView";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useSafeAreaInsets } from "react-native-safe-area-context";

const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => {
const { grade, allGrades = [] } = route.params;
Expand Down Expand Up @@ -335,7 +333,7 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => {
}}
numberOfLines={1}
>
{grade.student.disabled ? (grade.student.status === null ? "N. Not" : grade.student.status) : grade.student.value?.toFixed(2)}
{grade.student.disabled ? (grade.student.status === null ? "N. Not" : grade.student.status) : grade.student.value?.toFixed(2)}
</Text>
<Text
style={{
Expand Down
3 changes: 2 additions & 1 deletion src/views/account/Grades/Subject/SubjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, { useEffect, useState } from "react";
import { FlatList, View } from "react-native";
import Reanimated, {
FadeInDown,
FadeInUp,
FadeOutUp,
} from "react-native-reanimated";
import SubjectTitle from "./SubjectTitle";
Expand All @@ -21,12 +20,14 @@ interface SubjectItemProps {
subject: GradesPerSubject;
allGrades: Grade[];
navigation: NativeStackNavigationProp<RouteParameters, keyof RouteParameters>;
index?: number;
}

const SubjectItem: React.FC<SubjectItemProps> = ({
subject,
allGrades,
navigation,
index,
}) => {
const [subjectData, setSubjectData] = useState({
color: "#888888",
Expand Down
2 changes: 1 addition & 1 deletion src/views/account/Homeworks/Homeworks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const WeekView: Screen<"Homeworks"> = ({ route, navigation }) => {
start.setHours(0, 0, 0, 0);
const diff = now.getTime() - start.getTime();
const oneWeek = 1000 * 60 * 60 * 24 * 7;
return Math.floor(diff / oneWeek);
return Math.floor(diff / oneWeek) + 1;
};

const currentWeek = getCurrentWeekNumber();
Expand Down
25 changes: 13 additions & 12 deletions src/views/account/News/Atoms/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation,
<View style={{
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
flex: 1,
gap: 10,
marginBottom: 2,
}}>
{!message.read && !isED && (
<View style={{
width: 8,
height: 8,
width: 9,
height: 9,
borderRadius: 5,
marginTop: 1,
backgroundColor: theme.colors.primary,
}} />
)}
{message.title !== "" && <NativeText
numberOfLines={1}
variant="title"
>
{message.title}
</NativeText>}
</View>
{message.title !== "" && <NativeText
numberOfLines={1}
variant="title"
>
{message.title}
</NativeText>}

{message.content && (
<NativeText
Expand All @@ -72,14 +75,12 @@ const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
marginTop: 5,
}}
>
<NativeText
numberOfLines={1}
variant="subtitle"
style={{
marginTop: 6,
}}
>
{formatDate(message.date)}
</NativeText>
Expand Down

0 comments on commit 87dee06

Please sign in to comment.