@burdenoff/microfe-timecampus 2026.1031.11 → 2026.1031.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/timecampus/TimeCampusRoot.d.ts.map +1 -1
- package/dist/timecampus/TimeCampusRoot.js +121 -80
- package/dist/timecampus/TimeCampusRoot.js.map +1 -1
- package/dist/timecampus/TimeCampusRoutes.d.ts.map +1 -1
- package/dist/timecampus/TimeCampusRoutes.js +24 -5
- package/dist/timecampus/TimeCampusRoutes.js.map +1 -1
- package/dist/timecampus/pages/lifetime/LifeBalancePage.d.ts.map +1 -1
- package/dist/timecampus/pages/lifetime/LifeBalancePage.js +34 -31
- package/dist/timecampus/pages/lifetime/LifeBalancePage.js.map +1 -1
- package/dist/timecampus/pages/mobile/MobileLifeBalancePage.d.ts +8 -0
- package/dist/timecampus/pages/mobile/MobileLifeBalancePage.d.ts.map +1 -0
- package/dist/timecampus/pages/mobile/MobileLifeBalancePage.js +224 -0
- package/dist/timecampus/pages/mobile/MobileLifeBalancePage.js.map +1 -0
- package/dist/timecampus/pages/mobile/MobileScreen.d.ts +32 -0
- package/dist/timecampus/pages/mobile/MobileScreen.d.ts.map +1 -0
- package/dist/timecampus/pages/mobile/MobileScreen.js +89 -0
- package/dist/timecampus/pages/mobile/MobileScreen.js.map +1 -0
- package/dist/timecampus/pages/mobile/MobileTimelinePage.d.ts +8 -0
- package/dist/timecampus/pages/mobile/MobileTimelinePage.d.ts.map +1 -0
- package/dist/timecampus/pages/mobile/MobileTimelinePage.js +341 -0
- package/dist/timecampus/pages/mobile/MobileTimelinePage.js.map +1 -0
- package/dist/timecampus/pages/mobile/MobileTimerPage.d.ts +8 -0
- package/dist/timecampus/pages/mobile/MobileTimerPage.d.ts.map +1 -0
- package/dist/timecampus/pages/mobile/MobileTimerPage.js +226 -0
- package/dist/timecampus/pages/mobile/MobileTimerPage.js.map +1 -0
- package/dist/timecampus/pages/mobile/mobileModel.d.ts +121 -0
- package/dist/timecampus/pages/mobile/mobileModel.d.ts.map +1 -0
- package/dist/timecampus/pages/mobile/mobileModel.js +127 -0
- package/dist/timecampus/pages/mobile/mobileModel.js.map +1 -0
- package/dist/timecampus/pages/pomodoro/PomodoroPage.d.ts.map +1 -1
- package/dist/timecampus/pages/pomodoro/PomodoroPage.js +46 -44
- package/dist/timecampus/pages/pomodoro/PomodoroPage.js.map +1 -1
- package/dist/timecampus/pages/time/TimerPage.d.ts.map +1 -1
- package/dist/timecampus/pages/time/TimerPage.js +34 -32
- package/dist/timecampus/pages/time/TimerPage.js.map +1 -1
- package/dist/timecampus/pages/timeline/TimelinePage.d.ts.map +1 -1
- package/dist/timecampus/pages/timeline/TimelinePage.js +324 -319
- package/dist/timecampus/pages/timeline/TimelinePage.js.map +1 -1
- package/dist/timecampus/types/index.d.ts +5 -0
- package/dist/timecampus/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileTimerPage.js","names":[],"sources":["../../../../src/timecampus/pages/mobile/MobileTimerPage.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { Play, Settings, Square } from \"lucide-react\";\nimport { GlassCard } from \"@burdenoff/fe-libs/ui\";\nimport {\n useTimeCampus,\n useTimeCampusNavigate,\n} from \"../../providers/TimeCampusProvider\";\nimport { useTr } from \"../../hooks\";\nimport { cn } from \"../../utils/helpers\";\nimport { chartTokens } from \"../../components/charts/chartTheme\";\nimport {\n useCompletePomodoroSessionMutation,\n useGetActivePomodoroSessionQuery,\n useGetPomodoroSettingsQuery,\n useGetPomodoroStatsQuery,\n useInterruptPomodoroSessionMutation,\n useListPomodoroGoalsQuery,\n useStartPomodoroSessionMutation,\n} from \"@/generated/wspace-operations\";\nimport { PomodoroSessionType } from \"@/generated/wspace-types\";\nimport { durationForSession } from \"../pomodoro/pomodoroDuration\";\nimport { MobileScreen } from \"./MobileScreen\";\nimport {\n formatCountdown,\n localDayBounds,\n remainingSeconds,\n ringFraction,\n toLocalDateKey,\n todaysGoal,\n} from \"./mobileModel\";\n\ntype Mode = \"work\" | \"break\";\n\nconst RING_RADIUS = 46;\nconst RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;\nconst REFETCH = [\n \"GetActivePomodoroSession\",\n \"GetPomodoroStats\",\n \"ListPomodoroGoals\",\n \"ListPomodoroSessions\",\n];\n\nfunction modeOf(type: PomodoroSessionType | undefined): Mode {\n return type === PomodoroSessionType.Focus || type === undefined\n ? \"work\"\n : \"break\";\n}\n\n/**\n * Phone focus timer: one big countdown ring, a Work/Break switch and\n * thumb-sized Start/Stop controls. Sessions are real pomodoro sessions on the\n * backend, so a session started here continues on the desktop Pomodoro page\n * (and vice versa).\n */\nexport function MobileTimerPage() {\n const { workspaceId = \"\" } = useTimeCampus();\n const navigate = useTimeCampusNavigate();\n const t = useTr();\n\n const today = useMemo(() => localDayBounds(toLocalDateKey(new Date())), []);\n\n const { data: activeData, loading: activeLoading } =\n useGetActivePomodoroSessionQuery({\n variables: { workspaceId },\n skip: !workspaceId,\n fetchPolicy: \"cache-and-network\",\n });\n const { data: settingsData } = useGetPomodoroSettingsQuery({\n variables: { workspaceId },\n skip: !workspaceId,\n });\n const { data: statsData } = useGetPomodoroStatsQuery({\n variables: { workspaceId, startDate: today.from, endDate: today.to },\n skip: !workspaceId,\n fetchPolicy: \"cache-and-network\",\n });\n const { data: goalsData } = useListPomodoroGoalsQuery({\n variables: { workspaceId },\n skip: !workspaceId,\n });\n\n const [startSession, { loading: starting, error: startError }] =\n useStartPomodoroSessionMutation();\n const [completeSession] = useCompletePomodoroSessionMutation();\n const [interruptSession, { loading: stopping }] =\n useInterruptPomodoroSessionMutation();\n\n const settings = settingsData?.pomodoroSettings ?? null;\n const active =\n activeData?.activePomodoroSession &&\n !activeData.activePomodoroSession.completed &&\n !activeData.activePomodoroSession.interrupted\n ? activeData.activePomodoroSession\n : null;\n\n const [mode, setMode] = useState<Mode>(\"work\");\n const selectedType =\n mode === \"work\"\n ? PomodoroSessionType.Focus\n : PomodoroSessionType.ShortBreak;\n const runningType = active?.type ?? selectedType;\n const total = active?.duration ?? durationForSession(runningType, settings);\n\n const [now, setNow] = useState(() => Date.now());\n useEffect(() => {\n if (!active) return;\n setNow(Date.now());\n const interval = window.setInterval(() => setNow(Date.now()), 1000);\n return () => window.clearInterval(interval);\n }, [active]);\n\n const remaining = active\n ? remainingSeconds(active, durationForSession(active.type, settings), now)\n : durationForSession(selectedType, settings);\n\n // Finish the session on the server exactly once when the countdown runs out.\n const completingRef = useRef<string | null>(null);\n const finish = useCallback(\n async (id: string) => {\n if (completingRef.current === id) return;\n completingRef.current = id;\n try {\n await completeSession({\n variables: { id, workspaceId },\n refetchQueries: REFETCH,\n awaitRefetchQueries: true,\n });\n } finally {\n completingRef.current = null;\n }\n },\n [completeSession, workspaceId],\n );\n useEffect(() => {\n if (active && remaining <= 0) void finish(active.id);\n }, [active, remaining, finish]);\n\n const handleStart = async () => {\n if (!workspaceId || active) return;\n await startSession({\n variables: { input: { workspaceId, type: selectedType } },\n refetchQueries: REFETCH,\n awaitRefetchQueries: true,\n });\n };\n\n const handleStop = async () => {\n if (!active) return;\n await interruptSession({\n variables: {\n id: active.id,\n workspaceId,\n reason: \"Stopped from the phone timer\",\n },\n refetchQueries: REFETCH,\n awaitRefetchQueries: true,\n });\n };\n\n const goal = todaysGoal(goalsData?.pomodoroGoals ?? []);\n const completedToday = statsData?.pomodoroStats.completedSessions ?? 0;\n const shownMode = active ? modeOf(active.type) : mode;\n const fraction = ringFraction(remaining, total);\n const workMinutes = Math.round(\n durationForSession(PomodoroSessionType.Focus, settings) / 60,\n );\n const breakMinutes = Math.round(\n durationForSession(PomodoroSessionType.ShortBreak, settings) / 60,\n );\n\n return (\n <MobileScreen\n active=\"timer\"\n title={t(\"timecampus.mobile.timer.title\", \"Focus session\")}\n fullViewPath=\"/pomodoro\"\n trailing={\n <button\n type=\"button\"\n onClick={() => navigate(\"/pomodoro/settings\")}\n className=\"inline-flex h-11 w-11 items-center justify-center rounded-full text-text-secondary hover:text-text-primary\"\n aria-label={t(\"timecampus.mobile.timer.settings\", \"Timer settings\")}\n >\n <Settings className=\"h-5 w-5\" />\n </button>\n }\n >\n <GlassCard\n treatment=\"glass\"\n glow={Boolean(active)}\n className=\"flex flex-col items-center px-4 py-8\"\n >\n <div\n className=\"relative aspect-square w-full max-w-[18rem]\"\n role=\"timer\"\n aria-live=\"off\"\n aria-label={t(\n \"timecampus.mobile.timer.remainingAria\",\n \"{{time}} remaining\",\n { time: formatCountdown(remaining) },\n )}\n >\n <svg viewBox=\"0 0 100 100\" className=\"h-full w-full -rotate-90\">\n <circle\n cx=\"50\"\n cy=\"50\"\n r={RING_RADIUS}\n fill=\"none\"\n strokeWidth=\"5\"\n stroke={chartTokens.track}\n />\n <circle\n cx=\"50\"\n cy=\"50\"\n r={RING_RADIUS}\n fill=\"none\"\n strokeWidth=\"5\"\n strokeLinecap=\"round\"\n strokeDasharray={RING_CIRCUMFERENCE}\n strokeDashoffset={RING_CIRCUMFERENCE * (1 - fraction)}\n stroke={\n shownMode === \"work\" ? chartTokens.brand : chartTokens.series[1]\n }\n className=\"motion-safe:transition-[stroke-dashoffset] motion-safe:duration-1000\"\n />\n </svg>\n <div className=\"absolute inset-0 flex flex-col items-center justify-center\">\n <p\n className=\"font-mono text-6xl font-bold tabular-nums text-text-primary\"\n data-testid=\"mobile-timer-countdown\"\n >\n {formatCountdown(remaining)}\n </p>\n <p className=\"mt-1 text-base text-text-secondary\">\n {t(\"timecampus.mobile.timer.pomodoro\", \"Pomodoro\")}\n </p>\n <p\n className={cn(\n \"text-lg font-semibold uppercase tracking-wide\",\n shownMode === \"work\" ? \"text-primary\" : \"text-text-secondary\",\n )}\n >\n {shownMode === \"work\"\n ? t(\"timecampus.mobile.timer.work\", \"Work\")\n : t(\"timecampus.mobile.timer.break\", \"Break\")}\n </p>\n </div>\n </div>\n </GlassCard>\n\n <div\n role=\"radiogroup\"\n aria-label={t(\"timecampus.mobile.timer.type\", \"Session type\")}\n className=\"grid grid-cols-2 gap-1 rounded-full border border-border-subtle bg-bg-sunken/50 p-1\"\n >\n {([\"work\", \"break\"] as const).map((option) => {\n const selected = shownMode === option;\n return (\n <button\n key={option}\n type=\"button\"\n role=\"radio\"\n aria-checked={selected}\n disabled={Boolean(active)}\n onClick={() => setMode(option)}\n className={cn(\n \"min-h-12 rounded-full text-base font-medium transition-colors disabled:cursor-not-allowed\",\n selected\n ? \"bg-bg-surface text-text-primary shadow-sm\"\n : \"text-text-secondary\",\n )}\n >\n {option === \"work\"\n ? t(\"timecampus.mobile.timer.workOption\", \"Work ({{min}}m)\", {\n min: workMinutes,\n })\n : t(\"timecampus.mobile.timer.breakOption\", \"Break ({{min}}m)\", {\n min: breakMinutes,\n })}\n </button>\n );\n })}\n </div>\n\n {startError && (\n <p className=\"rounded-lg border border-status-error-bg/40 bg-status-error-bg p-3 text-sm text-status-error-text\">\n {t(\n \"timecampus.mobile.timer.startError\",\n \"Couldn't start the session. Please try again.\",\n )}\n </p>\n )}\n\n <div className=\"grid grid-cols-2 gap-3\">\n <button\n type=\"button\"\n onClick={handleStart}\n disabled={\n Boolean(active) || starting || activeLoading || !workspaceId\n }\n className=\"inline-flex min-h-14 items-center justify-center gap-2 rounded-2xl bg-action-primary-bg text-base font-semibold uppercase text-action-primary-text disabled:opacity-50\"\n data-testid=\"mobile-timer-start\"\n >\n <Play className=\"h-5 w-5\" />\n {starting\n ? t(\"timecampus.mobile.timer.starting\", \"Starting…\")\n : t(\"timecampus.mobile.timer.start\", \"Start\")}\n </button>\n <button\n type=\"button\"\n onClick={handleStop}\n disabled={!active || stopping}\n className=\"inline-flex min-h-14 items-center justify-center gap-2 rounded-2xl border border-border-subtle bg-bg-surface text-base font-semibold uppercase text-text-primary disabled:opacity-50\"\n data-testid=\"mobile-timer-stop\"\n >\n <Square className=\"h-5 w-5\" />\n {stopping\n ? t(\"timecampus.mobile.timer.stopping\", \"Stopping…\")\n : t(\"timecampus.mobile.timer.stop\", \"Stop\")}\n </button>\n </div>\n\n <div className=\"text-center\" data-testid=\"mobile-timer-goal\">\n <p className=\"text-base font-semibold text-text-primary\">\n {t(\"timecampus.mobile.timer.goalsToday\", \"Focus today\")}\n </p>\n <p className=\"text-sm text-text-secondary\">\n {goal\n ? t(\n \"timecampus.mobile.timer.goalProgress\",\n \"{{done}} of {{target}} focus sessions completed\",\n { done: completedToday, target: goal.target },\n )\n : t(\n \"timecampus.mobile.timer.sessionsDone\",\n \"{{done}} focus sessions completed\",\n { done: completedToday },\n )}\n </p>\n {!goal && (\n <button\n type=\"button\"\n onClick={() => navigate(\"/pomodoro\")}\n className=\"mt-1 min-h-11 text-sm font-medium text-primary\"\n >\n {t(\"timecampus.mobile.timer.setGoal\", \"Set a daily goal\")}\n </button>\n )}\n </div>\n </MobileScreen>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,IAAM,IAAc,IACd,IAAqB,IAAI,KAAK,KAAK,GACnC,IAAU;CACd;CACA;CACA;CACA;AACF;AAEA,SAAS,EAAO,GAA6C;CAC3D,OAAO,MAAS,EAAoB,SAAS,MAAS,KAAA,IAClD,SACA;AACN;AAQA,SAAgB,IAAkB;CAChC,IAAM,EAAE,iBAAc,OAAO,EAAc,GACrC,IAAW,EAAsB,GACjC,IAAI,GAAM,GAEV,IAAQ,QAAc,EAAe,kBAAe,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAEpE,EAAE,MAAM,GAAY,SAAS,MACjC,GAAiC;EAC/B,WAAW,EAAE,eAAY;EACzB,MAAM,CAAC;EACP,aAAa;CACf,CAAC,GACG,EAAE,MAAM,MAAiB,EAA4B;EACzD,WAAW,EAAE,eAAY;EACzB,MAAM,CAAC;CACT,CAAC,GACK,EAAE,MAAM,MAAc,EAAyB;EACnD,WAAW;GAAE;GAAa,WAAW,EAAM;GAAM,SAAS,EAAM;EAAG;EACnE,MAAM,CAAC;EAC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V,eAAY;KAPd,UAAA,CASE,kBAAC,IAAD,EAAM,WAAU,UAAW,CAAA,GAC1B,IACG,EAAE,oCAAoC,WAAW,IACjD,EAAE,iCAAiC,OAAO,CACxC;IACR,CAAA,GAAA,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,UAAU,CAAC,KAAU;KACrB,WAAU;KACV,eAAY;KALd,UAAA,CAOE,kBAAC,IAAD,EAAQ,WAAU,UAAW,CAAA,GAC5B,IACG,EAAE,oCAAoC,WAAW,IACjD,EAAE,gCAAgC,MAAM,CACtC;IACL,CAAA,CAAA;;GAEL,kBAAC,OAAD;IAAK,WAAU;IAAc,eAAY;IAAzC,UAAA;KACE,kBAAC,KAAD;MAAG,WAAU;MACV,UAAA,EAAE,sCAAsC,aAAa;KACrD,CAAA;KACH,kBAAC,KAAD;MAAG,WAAU;MACV,UAAA,IACG,EACE,wCACA,mDACA;OAAE,MAAM;OAAgB,QAAQ,EAAK;MAAO,CAC9C,IACA,EACE,wCACA,qCACA,EAAE,MAAM,EAAe,CACzB;KACH,CAAA;KACF,CAAC,KACA,kBAAC,UAAD;MACE,MAAK;MACL,eAAe,EAAS,WAAW;MACnC,WAAU;MAET,UAAA,EAAE,mCAAmC,kBAAkB;KAClD,CAAA;IAEP;;EACO;;AAElB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure view-model helpers for the phone-optimised TimeCampus screens
|
|
3
|
+
* (`/mobile/timer`, `/mobile/timeline`, `/mobile/life-balance`).
|
|
4
|
+
*
|
|
5
|
+
* Everything here is derived from data the backend already returns — nothing
|
|
6
|
+
* is invented. When there is not enough data to say something honestly (no
|
|
7
|
+
* targets declared, nothing tracked yet) the helpers return `null` and the
|
|
8
|
+
* screen says so instead of showing a made-up number.
|
|
9
|
+
*/
|
|
10
|
+
/** `YYYY-MM-DD` for a Date in the viewer's local time zone. */
|
|
11
|
+
export declare function toLocalDateKey(date: Date): string;
|
|
12
|
+
/** Parses a `YYYY-MM-DD` key as local midnight; `null` when it is not a real date. */
|
|
13
|
+
export declare function parseLocalDateKey(key: string | null | undefined): Date | null;
|
|
14
|
+
/** Moves a `YYYY-MM-DD` key by whole days (DST-safe: calendar arithmetic). */
|
|
15
|
+
export declare function shiftDateKey(key: string, days: number): string;
|
|
16
|
+
/** ISO bounds of one local calendar day. */
|
|
17
|
+
export declare function localDayBounds(key: string): {
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
};
|
|
21
|
+
/** "Today", "Yesterday", or a short weekday + date ("Wed, Oct 25"). */
|
|
22
|
+
export declare function dayHeading(key: string, now?: Date): string;
|
|
23
|
+
/** Long form of the day for the sub-heading ("Wednesday, October 25"). */
|
|
24
|
+
export declare function longDayLabel(key: string): string;
|
|
25
|
+
/** Compact "1h 30m" / "45m" / "0m" from seconds (never shows seconds). */
|
|
26
|
+
export declare function compactDuration(seconds: number): string;
|
|
27
|
+
/** "MM:SS" countdown; hours roll into the minutes ("90:00"). */
|
|
28
|
+
export declare function formatCountdown(seconds: number): string;
|
|
29
|
+
export interface SessionClock {
|
|
30
|
+
startTime: string;
|
|
31
|
+
/** Planned length in seconds; falls back to the mode default when absent. */
|
|
32
|
+
duration?: number | null;
|
|
33
|
+
}
|
|
34
|
+
/** Seconds left on a running session at `now` (never negative). */
|
|
35
|
+
export declare function remainingSeconds(session: SessionClock, fallbackDurationSeconds: number, now?: number): number;
|
|
36
|
+
/** Fraction of the ring that is still "left" (1 = full, 0 = done). */
|
|
37
|
+
export declare function ringFraction(remaining: number, total: number): number;
|
|
38
|
+
export interface GoalLike {
|
|
39
|
+
type: string;
|
|
40
|
+
target: number;
|
|
41
|
+
current: number;
|
|
42
|
+
startDate: string;
|
|
43
|
+
endDate: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The daily focus goal that covers `now`, if the user set one. Only DAILY goals
|
|
47
|
+
* qualify — a weekly target is not "today's goal".
|
|
48
|
+
*/
|
|
49
|
+
export declare function todaysGoal<T extends GoalLike>(goals: readonly T[], now?: Date): T | null;
|
|
50
|
+
export interface CategoryTotal {
|
|
51
|
+
category: string;
|
|
52
|
+
totalSeconds: number;
|
|
53
|
+
}
|
|
54
|
+
export interface TimelineSummaryLike {
|
|
55
|
+
totalTrackedSeconds: number;
|
|
56
|
+
focusRatio?: number | null;
|
|
57
|
+
byCategory: readonly CategoryTotal[];
|
|
58
|
+
}
|
|
59
|
+
export interface FocusSummary {
|
|
60
|
+
/** Whole-number focus share, or null when the backend has no ratio yet. */
|
|
61
|
+
focusPercent: number | null;
|
|
62
|
+
deepWorkSeconds: number;
|
|
63
|
+
meetingSeconds: number;
|
|
64
|
+
trackedSeconds: number;
|
|
65
|
+
}
|
|
66
|
+
export declare function focusSummary(summary: TimelineSummaryLike | null | undefined): FocusSummary;
|
|
67
|
+
export interface SearchableSegment {
|
|
68
|
+
title?: string | null;
|
|
69
|
+
app?: string | null;
|
|
70
|
+
category: string;
|
|
71
|
+
projectId?: string | null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Case-insensitive match on the segment's title, app, category label or project
|
|
75
|
+
* name. An empty query keeps everything.
|
|
76
|
+
*/
|
|
77
|
+
export declare function filterSegments<T extends SearchableSegment>(segments: readonly T[], query: string, projectNameById: ReadonlyMap<string, string>, categoryLabel: (category: string) => string): T[];
|
|
78
|
+
/** Segments ordered by start time (planned blocks keep their slot). */
|
|
79
|
+
export declare function sortByStart<T extends {
|
|
80
|
+
startTime: string;
|
|
81
|
+
}>(segments: readonly T[]): T[];
|
|
82
|
+
export interface DomainBalanceLike {
|
|
83
|
+
domain: string;
|
|
84
|
+
actualSeconds: number;
|
|
85
|
+
actualShare: number;
|
|
86
|
+
desiredShare: number;
|
|
87
|
+
gap: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* How close the tracked split is to the declared one, 0–100: one minus the
|
|
91
|
+
* total-variation distance between the two distributions. 100 means the time
|
|
92
|
+
* split exactly as wanted; 0 means none of it went where it was wanted.
|
|
93
|
+
* `null` when the user has not declared targets or nothing is tracked — there
|
|
94
|
+
* is nothing honest to score.
|
|
95
|
+
*/
|
|
96
|
+
export declare function balanceScore(byDomain: readonly DomainBalanceLike[], hasTargets: boolean): number | null;
|
|
97
|
+
export type BalanceStatus = "on-track" | "drifting" | "off-balance";
|
|
98
|
+
export declare function balanceStatus(score: number): BalanceStatus;
|
|
99
|
+
export interface DomainRow {
|
|
100
|
+
domain: string;
|
|
101
|
+
actualSeconds: number;
|
|
102
|
+
/** Target for the selected range, pro-rated from hours/week; null if none. */
|
|
103
|
+
targetSeconds: number | null;
|
|
104
|
+
/** actual / target as a whole percent, null without a target. */
|
|
105
|
+
percentOfTarget: number | null;
|
|
106
|
+
actualShare: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Rows for the "so far" list: domains with tracked time or a target, most time
|
|
110
|
+
* first. Weekly targets are pro-rated to the range length.
|
|
111
|
+
*/
|
|
112
|
+
export declare function domainRows(byDomain: readonly DomainBalanceLike[], targetHoursPerWeek: Readonly<Record<string, number | undefined>>, rangeDays: number): DomainRow[];
|
|
113
|
+
/**
|
|
114
|
+
* The domain furthest below its target (largest unmet seconds), for the
|
|
115
|
+
* "make room for…" nudge. `null` when every target is met or none are set.
|
|
116
|
+
*/
|
|
117
|
+
export declare function biggestShortfall(rows: readonly DomainRow[]): {
|
|
118
|
+
domain: string;
|
|
119
|
+
missingSeconds: number;
|
|
120
|
+
} | null;
|
|
121
|
+
//# sourceMappingURL=mobileModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobileModel.d.ts","sourceRoot":"","sources":["../../../../src/timecampus/pages/mobile/mobileModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAKjD;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,GAAG,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;AAMD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,UAAU,EAAE,OAAO,GAClB,MAAM,GAAG,IAAI,CAUf;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;AAEpE,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAI1D;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iEAAiE;IACjE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAChE,SAAS,EAAE,MAAM,GAChB,SAAS,EAAE,CAsBb;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,SAAS,SAAS,EAAE,GACzB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAWnD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//#region src/timecampus/pages/mobile/mobileModel.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
|
|
4
|
+
}
|
|
5
|
+
function t(e) {
|
|
6
|
+
if (!e) return null;
|
|
7
|
+
let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
8
|
+
if (!t) return null;
|
|
9
|
+
let [, n, r, i] = t, a = new Date(Number(n), Number(r) - 1, Number(i));
|
|
10
|
+
return a.getFullYear() !== Number(n) || a.getMonth() !== Number(r) - 1 || a.getDate() !== Number(i) ? null : a;
|
|
11
|
+
}
|
|
12
|
+
function n(n, r) {
|
|
13
|
+
let i = t(n) ?? /* @__PURE__ */ new Date();
|
|
14
|
+
return e(new Date(i.getFullYear(), i.getMonth(), i.getDate() + r));
|
|
15
|
+
}
|
|
16
|
+
function r(e) {
|
|
17
|
+
let n = t(e) ?? /* @__PURE__ */ new Date(), r = new Date(n.getFullYear(), n.getMonth(), n.getDate()), i = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 23, 59, 59, 999);
|
|
18
|
+
return {
|
|
19
|
+
from: r.toISOString(),
|
|
20
|
+
to: i.toISOString()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function i(r, i = /* @__PURE__ */ new Date()) {
|
|
24
|
+
let a = e(i);
|
|
25
|
+
if (r === a) return "Today";
|
|
26
|
+
if (r === n(a, -1)) return "Yesterday";
|
|
27
|
+
let o = t(r);
|
|
28
|
+
return o ? o.toLocaleDateString("en-US", {
|
|
29
|
+
weekday: "short",
|
|
30
|
+
month: "short",
|
|
31
|
+
day: "numeric"
|
|
32
|
+
}) : r;
|
|
33
|
+
}
|
|
34
|
+
function a(e) {
|
|
35
|
+
let n = t(e);
|
|
36
|
+
return n ? n.toLocaleDateString("en-US", {
|
|
37
|
+
weekday: "long",
|
|
38
|
+
month: "long",
|
|
39
|
+
day: "numeric"
|
|
40
|
+
}) : e;
|
|
41
|
+
}
|
|
42
|
+
function o(e) {
|
|
43
|
+
let t = Math.max(0, Math.round(e)), n = Math.floor(t / 3600), r = Math.floor(t % 3600 / 60);
|
|
44
|
+
return n === 0 ? `${r}m` : r === 0 ? `${n}h` : `${n}h ${r}m`;
|
|
45
|
+
}
|
|
46
|
+
function s(e) {
|
|
47
|
+
let t = Math.max(0, Math.floor(e)), n = Math.floor(t / 60), r = t % 60;
|
|
48
|
+
return `${String(n).padStart(2, "0")}:${String(r).padStart(2, "0")}`;
|
|
49
|
+
}
|
|
50
|
+
function c(e, t, n = Date.now()) {
|
|
51
|
+
let r = e.duration && e.duration > 0 ? e.duration : t, i = new Date(e.startTime).getTime();
|
|
52
|
+
if (!Number.isFinite(i)) return r;
|
|
53
|
+
let a = Math.floor((n - i) / 1e3);
|
|
54
|
+
return Math.max(0, r - Math.max(0, a));
|
|
55
|
+
}
|
|
56
|
+
function l(e, t) {
|
|
57
|
+
return !Number.isFinite(t) || t <= 0 ? 0 : Math.min(1, Math.max(0, e / t));
|
|
58
|
+
}
|
|
59
|
+
function u(t, n = /* @__PURE__ */ new Date()) {
|
|
60
|
+
let r = e(n), i = (t) => {
|
|
61
|
+
let n = new Date(t);
|
|
62
|
+
return Number.isFinite(n.getTime()) ? e(n) : null;
|
|
63
|
+
}, a = t.filter((e) => {
|
|
64
|
+
if (e.type !== "DAILY" || e.target <= 0) return !1;
|
|
65
|
+
let t = i(e.startDate), n = i(e.endDate);
|
|
66
|
+
return (t === null || t <= r) && (n === null || r <= n);
|
|
67
|
+
});
|
|
68
|
+
return a.length === 0 ? null : a.reduce((e, t) => new Date(t.startDate).getTime() > new Date(e.startDate).getTime() ? t : e);
|
|
69
|
+
}
|
|
70
|
+
function d(e) {
|
|
71
|
+
let t = (t) => e?.byCategory.filter((e) => e.category === t).reduce((e, t) => e + t.totalSeconds, 0) ?? 0, n = e?.focusRatio;
|
|
72
|
+
return {
|
|
73
|
+
focusPercent: typeof n == "number" && Number.isFinite(n) ? Math.round(n * 100) : null,
|
|
74
|
+
deepWorkSeconds: t("DEEP_WORK"),
|
|
75
|
+
meetingSeconds: t("MEETING"),
|
|
76
|
+
trackedSeconds: e?.totalTrackedSeconds ?? 0
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function f(e, t, n, r) {
|
|
80
|
+
let i = t.trim().toLowerCase();
|
|
81
|
+
return i ? e.filter((e) => [
|
|
82
|
+
e.title,
|
|
83
|
+
e.app,
|
|
84
|
+
r(e.category),
|
|
85
|
+
e.projectId ? n.get(e.projectId) : void 0
|
|
86
|
+
].some((e) => typeof e == "string" && e.toLowerCase().includes(i))) : [...e];
|
|
87
|
+
}
|
|
88
|
+
function p(e) {
|
|
89
|
+
return [...e].sort((e, t) => new Date(e.startTime).getTime() - new Date(t.startTime).getTime());
|
|
90
|
+
}
|
|
91
|
+
function m(e, t) {
|
|
92
|
+
if (!t || e.reduce((e, t) => e + t.actualSeconds, 0) <= 0) return null;
|
|
93
|
+
let n = e.reduce((e, t) => e + Math.abs(t.actualShare - t.desiredShare), 0) / 2;
|
|
94
|
+
return Math.round(Math.min(1, Math.max(0, 1 - n)) * 100);
|
|
95
|
+
}
|
|
96
|
+
function h(e) {
|
|
97
|
+
return e >= 75 ? "on-track" : e >= 50 ? "drifting" : "off-balance";
|
|
98
|
+
}
|
|
99
|
+
function g(e, t, n) {
|
|
100
|
+
let r = Math.max(1, n);
|
|
101
|
+
return e.map((e) => {
|
|
102
|
+
let n = t[e.domain], i = typeof n == "number" && n > 0 ? Math.round(n * 3600 * r / 7) : null;
|
|
103
|
+
return {
|
|
104
|
+
domain: e.domain,
|
|
105
|
+
actualSeconds: e.actualSeconds,
|
|
106
|
+
targetSeconds: i,
|
|
107
|
+
percentOfTarget: i && i > 0 ? Math.round(e.actualSeconds / i * 100) : null,
|
|
108
|
+
actualShare: e.actualShare
|
|
109
|
+
};
|
|
110
|
+
}).filter((e) => e.actualSeconds > 0 || e.targetSeconds !== null).sort((e, t) => t.actualSeconds - e.actualSeconds);
|
|
111
|
+
}
|
|
112
|
+
function _(e) {
|
|
113
|
+
let t = null;
|
|
114
|
+
for (let n of e) {
|
|
115
|
+
if (n.targetSeconds === null) continue;
|
|
116
|
+
let e = n.targetSeconds - n.actualSeconds;
|
|
117
|
+
e <= 0 || (!t || e > t.missingSeconds) && (t = {
|
|
118
|
+
domain: n.domain,
|
|
119
|
+
missingSeconds: e
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return t;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { m as balanceScore, h as balanceStatus, _ as biggestShortfall, o as compactDuration, i as dayHeading, g as domainRows, f as filterSegments, d as focusSummary, s as formatCountdown, r as localDayBounds, a as longDayLabel, t as parseLocalDateKey, c as remainingSeconds, l as ringFraction, n as shiftDateKey, p as sortByStart, e as toLocalDateKey, u as todaysGoal };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=mobileModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobileModel.js","names":[],"sources":["../../../../src/timecampus/pages/mobile/mobileModel.ts"],"sourcesContent":["/**\n * Pure view-model helpers for the phone-optimised TimeCampus screens\n * (`/mobile/timer`, `/mobile/timeline`, `/mobile/life-balance`).\n *\n * Everything here is derived from data the backend already returns — nothing\n * is invented. When there is not enough data to say something honestly (no\n * targets declared, nothing tracked yet) the helpers return `null` and the\n * screen says so instead of showing a made-up number.\n */\n\n// ---------------------------------------------------------------------------\n// Dates\n// ---------------------------------------------------------------------------\n\n/** `YYYY-MM-DD` for a Date in the viewer's local time zone. */\nexport function toLocalDateKey(date: Date): string {\n const y = date.getFullYear();\n const m = String(date.getMonth() + 1).padStart(2, \"0\");\n const d = String(date.getDate()).padStart(2, \"0\");\n return `${y}-${m}-${d}`;\n}\n\n/** Parses a `YYYY-MM-DD` key as local midnight; `null` when it is not a real date. */\nexport function parseLocalDateKey(key: string | null | undefined): Date | null {\n if (!key) return null;\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(key);\n if (!match) return null;\n const [, y, m, d] = match;\n const date = new Date(Number(y), Number(m) - 1, Number(d));\n if (\n date.getFullYear() !== Number(y) ||\n date.getMonth() !== Number(m) - 1 ||\n date.getDate() !== Number(d)\n ) {\n return null;\n }\n return date;\n}\n\n/** Moves a `YYYY-MM-DD` key by whole days (DST-safe: calendar arithmetic). */\nexport function shiftDateKey(key: string, days: number): string {\n const base = parseLocalDateKey(key) ?? new Date();\n const next = new Date(\n base.getFullYear(),\n base.getMonth(),\n base.getDate() + days,\n );\n return toLocalDateKey(next);\n}\n\n/** ISO bounds of one local calendar day. */\nexport function localDayBounds(key: string): { from: string; to: string } {\n const day = parseLocalDateKey(key) ?? new Date();\n const start = new Date(day.getFullYear(), day.getMonth(), day.getDate());\n const end = new Date(\n day.getFullYear(),\n day.getMonth(),\n day.getDate(),\n 23,\n 59,\n 59,\n 999,\n );\n return { from: start.toISOString(), to: end.toISOString() };\n}\n\n/** \"Today\", \"Yesterday\", or a short weekday + date (\"Wed, Oct 25\"). */\nexport function dayHeading(key: string, now: Date = new Date()): string {\n const today = toLocalDateKey(now);\n if (key === today) return \"Today\";\n if (key === shiftDateKey(today, -1)) return \"Yesterday\";\n const date = parseLocalDateKey(key);\n if (!date) return key;\n return date.toLocaleDateString(\"en-US\", {\n weekday: \"short\",\n month: \"short\",\n day: \"numeric\",\n });\n}\n\n/** Long form of the day for the sub-heading (\"Wednesday, October 25\"). */\nexport function longDayLabel(key: string): string {\n const date = parseLocalDateKey(key);\n if (!date) return key;\n return date.toLocaleDateString(\"en-US\", {\n weekday: \"long\",\n month: \"long\",\n day: \"numeric\",\n });\n}\n\n// ---------------------------------------------------------------------------\n// Durations\n// ---------------------------------------------------------------------------\n\n/** Compact \"1h 30m\" / \"45m\" / \"0m\" from seconds (never shows seconds). */\nexport function compactDuration(seconds: number): string {\n const total = Math.max(0, Math.round(seconds));\n const h = Math.floor(total / 3600);\n const m = Math.floor((total % 3600) / 60);\n if (h === 0) return `${m}m`;\n if (m === 0) return `${h}h`;\n return `${h}h ${m}m`;\n}\n\n/** \"MM:SS\" countdown; hours roll into the minutes (\"90:00\"). */\nexport function formatCountdown(seconds: number): string {\n const total = Math.max(0, Math.floor(seconds));\n const m = Math.floor(total / 60);\n const s = total % 60;\n return `${String(m).padStart(2, \"0\")}:${String(s).padStart(2, \"0\")}`;\n}\n\n// ---------------------------------------------------------------------------\n// Timer (pomodoro-backed focus session)\n// ---------------------------------------------------------------------------\n\nexport interface SessionClock {\n startTime: string;\n /** Planned length in seconds; falls back to the mode default when absent. */\n duration?: number | null;\n}\n\n/** Seconds left on a running session at `now` (never negative). */\nexport function remainingSeconds(\n session: SessionClock,\n fallbackDurationSeconds: number,\n now: number = Date.now(),\n): number {\n const planned =\n session.duration && session.duration > 0\n ? session.duration\n : fallbackDurationSeconds;\n const started = new Date(session.startTime).getTime();\n if (!Number.isFinite(started)) return planned;\n const elapsed = Math.floor((now - started) / 1000);\n return Math.max(0, planned - Math.max(0, elapsed));\n}\n\n/** Fraction of the ring that is still \"left\" (1 = full, 0 = done). */\nexport function ringFraction(remaining: number, total: number): number {\n if (!Number.isFinite(total) || total <= 0) return 0;\n return Math.min(1, Math.max(0, remaining / total));\n}\n\nexport interface GoalLike {\n type: string;\n target: number;\n current: number;\n startDate: string;\n endDate: string;\n}\n\n/**\n * The daily focus goal that covers `now`, if the user set one. Only DAILY goals\n * qualify — a weekly target is not \"today's goal\".\n */\nexport function todaysGoal<T extends GoalLike>(\n goals: readonly T[],\n now: Date = new Date(),\n): T | null {\n // Compare calendar days, not instants: a goal that ends \"on\" a date covers\n // the whole of that day whatever time-of-day the end was stored with.\n const today = toLocalDateKey(now);\n const dayKey = (iso: string): string | null => {\n const date = new Date(iso);\n return Number.isFinite(date.getTime()) ? toLocalDateKey(date) : null;\n };\n const active = goals.filter((goal) => {\n if (goal.type !== \"DAILY\" || goal.target <= 0) return false;\n const start = dayKey(goal.startDate);\n const end = dayKey(goal.endDate);\n return (start === null || start <= today) && (end === null || today <= end);\n });\n if (active.length === 0) return null;\n return active.reduce((best, goal) =>\n new Date(goal.startDate).getTime() > new Date(best.startDate).getTime()\n ? goal\n : best,\n );\n}\n\n// ---------------------------------------------------------------------------\n// Timeline\n// ---------------------------------------------------------------------------\n\nexport interface CategoryTotal {\n category: string;\n totalSeconds: number;\n}\n\nexport interface TimelineSummaryLike {\n totalTrackedSeconds: number;\n focusRatio?: number | null;\n byCategory: readonly CategoryTotal[];\n}\n\nexport interface FocusSummary {\n /** Whole-number focus share, or null when the backend has no ratio yet. */\n focusPercent: number | null;\n deepWorkSeconds: number;\n meetingSeconds: number;\n trackedSeconds: number;\n}\n\nexport function focusSummary(\n summary: TimelineSummaryLike | null | undefined,\n): FocusSummary {\n const total = (category: string) =>\n summary?.byCategory\n .filter((row) => row.category === category)\n .reduce((sum, row) => sum + row.totalSeconds, 0) ?? 0;\n const ratio = summary?.focusRatio;\n return {\n focusPercent:\n typeof ratio === \"number\" && Number.isFinite(ratio)\n ? Math.round(ratio * 100)\n : null,\n deepWorkSeconds: total(\"DEEP_WORK\"),\n meetingSeconds: total(\"MEETING\"),\n trackedSeconds: summary?.totalTrackedSeconds ?? 0,\n };\n}\n\nexport interface SearchableSegment {\n title?: string | null;\n app?: string | null;\n category: string;\n projectId?: string | null;\n}\n\n/**\n * Case-insensitive match on the segment's title, app, category label or project\n * name. An empty query keeps everything.\n */\nexport function filterSegments<T extends SearchableSegment>(\n segments: readonly T[],\n query: string,\n projectNameById: ReadonlyMap<string, string>,\n categoryLabel: (category: string) => string,\n): T[] {\n const needle = query.trim().toLowerCase();\n if (!needle) return [...segments];\n return segments.filter((segment) => {\n const haystack = [\n segment.title,\n segment.app,\n categoryLabel(segment.category),\n segment.projectId ? projectNameById.get(segment.projectId) : undefined,\n ];\n return haystack.some(\n (value) =>\n typeof value === \"string\" && value.toLowerCase().includes(needle),\n );\n });\n}\n\n/** Segments ordered by start time (planned blocks keep their slot). */\nexport function sortByStart<T extends { startTime: string }>(\n segments: readonly T[],\n): T[] {\n return [...segments].sort(\n (a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime(),\n );\n}\n\n// ---------------------------------------------------------------------------\n// Life balance\n// ---------------------------------------------------------------------------\n\nexport interface DomainBalanceLike {\n domain: string;\n actualSeconds: number;\n actualShare: number;\n desiredShare: number;\n gap: number;\n}\n\n/**\n * How close the tracked split is to the declared one, 0–100: one minus the\n * total-variation distance between the two distributions. 100 means the time\n * split exactly as wanted; 0 means none of it went where it was wanted.\n * `null` when the user has not declared targets or nothing is tracked — there\n * is nothing honest to score.\n */\nexport function balanceScore(\n byDomain: readonly DomainBalanceLike[],\n hasTargets: boolean,\n): number | null {\n if (!hasTargets) return null;\n const tracked = byDomain.reduce((sum, d) => sum + d.actualSeconds, 0);\n if (tracked <= 0) return null;\n const distance =\n byDomain.reduce(\n (sum, d) => sum + Math.abs(d.actualShare - d.desiredShare),\n 0,\n ) / 2;\n return Math.round(Math.min(1, Math.max(0, 1 - distance)) * 100);\n}\n\nexport type BalanceStatus = \"on-track\" | \"drifting\" | \"off-balance\";\n\nexport function balanceStatus(score: number): BalanceStatus {\n if (score >= 75) return \"on-track\";\n if (score >= 50) return \"drifting\";\n return \"off-balance\";\n}\n\nexport interface DomainRow {\n domain: string;\n actualSeconds: number;\n /** Target for the selected range, pro-rated from hours/week; null if none. */\n targetSeconds: number | null;\n /** actual / target as a whole percent, null without a target. */\n percentOfTarget: number | null;\n actualShare: number;\n}\n\n/**\n * Rows for the \"so far\" list: domains with tracked time or a target, most time\n * first. Weekly targets are pro-rated to the range length.\n */\nexport function domainRows(\n byDomain: readonly DomainBalanceLike[],\n targetHoursPerWeek: Readonly<Record<string, number | undefined>>,\n rangeDays: number,\n): DomainRow[] {\n const days = Math.max(1, rangeDays);\n return byDomain\n .map((d) => {\n const weekly = targetHoursPerWeek[d.domain];\n const targetSeconds =\n typeof weekly === \"number\" && weekly > 0\n ? Math.round((weekly * 3600 * days) / 7)\n : null;\n return {\n domain: d.domain,\n actualSeconds: d.actualSeconds,\n targetSeconds,\n percentOfTarget:\n targetSeconds && targetSeconds > 0\n ? Math.round((d.actualSeconds / targetSeconds) * 100)\n : null,\n actualShare: d.actualShare,\n };\n })\n .filter((row) => row.actualSeconds > 0 || row.targetSeconds !== null)\n .sort((a, b) => b.actualSeconds - a.actualSeconds);\n}\n\n/**\n * The domain furthest below its target (largest unmet seconds), for the\n * \"make room for…\" nudge. `null` when every target is met or none are set.\n */\nexport function biggestShortfall(\n rows: readonly DomainRow[],\n): { domain: string; missingSeconds: number } | null {\n let best: { domain: string; missingSeconds: number } | null = null;\n for (const row of rows) {\n if (row.targetSeconds === null) continue;\n const missing = row.targetSeconds - row.actualSeconds;\n if (missing <= 0) continue;\n if (!best || missing > best.missingSeconds) {\n best = { domain: row.domain, missingSeconds: missing };\n }\n }\n return best;\n}\n"],"mappings":";AAeA,SAAgB,EAAe,GAAoB;CAIjD,OAAO,GAHG,EAAK,YAGL,EAAE,GAFF,OAAO,EAAK,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAEnC,EAAE,GADP,OAAO,EAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,GACzB;AACtB;AAGA,SAAgB,EAAkB,GAA6C;CAC7E,IAAI,CAAC,GAAK,OAAO;CACjB,IAAM,IAAQ,4BAA4B,KAAK,CAAG;CAClD,IAAI,CAAC,GAAO,OAAO;CACnB,IAAM,GAAG,GAAG,GAAG,KAAK,GACd,IAAO,IAAI,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;CAQzD,OANE,EAAK,YAAY,MAAM,OAAO,CAAC,KAC/B,EAAK,SAAS,MAAM,OAAO,CAAC,IAAI,KAChC,EAAK,QAAQ,MAAM,OAAO,CAAC,IAEpB,OAEF;AACT;AAGA,SAAgB,EAAa,GAAa,GAAsB;CAC9D,IAAM,IAAO,EAAkB,CAAG,qBAAK,IAAI,KAAK;CAMhD,OAAO,EAAe,IALL,KACf,EAAK,YAAY,GACjB,EAAK,SAAS,GACd,EAAK,QAAQ,IAAI,CAEG,CAAI;AAC5B;AAGA,SAAgB,EAAe,GAA2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EACd,GACA,GACA,GACa;CACb,IAAM,IAAO,KAAK,IAAI,GAAG,CAAS;CAClC,OAAO,EACJ,KAAK,MAAM;EACV,IAAM,IAAS,EAAmB,EAAE,SAC9B,IACJ,OAAO,KAAW,YAAY,IAAS,IACnC,KAAK,MAAO,IAAS,OAAO,IAAQ,CAAC,IACrC;EACN,OAAO;GACL,QAAQ,EAAE;GACV,eAAe,EAAE;GACjB;GACA,iBACE,KAAiB,IAAgB,IAC7B,KAAK,MAAO,EAAE,gBAAgB,IAAiB,GAAG,IAClD;GACN,aAAa,EAAE;EACjB;CACF,CAAC,CAAC,CACD,QAAQ,MAAQ,EAAI,gBAAgB,KAAK,EAAI,kBAAkB,IAAI,CAAC,CACpE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,aAAa;AACrD;AAMA,SAAgB,EACd,GACmD;CACnD,IAAI,IAA0D;CAC9D,KAAK,IAAM,KAAO,GAAM;EACtB,IAAI,EAAI,kBAAkB,MAAM;EAChC,IAAM,IAAU,EAAI,gBAAgB,EAAI;EACpC,KAAW,MACX,CAAC,KAAQ,IAAU,EAAK,oBAC1B,IAAO;GAAE,QAAQ,EAAI;GAAQ,gBAAgB;EAAQ;CAEzD;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PomodoroPage.d.ts","sourceRoot":"","sources":["../../../../src/timecampus/pages/pomodoro/PomodoroPage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PomodoroPage.d.ts","sourceRoot":"","sources":["../../../../src/timecampus/pages/pomodoro/PomodoroPage.tsx"],"names":[],"mappings":"AAsFA,wBAAgB,YAAY,gCAunB3B"}
|
|
@@ -7,11 +7,12 @@ import "../../analytics/index.js";
|
|
|
7
7
|
import { PageLayout as r } from "../../components/PageLayout.js";
|
|
8
8
|
import { Modal as i } from "../../components/Modal.js";
|
|
9
9
|
import { PomodoroGoalType as a, PomodoroSessionOrderByField as pe, PomodoroSessionType as o, TimeCampusSortDirection as me } from "../../../generated/wspace-types.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { PhoneViewLink as he } from "../mobile/MobileScreen.js";
|
|
11
|
+
import { durationForSession as ge, nextSessionAfter as s } from "./pomodoroDuration.js";
|
|
12
|
+
import { useCallback as c, useEffect as l, useRef as _e, useState as u } from "react";
|
|
13
|
+
import { Pause as ve, Pencil as ye, Play as be, Plus as xe, RotateCcw as Se, SkipForward as Ce, Target as we, Trash2 as Te } from "lucide-react";
|
|
13
14
|
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
14
|
-
import { GlassCard as m, NextSteps as
|
|
15
|
+
import { GlassCard as m, NextSteps as Ee } from "@burdenoff/fe-libs/ui";
|
|
15
16
|
//#region src/timecampus/pages/pomodoro/PomodoroPage.tsx
|
|
16
17
|
var h = "mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary", g = "block text-sm font-medium text-text-primary";
|
|
17
18
|
function _(e) {
|
|
@@ -36,16 +37,16 @@ function b(e) {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
function x() {
|
|
39
|
-
let { workspaceId: _ = "" } = e(), v = t(), { data: x, loading:
|
|
40
|
+
let { workspaceId: _ = "" } = e(), v = t(), { data: x, loading: De, error: Oe } = oe({
|
|
40
41
|
variables: { workspaceId: _ },
|
|
41
42
|
skip: !_
|
|
42
|
-
}), { data:
|
|
43
|
+
}), { data: ke, loading: Ae, error: je } = ie({
|
|
43
44
|
variables: { workspaceId: _ },
|
|
44
45
|
skip: !_
|
|
45
|
-
}), { data:
|
|
46
|
+
}), { data: Me, loading: Ne, error: Pe } = ae({
|
|
46
47
|
variables: { workspaceId: _ },
|
|
47
48
|
skip: !_
|
|
48
|
-
}), { data:
|
|
49
|
+
}), { data: Fe } = le({
|
|
49
50
|
variables: {
|
|
50
51
|
workspaceId: _,
|
|
51
52
|
orderBy: {
|
|
@@ -58,20 +59,20 @@ function x() {
|
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
skip: !_
|
|
61
|
-
}), [S] = ue(), [C] = te(), w = fe(), [
|
|
62
|
+
}), [S] = ue(), [C] = te(), w = fe(), [Ie] = se(), { data: Le, refetch: T } = ce({
|
|
62
63
|
variables: { workspaceId: _ },
|
|
63
64
|
skip: !_
|
|
64
|
-
}), E =
|
|
65
|
+
}), E = Le?.pomodoroGoals ?? [], [Re, { loading: D, error: ze }] = ne(), [Be, { loading: O, error: Ve }] = de(), [He, { loading: k, error: Ue }] = re(), [We, A] = u(!1), [j, M] = u(null), [N, P] = u(null), [F, I] = u(b()), L = (e, t) => I((n) => ({
|
|
65
66
|
...n,
|
|
66
67
|
[e]: t
|
|
67
|
-
})),
|
|
68
|
+
})), Ge = () => {
|
|
68
69
|
M(null), I(b()), A(!0);
|
|
69
|
-
},
|
|
70
|
+
}, Ke = (e) => {
|
|
70
71
|
M(e), I(b(e)), A(!0);
|
|
71
|
-
},
|
|
72
|
+
}, qe = async () => {
|
|
72
73
|
if (!_) return;
|
|
73
74
|
let e = Number(F.target);
|
|
74
|
-
!e || e <= 0 || (j ? await
|
|
75
|
+
!e || e <= 0 || (j ? await Be({ variables: {
|
|
75
76
|
id: j.id,
|
|
76
77
|
workspaceId: _,
|
|
77
78
|
input: {
|
|
@@ -81,7 +82,7 @@ function x() {
|
|
|
81
82
|
startDate: new Date(F.startDate).toISOString(),
|
|
82
83
|
endDate: new Date(F.endDate).toISOString()
|
|
83
84
|
}
|
|
84
|
-
} }) : await
|
|
85
|
+
} }) : await Re({ variables: { input: {
|
|
85
86
|
workspaceId: _,
|
|
86
87
|
type: F.type,
|
|
87
88
|
target: e,
|
|
@@ -89,12 +90,12 @@ function x() {
|
|
|
89
90
|
startDate: new Date(F.startDate).toISOString(),
|
|
90
91
|
endDate: new Date(F.endDate).toISOString()
|
|
91
92
|
} } }), A(!1), await T());
|
|
92
|
-
},
|
|
93
|
-
!N || !_ || (await
|
|
93
|
+
}, Je = async () => {
|
|
94
|
+
!N || !_ || (await He({ variables: {
|
|
94
95
|
id: N.id,
|
|
95
96
|
workspaceId: _
|
|
96
97
|
} }), P(null), await T());
|
|
97
|
-
}, R = x?.pomodoroStats, z =
|
|
98
|
+
}, R = x?.pomodoroStats, z = ke?.activePomodoroSession, B = Me?.pomodoroSettings, V = Fe?.pomodoroSessions[0], [H, U] = u(1500), [W, G] = u(!1), [K, q] = u(o.Focus), J = _e(null), Y = c((e) => ge(e, B), [B]), X = c((e) => {
|
|
98
99
|
let t = (R?.completedSessions ?? 0) + 1;
|
|
99
100
|
return s(e, t, B?.sessionsBeforeLongBreak ?? 4);
|
|
100
101
|
}, [B?.sessionsBeforeLongBreak, R?.completedSessions]);
|
|
@@ -158,7 +159,7 @@ function x() {
|
|
|
158
159
|
W,
|
|
159
160
|
H
|
|
160
161
|
]);
|
|
161
|
-
let
|
|
162
|
+
let Ye = (e) => {
|
|
162
163
|
let t = Math.floor(e / 60), n = e % 60;
|
|
163
164
|
return `${String(t).padStart(2, "0")}:${String(n).padStart(2, "0")}`;
|
|
164
165
|
}, Q = c(async () => {
|
|
@@ -182,8 +183,8 @@ function x() {
|
|
|
182
183
|
Y,
|
|
183
184
|
K,
|
|
184
185
|
S
|
|
185
|
-
]),
|
|
186
|
-
G(!1), z && _ && (await
|
|
186
|
+
]), Xe = async () => {
|
|
187
|
+
G(!1), z && _ && (await Ie({
|
|
187
188
|
variables: {
|
|
188
189
|
id: z.id,
|
|
189
190
|
workspaceId: _,
|
|
@@ -197,7 +198,7 @@ function x() {
|
|
|
197
198
|
awaitRefetchQueries: !0
|
|
198
199
|
}), q(z.type)), U(Y(z?.type ?? K));
|
|
199
200
|
};
|
|
200
|
-
if (
|
|
201
|
+
if (De || Ae || Ne) return /* @__PURE__ */ f(r, {
|
|
201
202
|
title: "Pomodoro Timer",
|
|
202
203
|
description: "Focus with the Pomodoro Technique",
|
|
203
204
|
children: /* @__PURE__ */ f(ee, {
|
|
@@ -205,7 +206,7 @@ function x() {
|
|
|
205
206
|
count: 3
|
|
206
207
|
})
|
|
207
208
|
});
|
|
208
|
-
if (
|
|
209
|
+
if (Oe || je || Pe) return /* @__PURE__ */ f(r, {
|
|
209
210
|
title: "Pomodoro Timer",
|
|
210
211
|
description: "Focus with the Pomodoro Technique",
|
|
211
212
|
children: /* @__PURE__ */ f("div", {
|
|
@@ -213,13 +214,14 @@ function x() {
|
|
|
213
214
|
children: "Failed to load pomodoro data. Please try again later."
|
|
214
215
|
})
|
|
215
216
|
});
|
|
216
|
-
let
|
|
217
|
+
let Ze = Math.floor((R?.totalFocusMinutes ?? 0) / 60), Qe = (R?.totalFocusMinutes ?? 0) % 60, $ = z?.type ?? K, $e = $ === o.ShortBreak ? z ? "Short Break" : "Short Break Ready" : $ === o.LongBreak ? z ? "Long Break" : "Long Break Ready" : z ? "Focus Session" : "Focus Ready", et = $ === o.ShortBreak ? "Start Short Break" : $ === o.LongBreak ? "Start Long Break" : "Start Focus";
|
|
217
218
|
return /* @__PURE__ */ p(r, {
|
|
218
219
|
title: "Pomodoro Timer",
|
|
219
220
|
description: "Focus with the Pomodoro Technique",
|
|
220
221
|
purpose: "Work in focused sprints with prompted short and long breaks — configure a cadence that fits your rhythm and build a deep-work streak you can measure.",
|
|
221
222
|
children: [
|
|
222
|
-
/* @__PURE__ */ f(
|
|
223
|
+
/* @__PURE__ */ f(he, { path: "/mobile/timer" }),
|
|
224
|
+
/* @__PURE__ */ f(Ee, {
|
|
223
225
|
storageKey: "timecampus-pomodoro",
|
|
224
226
|
className: "mb-6",
|
|
225
227
|
steps: [
|
|
@@ -253,7 +255,7 @@ function x() {
|
|
|
253
255
|
}),
|
|
254
256
|
/* @__PURE__ */ f(n, {
|
|
255
257
|
title: "Focus Time",
|
|
256
|
-
value: `${
|
|
258
|
+
value: `${Ze}h ${Qe}m`,
|
|
257
259
|
trend: {
|
|
258
260
|
value: R?.completionRate ?? 0,
|
|
259
261
|
label: "completion rate"
|
|
@@ -278,12 +280,12 @@ function x() {
|
|
|
278
280
|
children: /* @__PURE__ */ f("span", {
|
|
279
281
|
"aria-live": "polite",
|
|
280
282
|
className: "inline-flex rounded-full bg-action-primary-bg/10 px-3 py-1 text-xs font-medium text-primary",
|
|
281
|
-
children:
|
|
283
|
+
children: $e
|
|
282
284
|
})
|
|
283
285
|
}),
|
|
284
286
|
/* @__PURE__ */ f("p", {
|
|
285
287
|
className: "text-7xl font-mono font-bold text-text-primary",
|
|
286
|
-
children:
|
|
288
|
+
children: Ye(H)
|
|
287
289
|
}),
|
|
288
290
|
/* @__PURE__ */ f("p", {
|
|
289
291
|
className: "mt-2 text-sm text-text-secondary",
|
|
@@ -295,22 +297,22 @@ function x() {
|
|
|
295
297
|
W ? /* @__PURE__ */ p("button", {
|
|
296
298
|
onClick: () => G(!1),
|
|
297
299
|
className: "inline-flex items-center gap-2 rounded-md bg-action-primary-bg px-6 py-3 text-sm font-medium text-action-primary-text hover:bg-action-primary-bg/90",
|
|
298
|
-
children: [/* @__PURE__ */ f(
|
|
300
|
+
children: [/* @__PURE__ */ f(ve, { className: "h-4 w-4" }), "Pause"]
|
|
299
301
|
}) : /* @__PURE__ */ p("button", {
|
|
300
302
|
onClick: Q,
|
|
301
303
|
className: "inline-flex items-center gap-2 rounded-md bg-action-primary-bg px-6 py-3 text-sm font-medium text-action-primary-text hover:bg-action-primary-bg/90",
|
|
302
|
-
children: [/* @__PURE__ */ f(
|
|
304
|
+
children: [/* @__PURE__ */ f(be, { className: "h-4 w-4" }), et]
|
|
303
305
|
}),
|
|
304
306
|
/* @__PURE__ */ p("button", {
|
|
305
307
|
onClick: Z,
|
|
306
308
|
disabled: !z,
|
|
307
309
|
className: "inline-flex items-center gap-2 rounded-md border border-border-subtle px-4 py-3 text-sm font-medium text-text-primary hover:bg-bg-sunken/50 disabled:opacity-50",
|
|
308
|
-
children: [/* @__PURE__ */ f(
|
|
310
|
+
children: [/* @__PURE__ */ f(Ce, { className: "h-4 w-4" }), "Skip"]
|
|
309
311
|
}),
|
|
310
312
|
/* @__PURE__ */ p("button", {
|
|
311
|
-
onClick: () => void
|
|
313
|
+
onClick: () => void Xe(),
|
|
312
314
|
className: "inline-flex items-center gap-2 rounded-md border border-border-subtle px-4 py-3 text-sm font-medium text-text-primary hover:bg-bg-sunken/50",
|
|
313
|
-
children: [/* @__PURE__ */ f(
|
|
315
|
+
children: [/* @__PURE__ */ f(Se, { className: "h-4 w-4" }), "Reset"]
|
|
314
316
|
})
|
|
315
317
|
]
|
|
316
318
|
})
|
|
@@ -324,11 +326,11 @@ function x() {
|
|
|
324
326
|
className: "mb-4 flex items-center justify-between",
|
|
325
327
|
children: [/* @__PURE__ */ p("h3", {
|
|
326
328
|
className: "flex items-center gap-2 text-sm font-semibold text-text-primary",
|
|
327
|
-
children: [/* @__PURE__ */ f(
|
|
329
|
+
children: [/* @__PURE__ */ f(we, { className: "h-4 w-4" }), "Focus Goals"]
|
|
328
330
|
}), /* @__PURE__ */ p("button", {
|
|
329
|
-
onClick:
|
|
331
|
+
onClick: Ge,
|
|
330
332
|
className: "inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-1.5 text-sm font-medium text-action-primary-text hover:bg-action-primary-bg/90",
|
|
331
|
-
children: [/* @__PURE__ */ f(
|
|
333
|
+
children: [/* @__PURE__ */ f(xe, { className: "h-4 w-4" }), "Add Goal"]
|
|
332
334
|
})]
|
|
333
335
|
}), E.length === 0 ? /* @__PURE__ */ f("p", {
|
|
334
336
|
className: "py-6 text-center text-sm text-text-secondary",
|
|
@@ -360,16 +362,16 @@ function x() {
|
|
|
360
362
|
children: [t, "%"]
|
|
361
363
|
}),
|
|
362
364
|
/* @__PURE__ */ f("button", {
|
|
363
|
-
onClick: () =>
|
|
365
|
+
onClick: () => Ke(e),
|
|
364
366
|
className: "rounded-md p-1.5 text-text-secondary hover:bg-bg-sunken hover:text-text-primary",
|
|
365
367
|
"aria-label": "Edit goal",
|
|
366
|
-
children: /* @__PURE__ */ f(
|
|
368
|
+
children: /* @__PURE__ */ f(ye, { className: "h-4 w-4" })
|
|
367
369
|
}),
|
|
368
370
|
/* @__PURE__ */ f("button", {
|
|
369
371
|
onClick: () => P(e),
|
|
370
372
|
className: "rounded-md p-1.5 text-text-secondary hover:bg-status-error-bg hover:text-status-error-text",
|
|
371
373
|
"aria-label": "Delete goal",
|
|
372
|
-
children: /* @__PURE__ */ f(
|
|
374
|
+
children: /* @__PURE__ */ f(Te, { className: "h-4 w-4" })
|
|
373
375
|
})
|
|
374
376
|
]
|
|
375
377
|
})]
|
|
@@ -385,7 +387,7 @@ function x() {
|
|
|
385
387
|
})]
|
|
386
388
|
}),
|
|
387
389
|
/* @__PURE__ */ p(i, {
|
|
388
|
-
open:
|
|
390
|
+
open: We,
|
|
389
391
|
onClose: () => A(!1),
|
|
390
392
|
title: j ? "Edit Focus Goal" : "Add Focus Goal",
|
|
391
393
|
description: "Set a target number of focus sessions",
|
|
@@ -394,12 +396,12 @@ function x() {
|
|
|
394
396
|
className: "rounded-md border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken/50",
|
|
395
397
|
children: "Cancel"
|
|
396
398
|
}), /* @__PURE__ */ f("button", {
|
|
397
|
-
onClick:
|
|
399
|
+
onClick: qe,
|
|
398
400
|
disabled: D || O || Number(F.target) <= 0,
|
|
399
401
|
className: "rounded-md bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:bg-action-primary-bg/90 disabled:opacity-50",
|
|
400
402
|
children: D || O ? "Saving..." : j ? "Save Changes" : "Add Goal"
|
|
401
403
|
})] }),
|
|
402
|
-
children: [(
|
|
404
|
+
children: [(ze || Ve) && /* @__PURE__ */ f("div", {
|
|
403
405
|
className: "mb-4 rounded-lg border border-status-error-bg/40 bg-status-error-bg p-3 text-sm text-status-error-text",
|
|
404
406
|
children: "Failed to save goal. Please try again."
|
|
405
407
|
}), /* @__PURE__ */ p("div", {
|
|
@@ -479,12 +481,12 @@ function x() {
|
|
|
479
481
|
className: "rounded-md border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken/50",
|
|
480
482
|
children: "Cancel"
|
|
481
483
|
}), /* @__PURE__ */ f("button", {
|
|
482
|
-
onClick:
|
|
484
|
+
onClick: Je,
|
|
483
485
|
disabled: k,
|
|
484
486
|
className: "rounded-md bg-status-error-bg px-4 py-2 text-sm font-medium text-status-error-text hover:bg-status-error-bg/90 disabled:opacity-50",
|
|
485
487
|
children: k ? "Deleting..." : "Delete"
|
|
486
488
|
})] }),
|
|
487
|
-
children: [
|
|
489
|
+
children: [Ue && /* @__PURE__ */ f("div", {
|
|
488
490
|
className: "mb-4 rounded-lg border border-status-error-bg/40 bg-status-error-bg p-3 text-sm text-status-error-text",
|
|
489
491
|
children: "Failed to delete goal. Please try again."
|
|
490
492
|
}), /* @__PURE__ */ p("p", {
|