Skip to content

Commit

Permalink
Merge branch 'main' into feat/background
Browse files Browse the repository at this point in the history
  • Loading branch information
Kgeek33 committed Jan 20, 2025
2 parents 5dedb41 + 212b9ce commit 23d3af4
Show file tree
Hide file tree
Showing 34 changed files with 770 additions and 456 deletions.
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const unusedImports = require("eslint-plugin-unused-imports");
const typescript = require("@typescript-eslint/parser");

module.exports = [
{ // Ignored directory
ignores: [
"**/node_modules/",
"**/android/",
"**/ios/",
"**/.*"
]
},
{ // Apply to `cjs`, `.mjs` and `.js` files.
files: ["**/*.?([cm])js?(x)"]
},
Expand Down
9 changes: 5 additions & 4 deletions src/components/Global/PapillonPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import { NativeText } from "./NativeComponents";
import { BlurView } from "expo-blur";
import { Check } from "lucide-react-native";

type PickerData = string[] | { label: string, icon?: JSX.Element, onPress: () => unknown }[];
export type PickerDataItem = { index?: number, label: string, icon?: JSX.Element, onPress?: () => unknown };
export type PickerData = string[] | PickerDataItem[];

interface PapillonPickerProps {
children: React.ReactNode
data: PickerData
selected?: string
selected?: string | PickerDataItem
contentContainerStyle?: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>
delay?: number,
direction?: "left" | "right",
animated?: boolean,
onSelectionChange?: (item: string) => unknown
onSelectionChange?: any
}

const PapillonPicker: React.FC<PapillonPickerProps> = ({
Expand Down Expand Up @@ -204,4 +205,4 @@ const styles = StyleSheet.create({
},
});

export default PapillonPicker;
export default PapillonPicker;
2 changes: 1 addition & 1 deletion src/components/Grades/GradeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const GradeModal: React.FC<GradeModalProps> = ({
await FileSystem.writeAsStringAsync(fileUri, imageBase64, { encoding: FileSystem.EncodingType.Base64 });
const asset = await MediaLibrary.createAssetAsync(fileUri);
await MediaLibrary.createAlbumAsync("Download", asset, false);
Alert.alert("Image sauvegardée", "L'image a été sauvegardée dans votre galerie.");
Alert.alert("Image sauvegardée", "L'image a été sauvegardée dans ta galerie.");
} catch (error) {
console.error("Failed to save image:", error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/ApparenceContainerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ApparenceContainerCard = () => {
Mode d'affichage
</NativeText>
<NativeText variant="subtitle">
Par défaut, Papillon s'adapte à votre thème système. Mais vous pouvez choisir un thème clair ou sombre.
Par défaut, Papillon s'adapte à ton thème système. Mais tu peux choisir un thème clair ou sombre.
</NativeText>
</NativeItem>
</NativeList>
Expand Down
2 changes: 1 addition & 1 deletion src/consts/DefaultTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const defaultTabs = [
{
tab: "Evaluation",
label: "Compétences",
description: "Vos compétences et évaluations",
description: "Tes compétences et évaluations",
icon: require("@/../assets/lottie/tab_evaluations.json"),
enabled: true,
}
Expand Down
15 changes: 7 additions & 8 deletions 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 All @@ -26,27 +25,27 @@ const decodeGradeValue = (
value: ecoledirecte.GradeValue | undefined,
): GradeValue => {
if (typeof value === "undefined")
return { value: null, disabled: true };
return { value: null, disabled: true, status: null };

switch (value.kind) {
case GradeKind.Grade:
return { value: value.points ?? 0, disabled: false };
return { value: value.points ?? 0, disabled: false, status: null };
case GradeKind.Absent:
return { value: value.points ?? 0, disabled: true, information: GradeInformation.Absent };
return { value: value.points ?? 0, disabled: true, status: "Abs" };
case GradeKind.Exempted:
return { value: value.points ?? 0, disabled: true, information: GradeInformation.Exempted };
return { value: value.points ?? 0, disabled: true, status: "Disp" };
case GradeKind.NotGraded:
return { value: value.points ?? 0, disabled: true, information: GradeInformation.NotGraded };
return { value: value.points ?? 0, disabled: true, status: "N. Not" };
default:
return { value: value.points ?? 0, disabled: true };
return { value: value.points ?? 0, disabled: true, status: null };
}
};

const getGradeValue = (value: number | string | undefined): GradeValue => {
return {
disabled: false,
value: value ? Number(value) : 0,
information: undefined,
status: null,
};
};

Expand Down
8 changes: 4 additions & 4 deletions src/services/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export async function updateGradesAndAveragesInCache <T extends Account> (accoun
let grades: Grade[] = [];
let averages: AverageOverview = {
subjects: [],
overall: { value: null, disabled: true },
classOverall: { value: null, disabled: true }
overall: { value: null, disabled: true, status: null },
classOverall: { value: null, disabled: true, status: null}
};

try {
Expand Down Expand Up @@ -100,8 +100,8 @@ export async function updateGradesAndAveragesInCache <T extends Account> (accoun
grades = [];
averages = {
subjects: [],
overall: { value: 0, disabled: true },
classOverall: { value: 0, disabled: true }
overall: { value: 0, disabled: true, status: null },
classOverall: { value: 0, disabled: true, status: null }
};
}

Expand Down
14 changes: 14 additions & 0 deletions src/services/iutlan/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export const saveIUTLanGrades = async (account: LocalAccount): Promise<{
classOverall: {
value: null,
disabled: true,
status: null,
},
overall: {
value: null,
disabled: true,
status: null,
},
subjects: []
};
Expand All @@ -63,24 +65,29 @@ export const saveIUTLanGrades = async (account: LocalAccount): Promise<{
student: {
value: parseFloat(note.note.value),
disabled: parsedStudent === null || isNaN(parsedStudent),
status: null,
},
min: {
value: parseFloat(note.note.min),
disabled: parsedMin === null || isNaN(parsedMin),
status: null,
},
max: {
value: parseFloat(note.note.max),
disabled: parsedMax === null || isNaN(parsedMax),
status: null,
},
average: {
value: parseFloat(note.note.moy),
disabled: parsedAverage === null || isNaN(parsedAverage),
status: null,
},

id: uuid(),
outOf: {
value: 20,
disabled: false,
status: null,
},
description: note.description,
timestamp: new Date(note.date).getTime(),
Expand Down Expand Up @@ -112,24 +119,29 @@ export const saveIUTLanGrades = async (account: LocalAccount): Promise<{
classAverage: {
value: classAverage,
disabled: false,
status: null,
},
color: "#888888",
max: {
value: max,
disabled: false,
status: null,
},
subjectName: subject.name,
min: {
value: min,
disabled: false,
status: null,
},
average: {
value: average,
disabled: false,
status: null,
},
outOf: {
value: 20,
disabled: false,
status: null,
},
});
});
Expand All @@ -144,10 +156,12 @@ export const saveIUTLanGrades = async (account: LocalAccount): Promise<{
classOverall: {
value: null,
disabled: true,
status: null,
},
overall: {
value: null,
disabled: true,
status: null,
},
subjects: []
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/pronote/evaluations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getTab = (account: PronoteAccount): pronote.Tab => {

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

return tab;
};
Expand Down
70 changes: 41 additions & 29 deletions src/services/pronote/grades.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,97 @@
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 };
return { value: null, disabled: true, status: "unknown" };

switch (value.kind) {
case pronote.GradeKind.Grade:
return { value: value.points, disabled: false };
return { value: value.points ?? 0, disabled: false, status: null };
case pronote.GradeKind.Absent:
return { value: null, disabled: true, information: GradeInformation.Absent };
return { value: null, disabled: true, status: "Abs" };
case pronote.GradeKind.Exempted:
return { value: null, disabled: true, information: GradeInformation.Exempted };
return { value: null, disabled: true, status: "Disp" };
case pronote.GradeKind.NotGraded:
return { value: null, disabled: true, information: GradeInformation.NotGraded };
return { value: null, disabled: true, status: "N. Not" };
case pronote.GradeKind.Unfit:
return { value: null, disabled: true, information: GradeInformation.Unfit };
return { value: null, disabled: true, status: null };
case pronote.GradeKind.Unreturned:
return { value: null, disabled: true, information: GradeInformation.Unreturned };
return { value: null, disabled: true, status: null };
case pronote.GradeKind.AbsentZero:
return { value: 0, disabled: false, information: GradeInformation.Absent };
return { value: 0, disabled: false, status: "Abs" };
case pronote.GradeKind.UnreturnedZero:
return { value: 0, disabled: false, information: GradeInformation.Unreturned };
return { value: 0, disabled: false, status: null };
default:
return { value: null, disabled: true };
return { value: null, disabled: true, status: null };
}
};

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"}`;
3 changes: 3 additions & 0 deletions src/services/shared/Grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ 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
Loading

0 comments on commit 23d3af4

Please sign in to comment.