Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
syrflover committed Jul 8, 2024
1 parent 61ea3ce commit 3f1e689
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,31 @@ const dayToNumber = (x: string) => {
}
};

const dayToString = (x: number) => {
switch (x) {
case 0:
return "Sun";
case 1:
return "Mon";
case 2:
return "Tue";
case 3:
return "Wed";
case 4:
return "Thu";
case 5:
return "Fri";
case 6:
return "Sat";
}
};

const IndexPage: React.FC<PageProps> = () => {
const [currentDateTime, setCurrentDateTime] = React.useState(
new Date()
);
const [channels, setChannels] = React.useState<Channel[]>([]);
const [selectedDay, selectDay] = React.useState(
currentDateTime.getDay()
);
const [selectedDay, selectDay] = React.useState(-1);

React.useEffect(() => {
fetch(
Expand Down Expand Up @@ -236,9 +253,23 @@ const IndexPage: React.FC<PageProps> = () => {
console.log(channels);

setChannels(channels);

setTimeout(() => {
selectDay(currentDateTime.getDay() + 4);
}, 5);
});
}, []);

React.useEffect(() => {
const day = dayToString(selectedDay);

if (day) {
document.getElementsByClassName(day).item(0)?.scrollIntoView({
behavior: "smooth",
});
}
}, [selectedDay]);

return (
<main style={pageStyles}>
<h1 style={headingStyles}>
Expand Down Expand Up @@ -293,12 +324,6 @@ const IndexPage: React.FC<PageProps> = () => {
}}
onClick={() => {
selectDay(dayToNumber(day));
document
.getElementsByClassName(day)
.item(0)
?.scrollIntoView({
behavior: "smooth",
});
}}
>
{day}
Expand Down

0 comments on commit 3f1e689

Please sign in to comment.