From 7f98642ec9e5d81f1b1d905742ddc6b591ccbcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Mon, 20 Jul 2026 08:32:29 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20formatDurationClock?= =?UTF-8?q?=20function=20and=20update=20duration=20display=20in=20Pomodoro?= =?UTF-8?q?=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/date-picker.tsx | 53 ++++++++++++++++++++--------- src/lib/format.ts | 8 +++++ src/pages/pomodoro-page.tsx | 34 ++++++++++++++---- src/pages/student-pomodoro-page.tsx | 6 ++-- 4 files changed, 76 insertions(+), 25 deletions(-) diff --git a/src/components/ui/date-picker.tsx b/src/components/ui/date-picker.tsx index c4fb286..791496f 100644 --- a/src/components/ui/date-picker.tsx +++ b/src/components/ui/date-picker.tsx @@ -1,6 +1,5 @@ import { For, Show, createEffect, createMemo, createSignal, onCleanup } from "solid-js"; import { Portal } from "solid-js/web"; -import { Button } from "@/components/ui/button"; import { IconCalendar, IconChevronLeft, IconChevronRight } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/cn"; @@ -30,6 +29,10 @@ function sameDay(a: Date | null, b: Date): boolean { return !!a && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate(); } +function isSameDay(a: Date, b: Date): boolean { + return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate(); +} + function monthDays(month: Date): Array { const year = month.getFullYear(); const monthIndex = month.getMonth(); @@ -56,6 +59,7 @@ export function DatePicker(props: { const [position, setPosition] = createSignal({ left: 0, top: 0, width: 288 }); const selected = createMemo(() => parseDate(props.value)); const [month, setMonth] = createSignal(selected() ?? new Date()); + const today = new Date(); const days = createMemo(() => monthDays(month())); const monthLabel = createMemo(() => new Intl.DateTimeFormat(locale(), { month: "long", year: "numeric" }).format(month()), @@ -64,6 +68,7 @@ export function DatePicker(props: { const date = selected(); return date ? new Intl.DateTimeFormat(locale(), { weekday: "long" }).format(date) : ""; }); + const todayLabel = createMemo(() => locale().startsWith("tr") ? "Bugün" : "Today"); const dayHeaders = createMemo(() => { const base = new Date(2024, 0, 1); return Array.from({ length: 7 }, (_, i) => { @@ -96,17 +101,16 @@ export function DatePicker(props: { setPosition({ left, top, width: panelWidth }); }; updatePosition(); - const closeOnOutside = (event: MouseEvent) => { - const target = event.target as Node; - if (root && !root.contains(target) && panel && !panel.contains(target)) setOpen(false); + const closeOnOutside = (event: PointerEvent) => { + if (root && !root.contains(event.target as Node) && panel && !panel.contains(event.target as Node)) setOpen(false); }; window.addEventListener("resize", updatePosition); window.addEventListener("scroll", updatePosition, true); - document.addEventListener("mousedown", closeOnOutside); + document.addEventListener("pointerdown", closeOnOutside); onCleanup(() => { window.removeEventListener("resize", updatePosition); window.removeEventListener("scroll", updatePosition, true); - document.removeEventListener("mousedown", closeOnOutside); + document.removeEventListener("pointerdown", closeOnOutside); }); }); @@ -143,17 +147,19 @@ export function DatePicker(props: {
e.stopPropagation()} >
- +

{monthLabel()}

- +
{(day) => {day}} @@ -163,20 +169,35 @@ export function DatePicker(props: { {(date) => ( }> {(day) => ( - + )} )}
+
diff --git a/src/lib/format.ts b/src/lib/format.ts index 1080f28..2b05094 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -28,6 +28,14 @@ export function formatDurationMinutes(ms: number | null | undefined, locale: Loc return locale === "tr" ? `${Math.round(ms / 60_000)} dk` : `${Math.round(ms / 60_000)} min`; } +export function formatDurationClock(ms: number | null | undefined): string { + if (ms == null) return "--:--"; + const totalSeconds = Math.max(0, Math.floor(ms / 1000)); + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; +} + export function examDurationMs(durationMs: number | null | undefined, startsAt: number | null, endsAt: number | null): number | null { if (durationMs != null) return durationMs; if (startsAt == null || endsAt == null || endsAt <= startsAt) return null; diff --git a/src/pages/pomodoro-page.tsx b/src/pages/pomodoro-page.tsx index f30dc93..0dc3cb3 100644 --- a/src/pages/pomodoro-page.tsx +++ b/src/pages/pomodoro-page.tsx @@ -10,9 +10,11 @@ import { Alert } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { DataTable } from "@/components/ui/data-table"; +import { IconClock } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { createFlash } from "@/lib/flash"; -import { formatDateTime, formatDurationMinutes } from "@/lib/format"; +import { createNow } from "@/lib/create-now"; +import { formatDateTime, formatDurationClock } from "@/lib/format"; import { usePreferences, useT } from "@/stores/preferences-context"; export default function PomodoroPage() { @@ -29,8 +31,13 @@ function PomodoroContent() { const [error, setError] = createSignal(""); const [pending, setPending] = createSignal(false); const [flash, setFlash] = createFlash(); + const now = createNow(1000); const [log, { refetch }] = createResource(() => getPomodoroMe({ limit: 20 })); const running = createMemo(() => log()?.items.find((item) => item.finished_at == null) ?? null); + const runningDuration = createMemo(() => { + const current = running(); + return current ? now() - current.started_at : null; + }); const columns = createMemo>["items"][number]>[]>(() => [ { accessorKey: "started_at", @@ -45,7 +52,7 @@ function PomodoroContent() { { accessorKey: "duration_ms", header: t("pomodoro.duration"), - cell: (cell) => formatDurationMinutes(cell.row.original.duration_ms, locale()), + cell: (cell) => {formatDurationClock(cell.row.original.duration_ms)}, }, ]); @@ -92,10 +99,25 @@ function PomodoroContent() { {error() && {error()}}
-
-

{t("pomodoro.total")}

-

{formatDurationMinutes(log()?.total_focus_ms, locale())}

-
+ +

{t("pomodoro.total")}

+

{formatDurationClock(log()?.total_focus_ms)}

+ + } + > +
+
+ + + + {t("pomodoro.running")} +
+

{formatDurationClock(runningDuration())}

+
+

{t("attempt.status")}

diff --git a/src/pages/student-pomodoro-page.tsx b/src/pages/student-pomodoro-page.tsx index 668a677..f20930e 100644 --- a/src/pages/student-pomodoro-page.tsx +++ b/src/pages/student-pomodoro-page.tsx @@ -12,7 +12,7 @@ import { ErrorAlert } from "@/components/ui/error-alert"; import { IconEye } from "@/components/ui/icons"; import { SidePanel } from "@/components/ui/side-panel"; import { TableRowActions } from "@/components/ui/table-row-actions"; -import { formatDateTime, formatDurationMinutes } from "@/lib/format"; +import { formatDateTime, formatDurationClock } from "@/lib/format"; import { personLabel } from "@/lib/person"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -118,7 +118,7 @@ function StudentPomodoroContent() { { accessorKey: "duration_ms", header: t("pomodoro.duration"), - cell: (cell) => formatDurationMinutes(cell.row.original.duration_ms, locale()), + cell: (cell) => {formatDurationClock(cell.row.original.duration_ms)}, }, ]); @@ -177,7 +177,7 @@ function StudentPomodoroContent() {

{t("pomodoro.total")}

-

{formatDurationMinutes(p().total_focus_ms, locale())}

+

{formatDurationClock(p().total_focus_ms)}