Skip to content

Commit

Permalink
Merge branch 'dev-channel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Truiteseche committed May 18, 2024
2 parents 6200d66 + 25ca2b1 commit 73d257a
Show file tree
Hide file tree
Showing 42 changed files with 871 additions and 206 deletions.
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ecole-directe-plus",
"version": "0.2.5",
"version": "0.3.0",
"type": "module",
"description": "Ecole Directe plus is a React web app that is designed to replace and improve EcoleDirecte",
"dependencies": {
Expand All @@ -10,6 +10,7 @@
"body-scroll-lock": "^4.0.0-beta.0",
"crypto-js": "^4.1.1",
"dompurify": "^3.1.0",
"js-sha256": "^0.11.0",
"react-content-loader": "^6.2.1",
"react-router-dom": "^6.16.0",
"uuid": "^9.0.1",
Expand Down
File renamed without changes
9 changes: 9 additions & 0 deletions public/images/canardman-sleeping.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 81 additions & 56 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function consoleLogEDPLogo() {

consoleLogEDPLogo();

const currentEDPVersion = "0.2.5";
const currentEDPVersion = "0.3.0";
const apiVersion = "4.53.4";

// secret webhooks
Expand Down Expand Up @@ -936,6 +936,7 @@ export default function App() {

enabledFeatures.moyenneMin = settings.moyenneMin;
enabledFeatures.moyenneMax = settings.moyenneMax;
enabledFeatures.coefficient = settings.coefficientNote;

// add the average of all subjects a special type of chart
for (const period in periods) {
Expand Down Expand Up @@ -964,20 +965,44 @@ export default function App() {
setDefaultPeriod(periods)
}

function sortNextHomeworks(homeworks) { // This function will sort (I would rather call it translate) the EcoleDirecte response to a better js object
function sortNextHomeworks(homeworks) { // This function will sort (I would rather call it translate) the EcoleDirecte response to a better js object
const upcomingAssignments = []
const sortedHomeworks = Object.fromEntries(Object.entries(homeworks).map((day) => {
return [day[0], day[1].map((homework) => {
return [day[0], day[1].map((homework, i) => {
const { codeMatiere, donneLe, effectue, idDevoir, interrogation, matiere, /* rendreEnLigne, documentsAFaire // I don't know what to do with that for now */ } = homework;
return ({
const task = {
id: idDevoir,
subjectCode: codeMatiere,
subject: matiere,
addDate: donneLe,
isInterrogation: interrogation,
isDone: effectue,
})
}

if (interrogation && upcomingAssignments.length < 3) {
upcomingAssignments.push({
date: day[0],
id: idDevoir,
index: i,
subject: matiere,
subjectCode: codeMatiere,
});
}

return task;
})]
}))

if (upcomingAssignments.length > 0) {
let i = 0;
while (upcomingAssignments.length < 3) {
upcomingAssignments.push({
id: "dummy" + i,
});
i++;
}
}
changeUserData("upcomingAssignments", upcomingAssignments)
return sortedHomeworks
}

Expand All @@ -988,9 +1013,9 @@ export default function App() {
if (!aFaire) {
return null;
}

const { donneLe, effectue, contenu, contenuDeSeance, document } = aFaire;
return ({
return {
id: id,
subjectCode: codeMatiere,
subject: matiere,
Expand All @@ -1002,10 +1027,9 @@ export default function App() {
files: document,
sessionContent: contenuDeSeance.contenu,
sessionContentFiles: contenuDeSeance.documents,
})
}
}).filter((item) => item)]
}))
console.log("sortedHomeworks:", sortedHomeworks)
return sortedHomeworks
}

Expand Down Expand Up @@ -1401,56 +1425,57 @@ export default function App() {
} else {
endpoint = "cahierdetexte/" + getISODate(date);
}

fetch(
getProxiedURL(`https://api.ecoledirecte.com/v3/Eleves/${accountsListState[userId].id}/${endpoint}.awp?verbe=get&v=${apiVersion}`, true),
{
method: "POST",
headers: {
"x-token": tokenState
if (accountsListState[activeAccount].firstName === "Guest") {
if (date === "incoming") {
import("./data/homeworks.json").then((module) => {
changeUserData("sortedHomeworks", sortNextHomeworks(module.data))
})
} else {
import("./data/detailed_homeworks.json").then((module) => {
changeUserData("sortedHomeworks", { ...getUserData("sortedHomeworks"), ...sortDayHomeworks({ [module.data.date]: module.data.matieres }) })
})
}
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
} else {
fetch(
getProxiedURL(`https://api.ecoledirecte.com/v3/Eleves/${accountsListState[userId].id}/${endpoint}.awp?verbe=get&v=${apiVersion}`, true),
{
method: "POST",
headers: {
"x-token": tokenState
},
body: "data={}",
signal: controller.signal
},
body: "data={}",
signal: controller.signal
},
)
.then((response) => response.json())
.then((response) => {
let code;
if (accountsListState[activeAccount].firstName === "Guest") {
code = 49969;
} else {
code = response.code;
}
if (code === 200) {
if (date === "incoming") {
changeUserData("sortedHomeworks", { ...sortNextHomeworks(response.data), ...getUserData("sortedHomeworks") })
} else {
changeUserData("sortedHomeworks", { ...getUserData("sortedHomeworks"), ...sortDayHomeworks({ [response.data.date]: response.data.matieres }) })
)
.then((response) => response.json())
.then((response) => {
const code = response.code;
if (code === 200) {
if (date === "incoming") {
changeUserData("sortedHomeworks", { ...sortNextHomeworks(response.data), ...getUserData("sortedHomeworks") })
} else {
changeUserData("sortedHomeworks", { ...getUserData("sortedHomeworks"), ...sortDayHomeworks({ [response.data.date]: response.data.matieres }) })
}
} else if (code === 520 || code === 525) {
// token invalide
console.log("INVALID TOKEN: LOGIN REQUIRED");
requireLogin();
}
} else if (code === 520 || code === 525) {
// token invalide
console.log("INVALID TOKEN: LOGIN REQUIRED");
requireLogin();
} else if (code === 49969) {
let userHomeworks = structuredClone(homeworks);
import("./data/homeworks.json").then((module) => {
userHomeworks[userId] = module.data;
setHomeworks(userHomeworks);
})
}
setTokenState((old) => (response?.token || old));
})
.catch((error) => {
if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
setProxyError(true);
}
})
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
setTokenState((old) => (response?.token || old));
})
.catch((error) => {
if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
setProxyError(true);
}
})
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
}
}

async function fetchHomeworksDone({ tasksDone=[], tasksNotDone=[]}, controller = (new AbortController())) {
async function fetchHomeworksDone({ tasksDone = [], tasksNotDone = [] }, controller = (new AbortController())) {
/**
* Change the state of selected homeworks
* @param tasksDone Tasks switched to true
Expand All @@ -1468,7 +1493,7 @@ export default function App() {
headers: {
"x-token": tokenState
},
body: "data=" + JSON.stringify({idDevoirsEffectues: tasksDone, idDevoirsNonEffectues: tasksNotDone}),
body: "data=" + JSON.stringify({ idDevoirsEffectues: tasksDone, idDevoirsNonEffectues: tasksNotDone }),
signal: controller.signal
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/EdpUnblock/EdpUnblock.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
font-size: var(--font-size-36);
}

.edpu-page main > div > p {
.edpu-page main > div > p, .edpu-page main > div > p span {
max-width: 650px;
font-size: var(--font-size-20);
color: #b4b4f0;
Expand Down
Loading

0 comments on commit 73d257a

Please sign in to comment.