Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into feat/scolengo-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
NonozgYtb authored Mar 23, 2024
2 parents 48ff4a9 + 35c8cc8 commit c9e8af6
Show file tree
Hide file tree
Showing 34 changed files with 2,018 additions and 853 deletions.
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ body:
- type: input
attributes:
label: Appareil
placeholder: iPhone 11
placeholder: iPhone 11, Samsung Galaxy S20...
validations:
required: true
- type: input
attributes:
label: Système d`exploitation
placeholder: iOS 16
label: Version du système d`exploitation
placeholder: iOS 17, Android 12...
validations:
required: true
- type: input
attributes:
label: Version
placeholder: '5.0.17 beta'
placeholder: '6.6.3 beta'
value: '6.6.'
validations:
required: true
Expand All @@ -52,8 +52,7 @@ body:
options:
- Application native Android
- Application native iOS
- Développement local (Web)
- Développement local (iOS ou Android)
- Prébuild de développement (iOS/Android)
validations:
required: true
- type: dropdown
Expand All @@ -62,6 +61,7 @@ body:
options:
- 🦋 Pronote
- 🟦 EcoleDirecte
- 🟡 Skolengo
validations:
required: true
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions App.old.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function InsetSettings() {
name="About"
component={AboutScreen}
options={{
headerTitle: 'A propos de Papillon',
headerTitle: 'À propos de Papillon',
headerBackTitle: 'Préférences',
}}
/>
Expand All @@ -343,7 +343,7 @@ function InsetSettings() {
component={DonorsScreen}
options={{
headerTitle: 'Donateurs',
headerBackTitle: 'A propos',
headerBackTitle: 'À propos',
}}
/>
<Stack.Screen
Expand Down
9 changes: 9 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ function App() {
headerBackVisible: false,
},
},
{
name: 'ConsentScreenWithoutAcceptation',
component: require('./views/ConsentScreenWithoutAcceptation').default,
options: {
presentation: 'modal',
headerTitle: 'Termes & conditions',
headerBackVisible: false,
},
},
];

return (
Expand Down
4 changes: 3 additions & 1 deletion fetch/BackgroundFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { BackgroundFetchResult } from 'expo-background-fetch';
import fetchLessons from './background/Lessons';
import fetchHomeworks from './background/Homeworks';
import fetchGrades from './background/Grades';
import fetchCours from './background/BagReminder';
import selfReminder from './background/SelfReminder';

const backgroundFetch = async () => {
console.log('[background fetch] Running background fetch');

await Promise.all([fetchLessons(), fetchHomeworks(), fetchGrades()]);
await Promise.all([fetchLessons(), fetchHomeworks(), fetchGrades(), fetchCours(), selfReminder()]);

return BackgroundFetchResult.NewData;
};
Expand Down
104 changes: 0 additions & 104 deletions fetch/PronoteData/PronoteGrades.js

This file was deleted.

5 changes: 5 additions & 0 deletions fetch/PronoteData/discussions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const discussionsHandler = async (instance?: Pronote): Promise<PapillonDi
content: message.content,
author: message.author.name,
timestamp: message.created.getTime(),
amountOfRecipients: message.amountOfRecipients,
files: message.files.map(file => ({
name: file.name,
url: file.url
}))
});
}

Expand Down
3 changes: 3 additions & 0 deletions fetch/PronoteData/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CachedPapillonGrades, PapillonGradeValue, PapillonGrades } from '.
import AsyncStorage from '@react-native-async-storage/async-storage';
import { type Pronote, PronoteApiGradeType } from 'pawnote';
import { AsyncStoragePronoteKeys } from './connector';
import type { PapillonAttachment } from '../types/attachment';

/**
* Get the state of a grade in an integer form.
Expand Down Expand Up @@ -61,6 +62,8 @@ export const gradesHandler = async (periodName: string, instance?: Pronote, forc
is_bonus: grade.isBonus,
is_optional: grade.isOptional,
is_out_of_20: grade.isOutOf20,
correctionFile: grade.correctionFile as unknown as PapillonAttachment | undefined,
subjectFile: grade.subjectFile as unknown as PapillonAttachment | undefined,
grade: {
value: getGradeState(grade.value),
out_of: getGradeState(grade.outOf),
Expand Down
28 changes: 15 additions & 13 deletions fetch/PronoteData/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ function removeDuplicateCourses(courses: PapillonLesson[]): PapillonLesson[] {
for (let i = 0; i < courses.length; i += 1) {
// if next cours starts at the same time
if (i + 1 < courses.length && courses[i].start === courses[i + 1].start) {
// remove the course with the lowest num
if (courses[i].num < courses[i + 1].num) {
result.splice(i + 1, 1);
} else {
// remove the course that has is_cancelled set to true
if (courses[i].is_cancelled) {
result.splice(i, 1);
} else if (courses[i + 1].is_cancelled) {
result.splice(i + 1, 1);
}
}
else {
// celui ci est en classe absente alors que rien sur pronote
if (i + 1 < courses.length && courses[i].subject?.id === courses[i + 1].subject?.id && courses[i].rooms.join(',') == courses[i + 1].rooms.join(',')) {
// check if difference between the two courses is less than 21 minutes
const diff = new Date(courses[i + 1].start).getTime() - new Date(courses[i].end).getTime();
if (diff < 21 * 60 * 1000) {
// Merge the two courses.
result[i].end = courses[i + 1].end;

if (i + 1 < courses.length && courses[i].subject?.id === courses[i + 1].subject?.id && courses[i].rooms.join(',') == courses[i + 1].rooms.join(',')) {
// check if difference between the two courses is less than 21 minutes
const diff = new Date(courses[i + 1].start).getTime() - new Date(courses[i].end).getTime();
if (diff < 21 * 60 * 1000) {
// Merge the two courses.
result[i].end = courses[i + 1].end;

// Remove the second course.
result.splice(i + 1, 1);
// Remove the second course.
result.splice(i + 1, 1);
}
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions fetch/background/BagReminder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {getContextValues} from '../../utils/AppContext';
import notifee from '@notifee/react-native';
import {PapillonLesson} from '../types/timetable';
import {checkCanNotify, DidNotified, SetNotified} from './Helper';
import formatCoursName from '../../utils/FormatCoursName';

const now = new Date();

const fetchCours = async () => {
if (now.getHours() >= 18 && now.getHours() <= 20) {
console.log('[background fetch] Running cours fetch');
const tomorrow = new Date(now);
tomorrow.setDate(now.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
const tommorowAsString = tomorrow.toISOString().split('T')[0];
let dataInstance = await getContextValues().dataProvider;
await dataInstance.getTimetable(tomorrow).then(timetable => {
console.log('[background fetch] fetched cours');
const cours = timetable.filter(cours => {
if (cours.isCancelled) return false;
if (cours.start.split('T')[0] !== tommorowAsString) return false;
return true;
});
if (cours.length > 0) {
remindBag(cours);
}
});
} else {
console.log('[background fetch] Skipping cours fetch');
}
};

const remindBag = async (lesson: PapillonLesson[]) => {
const tomorrow = new Date(now);
tomorrow.setDate(now.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);

const canNotify: boolean = await checkCanNotify('notifications_BagReminderEnabled');
const didNotify: boolean = await DidNotified('hw_' + tomorrow.getTime());
if (!canNotify || didNotify) return;
var body = '';
var isFirst = true;
lesson.forEach(cours => {
if (!body.includes(cours.subject)) {
let start = new Date(cours.start);
let end = new Date(cours.end);
if (!isFirst) body += '\n';
isFirst = false;
body += `${('0' + start.getHours()).slice(-2)}:${('0' + start.getMinutes()).slice(-2)} - ${('0' + end.getHours()).slice(-2)}:${('0' + end.getMinutes()).slice(-2)}${formatCoursName(cours.subject.name)}`;
}
});
await notifee.displayNotification({
id: 'hw_' + tomorrow.getTime(),
title: '🎒 Il est temps de préparer votre sac pour demain !',
body: body,
android: {
channelId: 'bag-remind',
},
ios: {
sound: 'papillon_ding.wav',
threadId: 'notifications_BagReminderEnabled',
},
});
await SetNotified('hw_' + tomorrow.getTime());
};

export default fetchCours;
13 changes: 7 additions & 6 deletions fetch/background/Grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,24 @@ const sendGradesToSharedGroup = async (grades: PapillonGrades) => {
};

const notifyGrades = async (grades: PapillonGrades[]) => {
let oldGrades = await AsyncStorage.getItem('oldGrades');
let oldGradesData = await AsyncStorage.getItem('oldGrades');
const fullGrades = grades.grades;
const avg = await calculateSubjectAverage(fullGrades);

if (oldGrades === null) {
if (oldGradesData === null) {
await AsyncStorage.setItem('oldGrades', JSON.stringify(fullGrades));
return true;
}

oldGrades = JSON.parse(oldGrades);
const oldGrades = JSON.parse(oldGradesData);

if (oldGrades.length === fullGrades.length) {
return true;
}

// find the difference between the two arrays
const lastGrades = fullGrades.filter((grade) => !oldGrades.includes(grade));
// make a list of the new grades
const lastGrades = fullGrades.filter((grade) => {
return !oldGrades.some((oldGrade) => oldGrade.subject.name === grade.subject.name && oldGrade.date === grade.date && oldGrade.grade.value.value === grade.grade.value.value);
});

for (let i = 0; i < lastGrades.length; i++) {
let lastGrade = lastGrades[i];
Expand Down
Loading

0 comments on commit c9e8af6

Please sign in to comment.