Skip to content

Commit f16e5b8

Browse files
committed
current day influences current task and order of upcoming tasks
1 parent b4cac9f commit f16e5b8

File tree

3 files changed

+43
-47
lines changed

3 files changed

+43
-47
lines changed

client/src/components/ui/focus/taskDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function TaskDisplay({
2121
time: Time;
2222
}) {
2323
return (
24-
<div className="w-100 m-3 flex flex-auto flex-col rounded-3xl bg-indigo-400 p-4 px-3 shadow-md shadow-black/40">
24+
<div className="px-auto m-3 flex w-80 flex-auto flex-col rounded-3xl bg-indigo-400 p-4 shadow-md shadow-black/40">
2525
<div className="flex flex-auto flex-row gap-4 px-3">
2626
<div>{task.name}:</div>
2727
<div>

client/src/components/ui/focus/upcomingTasks.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ export default function UpcomingTasks({ tasks, times }: Tasks) {
3535
const d = new Date();
3636
const cur_time =
3737
d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds();
38-
38+
const cur_d = d.getDay();
3939
let ut = times.filter(
4040
(time) =>
41-
serializeTime(time.start_time) >= cur_time ||
42-
serializeTime(time.end_time) >= cur_time,
41+
!(cur_d == time.day && serializeTime(time.end_time) <= cur_time),
4342
);
4443

45-
ut = ut
46-
.sort((a, b) => {
47-
return serializeTime(a.start_time) - serializeTime(b.start_time);
48-
})
49-
.slice(1);
50-
44+
ut = ut.sort((a, b) => {
45+
return (
46+
serializeTime(a.start_time) +
47+
((a.day + 8 - cur_d) % 8) * 24 * 60 * 60 -
48+
(serializeTime(b.start_time) +
49+
((b.day + 8 - cur_d) % 8) * 24 * 60 * 60)
50+
);
51+
});
5152
setUpcomingTimes(ut);
5253
}
5354

client/src/pages/focus.tsx

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,28 @@ const CountdownTimer = () => {
7777
const d = new Date();
7878
const cur_time =
7979
d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds();
80+
const cur_d = d.getDay();
8081

8182
// filter out finished tasks
8283
upcomingTimes = ts.filter((time) => {
83-
const end_time = serializeTime(time.end_time);
84-
return end_time > cur_time;
84+
return !(cur_d == time.day && serializeTime(time.end_time) <= cur_time);
8585
});
8686

8787
// sort by start time
8888
upcomingTimes = upcomingTimes.sort((a, b) => {
89-
return serializeTime(a.start_time) - serializeTime(b.start_time);
89+
return (
90+
serializeTime(a.start_time) +
91+
((a.day + 8 - cur_d) % 8) * 24 * 60 * 60 -
92+
(serializeTime(b.start_time) + ((b.day + 8 - cur_d) % 8) * 24 * 60 * 60)
93+
);
9094
});
9195

9296
// logic for if there are no tasks currently or at all
9397
if (upcomingTimes.length > 0) {
94-
if (serializeTime(upcomingTimes[0].start_time) < cur_time) {
98+
if (
99+
serializeTime(upcomingTimes[0].start_time) < cur_time &&
100+
upcomingTimes[0].day == cur_d
101+
) {
95102
setCurrentTime(upcomingTimes[0]);
96103
} else {
97104
setCurrentTime(null);
@@ -109,14 +116,6 @@ const CountdownTimer = () => {
109116
}
110117
}
111118

112-
// check for tasks
113-
// direct to make task page if no tasks
114-
// refresh timer to check for tasks
115-
// play timer if there is a current task
116-
117-
// lonk in button
118-
// lonk out
119-
120119
return (
121120
<div className="h-screen bg-slate-800 p-8 font-inter">
122121
<div className="flex flex-col items-center justify-start rounded-xl bg-slate-700 p-8 font-mono text-white shadow-inner shadow-slate-900">
@@ -125,23 +124,19 @@ const CountdownTimer = () => {
125124
<div className="flex flex-col">
126125
<div>
127126
{currentTime ? (
128-
<div>
129-
<TimeDisplay
130-
statusSignal={onTaskEnd}
131-
time={currentTime.end_time}
132-
current={true}
133-
/>
134-
</div>
127+
<TimeDisplay
128+
statusSignal={onTaskEnd}
129+
time={currentTime.end_time}
130+
current={true}
131+
/>
135132
) : (
136133
<>
137134
{nextTime ? (
138-
<div>
139-
<TimeDisplay
140-
statusSignal={onTaskEnd}
141-
time={nextTime.start_time}
142-
current={false}
143-
/>
144-
</div>
135+
<TimeDisplay
136+
statusSignal={onTaskEnd}
137+
time={nextTime.start_time}
138+
current={false}
139+
/>
145140
) : (
146141
<></>
147142
)}
@@ -156,17 +151,17 @@ const CountdownTimer = () => {
156151
)}
157152
</div>
158153
</div>
159-
<div className="justify-top flex flex-col pl-8">
160-
<div className="p-4 font-inter text-xl font-semibold">upcoming</div>
161-
<div>
162-
{times.length > 0 ? (
163-
<>
164-
<UpcomingTasks tasks={tasks} times={times} />
165-
</>
166-
) : (
167-
<></>
168-
)}
169-
</div>
154+
<div>
155+
{times.length > 1 ? (
156+
<div className="justify-top flex flex-col pl-8">
157+
<div className="p-4 font-inter text-2xl font-semibold">
158+
upcoming
159+
</div>
160+
<UpcomingTasks tasks={tasks} times={times} />
161+
</div>
162+
) : (
163+
<></>
164+
)}
170165
</div>
171166
</div>
172167
<div className="p-8">

0 commit comments

Comments
 (0)