Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Home Lessons #535

Merged
merged 30 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e461fdd
fix
JyhuKo Dec 20, 2024
4086969
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
29825f9
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
1ba5b29
Create holidayEmoji.ts
JyhuKo Dec 22, 2024
2966671
Update Page.tsx
JyhuKo Dec 22, 2024
ded4123
Update Page.tsx
JyhuKo Dec 22, 2024
85e0021
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
fb88d3b
Update holidayEmoji.ts
JyhuKo Dec 22, 2024
4435864
Update holidayEmoji.ts
JyhuKo Dec 22, 2024
76a1162
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
d705da3
mince
JyhuKo Dec 22, 2024
89a3748
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
49afabe
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
1948762
Update src/utils/format/holidayEmoji.ts
JyhuKo Dec 22, 2024
65ff1a6
Update src/views/account/Home/Elements/TimetableElement.tsx
JyhuKo Dec 22, 2024
d7a3680
Update holidayEmoji.ts
JyhuKo Dec 22, 2024
267fe25
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
52c4382
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
e02fbff
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
a8ae4d7
Update TimetableElement.tsx
JyhuKo Dec 22, 2024
617833f
j ai fais dla merde
JyhuKo Dec 22, 2024
5f4b5c3
plus de jours fériés et nouveaux emojis
JyhuKo Dec 23, 2024
a06b588
Update holidayEmoji.ts
JyhuKo Dec 23, 2024
acbb514
fix wekkend if lessons
JyhuKo Dec 23, 2024
efbedb5
fix Lint
JyhuKo Dec 23, 2024
c892df7
new emojis
JyhuKo Dec 23, 2024
02b3119
Update holidayEmoji.ts
JyhuKo Dec 23, 2024
d204f59
Update src/utils/format/holidayEmoji.ts
JyhuKo Dec 23, 2024
988c04a
Update src/utils/format/holidayEmoji.ts
JyhuKo Dec 23, 2024
532b8db
fix lint
JyhuKo Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/pronote/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const createDiscussionRecipients = async (account: PronoteAccount): Promi
const recipientsALL = await Promise.all([
pronote.EntityKind.Teacher,
pronote.EntityKind.Personal
].map(kind => pronote.newDiscussionRecipients(account.instance!, user, kind)));
].map(kind => pronote.newDiscussionRecipients(account.instance!, kind)));

const recipients = recipientsALL.flat();
info("PRONOTE->createDiscussionRecipients(): OK", "pronote");
Expand Down
54 changes: 54 additions & 0 deletions src/utils/format/holidayEmoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const getHolidayEmoji = (date: Date = new Date()): string => {
const year = date.getFullYear();

const holidays = [
{ start: new Date(`${year}-01-01`), end: new Date(`${year}-01-01`), emoji: "🎉" }, // Nouvel An
{ start: new Date(`${year}-05-01`), end: new Date(`${year}-05-01`), emoji: "🌹" }, // Fête du Travail
{ start: new Date(`${year}-05-08`), end: new Date(`${year}-05-08`), emoji: "🇫🇷" }, // Armistice 1945
{ start: new Date(`${year}-07-14`), end: new Date(`${year}-07-14`), emoji: "🎇" }, // Fête Nationale
{ start: new Date(`${year}-11-01`), end: new Date(`${year}-11-01`), emoji: "🕯️" }, // Toussaint
{ start: new Date(`${year}-11-11`), end: new Date(`${year}-11-11`), emoji: "🕊️" }, // Armistice
{ start: new Date(`${year}-12-25`), end: new Date(`${year}-12-25`), emoji: "🎄" }, // Noël
];

const schoolHolidays = [
{
start: new Date(`${year}-10-19`),
end: new Date(`${year}-11-04`),
emoji: "🍂", // Vacances de la Toussaint
},
{
start: new Date(`${year}-12-21`),
end: new Date(`${year + 1}-01-06`),
emoji: "❄️", // Vacances de Noël
},
{
start: new Date(`${year + 1}-02-08`),
end: new Date(`${year + 1}-03-10`),
emoji: "⛷️", // Vacances d'hiver
},
{
start: new Date(`${year + 1}-04-05`),
end: new Date(`${year + 1}-04-28`),
emoji: "🌸", // Vacances de printemps
},
{
start: new Date(`${year + 1}-07-05`),
end: new Date(`${year + 1}-09-01`),
emoji: "🏖️", // Grandes vacances
},
];

// Combine jours fériés et vacances scolaires
const allPeriods = [...holidays, ...schoolHolidays];

// Vérifie si la date donnée se trouve dans l'une des périodes
for (const period of allPeriods) {
if (date >= period.start && date <= period.end) {
return period.emoji;
}
}

// Emoji par défaut
return "📚";
};
89 changes: 66 additions & 23 deletions src/views/account/Home/Elements/TimetableElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import RedirectButton from "@/components/Home/RedirectButton";
import { updateTimetableForWeekInCache } from "@/services/timetable";
import MissingItem from "@/components/Global/MissingItem";
import { TimetableItem } from "../../Lessons/Atoms/Item";
import { getHolidayEmoji } from "@/utils/format/holidayEmoji";



interface TimetableElementProps {
onImportance: (value: number) => unknown
onImportance: (value: number) => unknown;
}

const TimetableElement: React.FC<TimetableElementProps> = ({ onImportance }) => {
const emoji = getHolidayEmoji();
const account = useCurrentAccount((store) => store.account!);
const timetables = useTimetableStore((store) => store.timetables);

Expand Down Expand Up @@ -57,41 +61,45 @@ const TimetableElement: React.FC<TimetableElementProps> = ({ onImportance }) =>
);
};

const fetchTimetable = async () => {
if (!timetables[currentWeekNumber] && account.instance) {
setLoading(true);
try {
await updateTimetableForWeekInCache(account, currentWeekNumber);
} finally {
setLoading(false);
}
}
const isWeekend = () => {
const today = new Date().getDay();
return today === 6 || today === 0; // 6 = Saturday, 0 = Sunday
};

const isVacation = (courses: TimetableClass[]) =>
courses.length === 1 && courses[0].type === "vacation";

const filterAndSortCourses = (weekCourses: TimetableClass[]): TimetableClass[] => {
const now = Date.now();
const todayCourses = weekCourses
.filter(c => isToday(c.startTimestamp) && c.endTimestamp > now)
.filter((c) => isToday(c.startTimestamp) && c.endTimestamp > now)
.sort((a, b) => a.startTimestamp - b.startTimestamp);

if (todayCourses.length > 0) {
return todayCourses;
}

const tomorrowCourses = weekCourses
.filter(c => isTomorrow(c.startTimestamp))
.filter((c) => isTomorrow(c.startTimestamp))
.sort((a, b) => a.startTimestamp - b.startTimestamp);

if (tomorrowCourses.length > 0) {
return tomorrowCourses.slice(0, 3);
}

return weekCourses
.filter(c => c.startTimestamp > now)
.filter((c) => c.startTimestamp > now)
.sort((a, b) => a.startTimestamp - b.startTimestamp)
.slice(0, 3);
};

const fetchTimetable = async () => {
if (!timetables[currentWeekNumber] && account.instance) {
setLoading(true);
try {
await updateTimetableForWeekInCache(account, currentWeekNumber);
} finally {
setLoading(false);
}
}
};

const updateNextCourses = () => {
if (!account.instance || !timetables[currentWeekNumber]) {
return;
Expand Down Expand Up @@ -134,6 +142,44 @@ const TimetableElement: React.FC<TimetableElementProps> = ({ onImportance }) =>
);
}

if (isWeekend()) {
return (
<NativeList
animated
key="weekend"
entering={FadeInDown.springify().mass(1).damping(20).stiffness(300)}
exiting={FadeOut.duration(300)}
>
<NativeItem animated style={{ paddingVertical: 10 }}>
<MissingItem
emoji="🌴"
title="C'est le week-end !"
description="Profitez de votre week-end, il n'y a pas de cours aujourd'hui."
/>
</NativeItem>
</NativeList>
);
}
JyhuKo marked this conversation as resolved.
Show resolved Hide resolved

if (isVacation(nextCourses)) {
return (
<NativeList
animated
key="vacation"
entering={FadeInDown.springify().mass(1).damping(20).stiffness(300)}
exiting={FadeOut.duration(300)}
>
<NativeItem animated style={{ paddingVertical: 10 }}>
<MissingItem
emoji={emoji}
title="C'est les vacances !"
description="Profitez de vos vacances, à bientôt."
/>
</NativeItem>
</NativeList>
);
}

if (hidden || nextCourses.length === 0) {
return (
<NativeList
Expand All @@ -156,8 +202,8 @@ const TimetableElement: React.FC<TimetableElementProps> = ({ onImportance }) =>
const label = isToday(nextCourses[0].startTimestamp)
? "Emploi du temps"
: isTomorrow(nextCourses[0].startTimestamp)
? "Cours de demain"
: "Prochains cours";
? "Cours de demain"
: "Prochains cours";

JyhuKo marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
Expand All @@ -166,10 +212,7 @@ const TimetableElement: React.FC<TimetableElementProps> = ({ onImportance }) =>
label={label}
trailing={<RedirectButton navigation={PapillonNavigation.current} redirect="Lessons" />}
/>
<Reanimated.View
layout={LinearTransition}
style={{ marginTop: 24, gap: 10 }}
>
<Reanimated.View layout={LinearTransition} style={{ marginTop: 24, gap: 10 }}>
{nextCourses.map((course, index) => (
<React.Fragment key={course.id || index}>
<TimetableItem item={course} index={index} small />
Expand Down
5 changes: 4 additions & 1 deletion src/views/account/Lessons/Atoms/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { Timetable, TimetableClass } from "@/services/shared/Timetable";
import { animPapillon } from "@/utils/ui/animations";
import LessonsLoading from "./Loading";
import MissingItem from "@/components/Global/MissingItem";
import { getHolidayEmoji } from "@/utils/format/holidayEmoji";

const emoji = getHolidayEmoji();

const RefreshControl = createNativeWrapper(RNRefreshControl, {
disallowInterruption: true,
Expand Down Expand Up @@ -120,7 +123,7 @@ export const Page = ({ day, date, current, paddingTop, refreshAction, loading, w
)}

{day.length === 1 && current && !loading && (day[0].type === "vacation" ? <MissingItem
emoji="🏝️"
emoji={emoji}
title="C'est les vacances !"
description="Profitez de vos vacances, à bientôt."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce serait intéressant d'indiquer la durée des vacances:

"Retour en classe le [dernier jour sans cours +1], d'ici là profitez de vos vacances, à bientôt."
Mais sur la page d'accueil juste, dans le petit popup de l'agenda

Et par contre pourquoi pas avoir plus d'infos dans l'agenda du style "Vacances de [nom vacances] du [date début complète (ex: 21 décembre)] au [date fin complète (ex: 6 janvier)]"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juste faire [Dernier jour + 1] ca marchera vraiment ? car le dernier jour c'est pas le vendredi ? et les cours recommence que le lundi, or cela indiquerai le samedi

Copy link

@Nicolasfr340 Nicolasfr340 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui mais en comptant aussi les jours sans cours du coup

En gros il regarde sur les prochains jours après le dernier jour des vacances, il compte le nombre de jours sans cours (ex: 1 ou 2) en partant du premier jour qu'il regarde, et il ajoute le nombre au nombre de jours de vacances, par contre si il ne détecte pas de jours sans cours en partant du début, il ajoute 0 car c'est le nombre de jours consécutifs sans cours à partir du premier jour

Du style les vacances s'arrêtent vendredi, le programme regarde sur les 7 prochains jours, il détecte des jours consécutifs sans cours au début de son échantillon de jours (Donc jour 1 et jour 2 il trouve des jours sans cours) -> il les ajoute au nombre de jours des vacances

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça consommerait trop de ressources réseau un peu inutiles non ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement, même si c'est une bonne idée, cela consommerait beaucoup de ressources et après, ça va prendre trop de temps pour retourner la durée

entering={animPapillon(FadeInDown)}
Expand Down
Loading