|
1 |
| -import React, { useEffect, useState } from "react"; |
| 1 | +import React, { useState } from "react"; |
2 | 2 | import "./App.css";
|
3 |
| -import { Schedule, today } from "./scheduler/Schedule"; |
| 3 | +import { Schedule, getRules } from "./scheduler/Schedule"; |
4 | 4 |
|
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; |
8 | 19 |
|
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; |
17 | 21 |
|
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); |
19 | 32 | const similarRules = Schedule.filter((r) => r.rule === rule.rule);
|
20 | 33 |
|
21 | 34 | return (
|
22 | 35 | <div className="min-w-full min-h-full flex flex-col content-center justify-center pt-20">
|
23 | 36 | <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 | + })} |
25 | 42 | </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}> |
31 | 53 | <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 | + })} |
33 | 60 | </h5>
|
34 | 61 | </div>
|
35 | 62 | ))}
|
36 | 63 | </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> |
37 | 110 | </div>
|
38 | 111 | );
|
39 | 112 | }
|
|
0 commit comments