Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@
0 0 14px color-mix(in srgb, var(--rc-bg) 60%, transparent);
}

/* A day of the activity heatmap's grid: 2px, under the smallest radius step, on a 7px cell. */
/* A day of the activity heatmap's grid: a fixed 2px corner, so the cells stay squares at any radius setting. */
.rc-heat-cell {
border-radius: 2px;
}
Expand Down
20 changes: 10 additions & 10 deletions apps/desktop/src/ui/ActivityProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* the page below is set to.
*/

import { useMemo, useState } from "react";
import { useLayoutEffect, useMemo, useRef, useState } from "react";
import type { UsageReport } from "../acp/rustcode";
import { count } from "../lib/plural";
import {
Expand Down Expand Up @@ -67,10 +67,16 @@ function cellTip(cell: ProfileCell, mode: ProfileMode): string {

export function ActivityProfile({ report, error }: { report: UsageReport | null; error?: string | null }) {
const [mode, setMode] = useState<ProfileMode>("daily");
const scroller = useRef<HTMLDivElement>(null);
const rows = report?.rows;
const summary = useMemo(() => (rows ? profileSummary(rows) : undefined), [rows]);
const columns = useMemo(() => (rows ? profileWeeks(rows, mode) : []), [rows, mode]);
const months = useMemo(() => monthLabels(columns), [columns]);
const loaded = Boolean(rows);
useLayoutEffect(() => {
const el = scroller.current;
if (loaded && el) el.scrollLeft = el.scrollWidth;
}, [loaded]);

const streak = summary?.streak;
const best =
Expand Down Expand Up @@ -156,14 +162,14 @@ export function ActivityProfile({ report, error }: { report: UsageReport | null;
/>
</div>
)}
<div className="overflow-x-auto p-4">
<div ref={scroller} className={cx("overflow-x-auto", !rows && "p-4")}>
{!rows ? (
<Skeleton className="h-[110px] w-full" />
) : (
<div
role="img"
aria-label={`Tokens per day over the last ${PROFILE_WEEKS} weeks, ${mode}.`}
className="flex min-w-[560px] flex-col gap-1.5"
className="flex min-w-[932px] flex-col gap-1.5 p-4"
>
<div className="flex gap-[3px]">
{columns.map((week, index) => (
Expand All @@ -174,13 +180,7 @@ export function ActivityProfile({ report, error }: { report: UsageReport | null;
{week.map((cell, day) =>
cell ? (
<Tooltip key={cell.day} label={cellTip(cell, mode)}>
<span
className={cx(
"aspect-square w-full rounded-inline",
SHADE[cell.level],
streak?.days.has(cell.day) && "ring-1 ring-accent/60",
)}
/>
<span className={cx("rc-heat-cell aspect-square w-full", SHADE[cell.level])} />
</Tooltip>
) : (
<span key={`future-${index}-${day}`} className="aspect-square w-full" />
Expand Down
Loading