Skip to content

Commit 2fc3f87

Browse files
committed
feat: add logic to change dates
This also hides the rules from future days and has a debug mode
1 parent 6fa13eb commit 2fc3f87

File tree

2 files changed

+96
-23
lines changed

2 files changed

+96
-23
lines changed

src/app/App.tsx

+94-21
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,112 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useState } from "react";
22
import "./App.css";
3-
import { Schedule, today } from "./scheduler/Schedule";
3+
import { Schedule, getRules } from "./scheduler/Schedule";
44

5-
function App() {
6-
const startDate = new Date(2025, 0, 1);
7-
const endDate = new Date(2026, 0, 1);
5+
const CALENDAR = {
6+
January: 31,
7+
February: 28,
8+
March: 31,
9+
April: 30,
10+
May: 31,
11+
June: 30,
12+
July: 31,
13+
August: 31,
14+
September: 30,
15+
October: 31,
16+
November: 30,
17+
December: 31,
18+
} as const;
819

9-
const schedule = [];
10-
for (
11-
let date = startDate, i = 0;
12-
date < endDate;
13-
date.setDate(date.getDate() + 1)
14-
) {
15-
schedule.push(`${date.toDateString()} => ${Schedule[i++].description}`);
16-
}
20+
type MONTH = keyof typeof CALENDAR;
1721

18-
const rule = today();
22+
function App() {
23+
const [debugMode, setDebugMode] = useState(false);
24+
const [month, setMonth] = useState<MONTH>(
25+
() => new Date().toLocaleString("default", { month: "long" }) as MONTH
26+
);
27+
const [day, setDay] = useState(() => new Date().getDate());
28+
const date = new Date(2025, Object.keys(CALENDAR).indexOf(month), day);
29+
const isFuture = !debugMode && date > new Date();
30+
31+
const rule = getRules(date);
1932
const similarRules = Schedule.filter((r) => r.rule === rule.rule);
2033

2134
return (
2235
<div className="min-w-full min-h-full flex flex-col content-center justify-center pt-20">
2336
<h1 className="mb-20 text-5xl font-extrabold text-center">
24-
{new Date().toDateString()}
37+
{date.toLocaleDateString("default", {
38+
month: "long",
39+
day: "numeric",
40+
year: "numeric",
41+
})}
2542
</h1>
26-
<h3 className="mb-10 text-3xl font-bold text-center">{rule.rule}</h3>
27-
<p className="text-center">{rule.description}</p>
28-
<div className="flex min-w-full mt-20 px-50 justify-around">
29-
{similarRules.map((r) => (
30-
<div>
43+
<h2 className="mb-10 text-3xl font-bold text-center">
44+
{isFuture ? "Come back on this day to see its rule" : rule.rule}
45+
</h2>
46+
<p className="text-center mb-10">{isFuture ? "???" : rule.description}</p>
47+
{rule.notes && (
48+
<p className="text-center mb-10">{isFuture ? "???" : rule.notes}</p>
49+
)}
50+
<div className="flex flex-col lg:flex-row min-w-full px-50 justify-around">
51+
{similarRules.map((r, index) => (
52+
<div key={index}>
3153
<h5 className="mb-10 text-xl font-bold text-center">
32-
{r.date.toDateString()}
54+
{isFuture
55+
? "???"
56+
: r.date.toLocaleString("default", {
57+
month: "long",
58+
day: "numeric",
59+
})}
3360
</h5>
3461
</div>
3562
))}
3663
</div>
64+
<div className="flex min-w-full mt-20 px-5 gap-8 justify-around">
65+
<select
66+
className="bg-white
67+
border
68+
border-gray-300
69+
rounded-md
70+
shadow-sm
71+
p-2
72+
w-2/3
73+
text-gray-900"
74+
id="month"
75+
value={month}
76+
onChange={(e) => setMonth(e.target.value as MONTH)}
77+
>
78+
{Object.keys(CALENDAR).map((month) => (
79+
<option key={month}>{month}</option>
80+
))}
81+
</select>
82+
<select
83+
className="bg-white
84+
border
85+
border-gray-300
86+
rounded-md
87+
shadow-sm
88+
p-2
89+
w-1/3
90+
text-gray-900"
91+
id="day"
92+
value={day}
93+
onChange={(e) => setDay(Number(e.target.value))}
94+
>
95+
{Array(CALENDAR[month])
96+
.fill(0)
97+
.map((_, day) => (
98+
<option key={day}>{day + 1}</option>
99+
))}
100+
</select>
101+
</div>
102+
<label className="mt-20 px-5 flex flex-row gap-3">
103+
<input
104+
type="checkbox"
105+
checked={debugMode}
106+
onChange={() => setDebugMode(!debugMode)}
107+
/>
108+
<span className="text-white">Debug mode</span>
109+
</label>
37110
</div>
38111
);
39112
}

src/app/scheduler/Schedule.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ while (!validShuffle) {
8181
validShuffle = validateShuffle(shuffle);
8282
}
8383

84-
export function today() {
85-
return shuffle[dayOfYearIndex(undefined)]
84+
export function getRules(date: Date) {
85+
return shuffle[dayOfYearIndex(date.toDateString())];
8686
}
8787

8888
export const Schedule = shuffle;

0 commit comments

Comments
 (0)