Skip to content

Commit

Permalink
fix(web): remove the -1 offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited authored Sep 22, 2023
1 parent df32168 commit 8b02914
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
40 changes: 37 additions & 3 deletions packages/website/src/components/Timetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,43 @@ const Timetable: Component<ITimetable> = (props) => {
const today = new Date();
const today_index = today.getDate();

console.log(props.lessons)

// is the lesson is for today (look at the day)
const lessons_of_today = () => props.lessons.filter(
lesson => new Date(lesson.start_date).getDate() === today_index
);
).filter(lesson => {
let isForG1A = false;

switch (lesson.type) {
case "TP":
// We only want to keep the TP lessons that are
// for the subgroup A and the group 1.
if (lesson.group.sub === 0 && lesson.group.main === 1) {
isForG1A = true;
}
break;

// Since TD lessons are the whole group, we don't
// need to check the subgroup.
case "TD":
// We only want to keep the TD lessons that are
// for the group 1.
if (lesson.group.main === 1) {
isForG1A = true;
}
break;

// Since CM lessons are for the whole year, we don't
// need to check the group and subgroup.
case "CM":
isForG1A = true;
break;
}

return isForG1A;

})

const start_date = () => new Date(props.header.start_date);
const end_date = () => new Date(props.header.end_date)
Expand All @@ -18,8 +51,9 @@ const Timetable: Component<ITimetable> = (props) => {
<For each={lessons_of_today()}>
{lesson => (
<div>
<p>{new Date(lesson.start_date).getHours()}:{new Date(lesson.start_date).getMinutes()}</p>
<p>{lesson.content.room}</p>
{lesson.start_date}
<p>{new Date(lesson.start_date).getHours()}:{new Date(lesson.start_date).getMinutes().toString().padStart(2, "0")}</p>
<p>{lesson.type}: {lesson.content.room}</p>
</div>
)}
</For>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Page: Component = () => {
const [latest, setLatest] = createSignal<ITimetable | null>(null);

onMount(async () => {
const response = await fetch("/api/latest/" + state.year);
const response = await fetch("/api/A1/3");
const json = await response.json();
setLatest(json.data as ITimetable);
});
Expand Down

0 comments on commit 8b02914

Please sign in to comment.