Skip to content
Merged
12 changes: 12 additions & 0 deletions client/src/components/ui/focus/currentTaskTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

export default function CurrentTaskTitle(task_name: string) {
return (
<div className="m-3 flex flex-col items-center justify-center rounded-3xl bg-slate-900 p-10 shadow-xl shadow-black/40">
<h1 className="mb-2 font-inter text-4xl font-semibold">Current Focus</h1>
<div className="rounded-full bg-indigo-400 p-3 px-8 font-inter text-xl font-semibold">
{task_name}
</div>
</div>
);
}
34 changes: 34 additions & 0 deletions client/src/components/ui/focus/taskDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
interface Task {
id: number;
name: string;
description: string;
}

interface Time {
id: number;
day: number;
start_time: string;
end_time: string;
repeating: boolean;
task: number;
}

export default function TaskDisplay({
task,
time,
}: {
task: Task;
time: Time;
}) {
return (
<div className="px-auto m-3 flex flex-auto flex-col rounded-3xl bg-indigo-400 p-4 shadow-md shadow-black/40">
<div className="flex flex-auto flex-row gap-4 px-3">
<div>{task.name}:</div>
<div>
{time.start_time} - {time.end_time}
</div>
</div>
<div className="px-3 italic">{task.description}</div>
</div>
);
}
61 changes: 61 additions & 0 deletions client/src/components/ui/focus/timeDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useEffect, useState } from "react";

import Timer from "./timer";

interface TimeDisplayProps {
statusSignal: (data: string) => void;
time: string;
current: boolean;
}

export default function TimeDisplay({
statusSignal,
time,
current,
}: TimeDisplayProps) {
const [timeRemaining, setTimeRemaining] = useState(0);

useEffect(() => {
const getTimeRemaining = setInterval(() => {
const [Hours, Mins, Sec] = time.split(":").map(Number);

const d = new Date();
const time_serial = Hours * 60 * 60 + Mins * 60 + Sec;
const cur_time =
d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds();

let remaining_time = 0;

remaining_time = time_serial - cur_time;
if (remaining_time <= 1) {
clearInterval(getTimeRemaining);
}

setTimeRemaining(remaining_time);
}, 1000);

return () => clearInterval(getTimeRemaining);
}, [time, timeRemaining]);

useEffect(() => {
if (timeRemaining <= 1) {
statusSignal("finished");
}
}, [timeRemaining, statusSignal]);

return (
<div className="m-3 flex flex-col items-center justify-center rounded-3xl bg-slate-900 p-10 shadow-xl shadow-black/40">
{current ? (
<>
<h1 className="mb-2 font-inter text-4xl font-semibold">Timer</h1>
</>
) : (
<>
<h1 className="mb-2 font-inter text-4xl font-semibold">Next Task</h1>
</>
)}
<div className="time_left">{Timer(timeRemaining)}</div>
<div></div>
</div>
);
}
33 changes: 33 additions & 0 deletions client/src/components/ui/focus/timer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const Timer = (timeRemaining: number) => {
const formatTime = (time: number) => {
const seconds = Math.floor(time % 60);
const minutes = Math.floor((time / 60) % 60);
const hours = Math.floor((time / (60 * 60)) % 24);

return (
<div className="countdown-display">
<div className="countdown-value">
{hours > 0 ? (
<>
{hours.toString()}
<span>:</span>
</>
) : (
<></>
)}
{minutes.toString().padStart(2, "0")}
<span>:</span>
{seconds.toString().padStart(2, "0")}
</div>
</div>
);
};

return (
<div className="rounded-full bg-indigo-400 p-3 px-8 font-inter text-xl font-semibold">
{formatTime(timeRemaining)}
</div>
);
};

export default Timer;
71 changes: 71 additions & 0 deletions client/src/components/ui/focus/upcomingTasks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useEffect, useState } from "react";

import TaskDisplay from "./taskDisplay";

interface Task {
id: number;
name: string;
description: string;
}

interface Time {
id: number;
day: number;
start_time: string;
end_time: string;
repeating: boolean;
task: number;
}

interface Tasks {
tasks: Task[];
times: Time[];
}

function serializeTime(time: string) {
const [Hours, Mins, Sec] = time.split(":").map(Number);
return Hours * 60 * 60 + Mins * 60 + Sec;
}

export default function UpcomingTasks({ tasks, times }: Tasks) {
const [upcomingTimes, setUpcomingTimes] = useState<Time[]>([]);

useEffect(() => {
function sortTimes() {
const d = new Date();
const cur_time =
d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds();
const cur_d = d.getDay();
let ut = times.filter(
(time) =>
!(cur_d == time.day && serializeTime(time.end_time) <= cur_time),
);

ut = ut.sort((a, b) => {
return (
serializeTime(a.start_time) +
((a.day + 8 - cur_d) % 8) * 24 * 60 * 60 -
(serializeTime(b.start_time) +
((b.day + 8 - cur_d) % 8) * 24 * 60 * 60)
);
});
setUpcomingTimes(ut);
}

sortTimes();
}, [times, tasks]);

return (
<div className="rounded-2xl bg-slate-900 p-2 py-3 shadow-xl shadow-black/40">
<div className="scrollbar h-[285px] w-96 overflow-y-auto overflow-x-hidden">
{upcomingTimes.map((time: Time) => (
<TaskDisplay
task={tasks.filter((task) => task.id === time.task)[0]}
time={time}
key={time.id}
/>
))}
</div>
</div>
);
}
46 changes: 46 additions & 0 deletions client/src/components/ui/refresh.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interface requi {
loading: boolean;
update: () => void;
}

export default function Refresh({ loading, update }: requi) {
return (
<div>
{loading ? (
<div>
<button
disabled
type="button"
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"
>
<svg
aria-hidden="true"
role="status"
className="me-2 h-4 w-4 animate-spin text-white"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
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"
fill="#E5E7EB"
/>
<path
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"
fill="currentColor"
/>
</svg>
Loading...
</button>
</div>
) : (
<button
onClick={update}
className="rounded-full bg-indigo-400 p-3 px-8 hover:bg-indigo-500"
>
refresh
</button>
)}
</div>
);
}
Loading
Loading