Add Timelog: show the timer in the tab title and simplify the code

This is the first commit of the project, at the state that runs on
timelog.minhtrannhat.com.

Changes in this state:
- Remove redundant UI text from the sidebar, timer and insights pages.
- Show the remaining time and tag in the browser tab title while a
  session runs.
- Put the shared record type and the due and end helpers in
  src/shared/record.ts.
- Remove the startup tag migration and the one-time Forest import
  script. The live data does not need them.
- Remove unused CSS, Playwright ignore rules and duplicate helpers.
- Do not track Forest CSV exports, because they contain private data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
minhtrannhatandClaude Opus 5.5 committed 2026-11-05 00:42:58 -05:00
commit a6ca255835
38 files changed
+2069

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, test } from "bun:test";
import { exportForestCsv, importForestCsv, parseCsv } from "../src/client/csv.ts";
import { overlapMs, rangeWindow, totals } from "../src/client/analytics.ts";
import { normalizeTag } from "../src/shared/tag.ts";
describe("Forest CSV", () => {
test("parses quotes, commas, and newlines", () => {
expect(parseCsv('a,b\r\n"one,two","line 1\nline 2"\r\n')).toEqual([
["a", "b"], ["one,two", "line 1\nline 2"],
]);
});
test("imports the supplied Forest export and round trips its data", async () => {
const source = [...new Bun.Glob("*.csv").scanSync(".")][0];
expect(source).toBeDefined();
const records = await importForestCsv(await Bun.file(source!).text());
expect(records).toHaveLength(2709);
expect(new Set(records.map(record => record.id)).size).toBe(records.length);
expect(records.filter(record => record.isSuccess === false)).toHaveLength(28);
expect(records.filter(record => record.tag === "Job Hunting")).toHaveLength(3);
expect(records.filter(record => record.tag === "Music")).toHaveLength(12);
expect(records.filter(record => record.tag === "Paperwork")).toHaveLength(2);
const output = parseCsv(exportForestCsv(records));
expect(output).toHaveLength(2710);
expect(output[0]).toEqual(["Start Time", "End Time", "Tag", "Note", "Tree Type", "Is Success"]);
expect(output[1]).toEqual([
"2021-04-28T20:38:16.930-0400", "2021-04-28T21:03:16.930-0400", "Study", "", "Cedar", "True",
]);
});
});
test("tag capitalization keeps mixed-case names and short acronyms", () => {
expect(normalizeTag(" job hunting ")).toBe("Job Hunting");
expect(normalizeTag("iOS AI study")).toBe("iOS AI Study");
});
describe("insights", () => {
test("splits a session crossing midnight and counts early stops", () => {
const start = +new Date(2026, 8, 20, 23, 30);
const end = +new Date(2026, 8, 21, 0, 30);
const record = {
id: "session_test", startMs: start, endMs: end, targetSeconds: 7200, tag: "Study", note: "",
treeType: "", isSuccess: false, source: "timer" as const, rawStart: null, rawEnd: null, deleted: false,
};
const first = rangeWindow("day", 0, new Date(2026, 8, 20));
const second = rangeWindow("day", 0, new Date(2026, 8, 21));
expect(overlapMs(record, first.start, first.end)).toBe(30 * 60 * 1000);
expect(totals([record], second).totalMs).toBe(30 * 60 * 1000);
expect(totals([record], first).tags).toEqual([["Study", 30 * 60 * 1000]]);
});
});