Skip to content

Commit b4cac9f

Browse files
committed
displays upcoming tasks next to timer
1 parent 9b3b3d4 commit b4cac9f

10 files changed

Lines changed: 209 additions & 218 deletions

File tree

client/src/components/ui/countdown.tsx

Lines changed: 0 additions & 59 deletions
This file was deleted.

client/src/components/ui/currentTask.tsx

Lines changed: 0 additions & 104 deletions
This file was deleted.

client/src/components/ui/taskDisplay.tsx renamed to client/src/components/ui/focus/currentTaskTitle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22

3-
export default function TaskDisplay(task_name: string) {
3+
export default function CurrentTaskTitle(task_name: string) {
44
return (
55
<div className="m-3 flex flex-col items-center justify-center rounded-3xl bg-slate-900 p-10 shadow-xl shadow-black/40">
66
<h1 className="mb-2 font-inter text-4xl font-semibold">Current Focus</h1>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
interface Task {
2+
id: number;
3+
name: string;
4+
description: string;
5+
}
6+
7+
interface Time {
8+
id: number;
9+
day: number;
10+
start_time: string;
11+
end_time: string;
12+
repeating: boolean;
13+
task: number;
14+
}
15+
16+
export default function TaskDisplay({
17+
task,
18+
time,
19+
}: {
20+
task: Task;
21+
time: Time;
22+
}) {
23+
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">
25+
<div className="flex flex-auto flex-row gap-4 px-3">
26+
<div>{task.name}:</div>
27+
<div>
28+
{time.start_time} - {time.end_time}
29+
</div>
30+
</div>
31+
<div className="px-3 italic">{task.description}</div>
32+
</div>
33+
);
34+
}
File renamed without changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { useEffect, useState } from "react";
2+
3+
import TaskDisplay from "./taskDisplay";
4+
5+
interface Task {
6+
id: number;
7+
name: string;
8+
description: string;
9+
}
10+
11+
interface Time {
12+
id: number;
13+
day: number;
14+
start_time: string;
15+
end_time: string;
16+
repeating: boolean;
17+
task: number;
18+
}
19+
20+
interface Tasks {
21+
tasks: Task[];
22+
times: Time[];
23+
}
24+
25+
function serializeTime(time: string) {
26+
const [Hours, Mins, Sec] = time.split(":").map(Number);
27+
return Hours * 60 * 60 + Mins * 60 + Sec;
28+
}
29+
30+
export default function UpcomingTasks({ tasks, times }: Tasks) {
31+
const [upcomingTimes, setUpcomingTimes] = useState<Time[]>([]);
32+
33+
useEffect(() => {
34+
function sortTimes() {
35+
const d = new Date();
36+
const cur_time =
37+
d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds();
38+
39+
let ut = times.filter(
40+
(time) =>
41+
serializeTime(time.start_time) >= cur_time ||
42+
serializeTime(time.end_time) >= cur_time,
43+
);
44+
45+
ut = ut
46+
.sort((a, b) => {
47+
return serializeTime(a.start_time) - serializeTime(b.start_time);
48+
})
49+
.slice(1);
50+
51+
setUpcomingTimes(ut);
52+
}
53+
54+
sortTimes();
55+
}, [times, tasks]);
56+
57+
return (
58+
<div className="rounded-2xl bg-slate-900 p-2 py-3 shadow-xl shadow-black/40">
59+
<div className="w-100 scrollbar h-[285px] overflow-y-auto">
60+
{upcomingTimes.map((time: Time) => (
61+
<TaskDisplay
62+
task={tasks.filter((task) => task.id === time.task)[0]}
63+
time={time}
64+
key={time.id}
65+
/>
66+
))}
67+
</div>
68+
</div>
69+
);
70+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interface requi {
2+
loading: boolean;
3+
update: () => void;
4+
}
5+
6+
export default function Refresh({ loading, update }: requi) {
7+
return (
8+
<div>
9+
{loading ? (
10+
<div>
11+
<button
12+
disabled
13+
type="button"
14+
className="focus:ring-brand-medium shadow-xs rounded-base box-border inline-flex items-center rounded-full border border-transparent bg-indigo-500 px-4 py-2.5 text-sm font-medium leading-5 hover:bg-indigo-600 focus:outline-none focus:ring-4"
15+
>
16+
<svg
17+
aria-hidden="true"
18+
role="status"
19+
className="me-2 h-4 w-4 animate-spin text-white"
20+
viewBox="0 0 100 101"
21+
fill="none"
22+
xmlns="http://www.w3.org/2000/svg"
23+
>
24+
<path
25+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
26+
fill="#E5E7EB"
27+
/>
28+
<path
29+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
30+
fill="currentColor"
31+
/>
32+
</svg>
33+
Loading...
34+
</button>
35+
</div>
36+
) : (
37+
<button
38+
onClick={update}
39+
className="rounded-full bg-indigo-400 p-3 px-8 hover:bg-indigo-500"
40+
>
41+
refresh
42+
</button>
43+
)}
44+
</div>
45+
);
46+
}

0 commit comments

Comments
 (0)