mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 15:02:04 +00:00
feat(coach): move conversations into a collapsible right panel
The Coach page gets a conversations panel on the right of the thread. From 1280 px it docks beside the thread and slides open and shut; the reading column keeps its width either way and only its centring moves. It is open on a first visit and remembers the last choice per device. Below 1280 px it is a sheet from the right. The toggle sits at the trailing edge of the top bar, through a small page-owned slot the top bar now renders. The panel lists every conversation grouped by recency, with a row menu to rename in place (Enter saves, Escape cancels without closing the panel) and delete with the existing undo toast. The undo window now survives the sheet closing. New chat is the round button at the panel's bottom right, and picking or starting a conversation keeps ?c= in the URL. The gear in the panel header opens quick settings: a popover from md up, a bottom sheet on a phone. It switches the answering provider (chain reordered through the existing route), the model and reasoning level where the person owns them, and shows what the Coach can see. Keys, the Codex sign-in and the fallback chain stay in Settings > AI. The drawer's gear opens the same overlay. The composer's + menu is gone. Settings > Coach links to /coach?settings=data, which opens the overlay on what the Coach can see instead of a rail that no longer exists.
This commit is contained in:
1 parent
1cb50ed21d
commit
12153fe143
33 files changed
+2074
-428
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { groupConversationsByRecency } from "../coach-conversation-groups";
|
||||
|
||||
// The suite runs with TZ=UTC, so local day boundaries are UTC midnights.
|
||||
const NOW = new Date("2026-10-04T15:00:00.000Z");
|
||||
|
||||
function c(id: string, updatedAt: string) {
|
||||
return { id, updatedAt };
|
||||
}
|
||||
|
||||
describe("groupConversationsByRecency", () => {
|
||||
it("buckets by local day: today, yesterday, the six days before, earlier", () => {
|
||||
const groups = groupConversationsByRecency(
|
||||
[
|
||||
c("a", "2026-10-04T00:00:00.000Z"), // today, at midnight
|
||||
c("b", "2026-10-03T23:59:59.000Z"), // yesterday, last second
|
||||
c("c", "2026-10-03T00:00:00.000Z"), // yesterday, first second
|
||||
c("d", "2026-09-28T00:00:00.000Z"), // six days before today
|
||||
c("e", "2026-09-27T23:59:59.000Z"), // one second older: earlier
|
||||
],
|
||||
NOW,
|
||||
);
|
||||
expect(groups.map((g) => [g.id, g.conversations.map((x) => x.id)])).toEqual(
|
||||
[
|
||||
["today", ["a"]],
|
||||
["yesterday", ["b", "c"]],
|
||||
["thisWeek", ["d"]],
|
||||
["earlier", ["e"]],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it("drops empty groups and keeps the caller's order inside a group", () => {
|
||||
const groups = groupConversationsByRecency(
|
||||
[c("x", "2026-01-02T00:00:00.000Z"), c("y", "2026-03-02T00:00:00.000Z")],
|
||||
NOW,
|
||||
);
|
||||
expect(groups).toHaveLength(1);
|
||||
expect(groups[0].id).toBe("earlier");
|
||||
expect(groups[0].labelKey).toBe("insights.coach.history.groupEarlier");
|
||||
expect(groups[0].conversations.map((x) => x.id)).toEqual(["x", "y"]);
|
||||
});
|
||||
|
||||
it("returns nothing for an empty list", () => {
|
||||
expect(groupConversationsByRecency([], NOW)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Bucket Coach conversations by how recently they were last touched: Today,
|
||||
* Yesterday, This week (the six days before yesterday), Earlier.
|
||||
*
|
||||
* Shared by the Coach page's conversations panel and the standalone
|
||||
* conversation list, so both group a thread the same way. Comparisons run
|
||||
* against LOCAL day boundaries, so "Today" follows the person's own midnight
|
||||
* rather than UTC's. Empty groups are dropped; order inside a group is the
|
||||
* caller's (the server already returns `updatedAt desc`).
|
||||
*/
|
||||
export type CoachRecencyGroupId =
|
||||
"today" | "yesterday" | "thisWeek" | "earlier";
|
||||
|
||||
export interface CoachRecencyGroup<T> {
|
||||
id: CoachRecencyGroupId;
|
||||
labelKey: string;
|
||||
conversations: T[];
|
||||
}
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
const GROUPS: ReadonlyArray<{ id: CoachRecencyGroupId; labelKey: string }> = [
|
||||
{ id: "today", labelKey: "insights.coach.history.groupToday" },
|
||||
{ id: "yesterday", labelKey: "insights.coach.history.groupYesterday" },
|
||||
{ id: "thisWeek", labelKey: "insights.coach.history.groupThisWeek" },
|
||||
{ id: "earlier", labelKey: "insights.coach.history.groupEarlier" },
|
||||
];
|
||||
|
||||
export function groupConversationsByRecency<T extends { updatedAt: string }>(
|
||||
conversations: readonly T[],
|
||||
now: Date = new Date(),
|
||||
): CoachRecencyGroup<T>[] {
|
||||
const startOfToday = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth(),
|
||||
now.getDate(),
|
||||
).getTime();
|
||||
const startOfYesterday = startOfToday - DAY_MS;
|
||||
const startOfWeek = startOfToday - 6 * DAY_MS;
|
||||
|
||||
const buckets: Record<CoachRecencyGroupId, T[]> = {
|
||||
today: [],
|
||||
yesterday: [],
|
||||
thisWeek: [],
|
||||
earlier: [],
|
||||
};
|
||||
for (const conversation of conversations) {
|
||||
const updated = new Date(conversation.updatedAt).getTime();
|
||||
if (updated >= startOfToday) buckets.today.push(conversation);
|
||||
else if (updated >= startOfYesterday) buckets.yesterday.push(conversation);
|
||||
else if (updated >= startOfWeek) buckets.thisWeek.push(conversation);
|
||||
else buckets.earlier.push(conversation);
|
||||
}
|
||||
|
||||
return GROUPS.map((g) => ({ ...g, conversations: buckets[g.id] })).filter(
|
||||
(g) => g.conversations.length > 0,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user