Skip to content
This repository was archived by the owner on Oct 9, 2026. It is now read-only.

Display pages read as tooltip on books and book calendar - #124

Merged
GeorgeSG merged 2 commits into
Ko-Insight:masterfrom
binarymelon:feature/calendar-pages-read
Aug 7, 2026
Merged

GeorgeSG merged 2 commits into
Ko-Insight:masterfrom
binarymelon:feature/calendar-pages-read

Conversation

@binarymelon

Copy link
Copy Markdown
Collaborator

Add pages read as tool-tip on calendar views

@@ -0,0 +1,73 @@
import { BookWithData, PageStat } from '@koinsight/common/types';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of computation going on in this file. So far I've been trying to keep this on the server side, especially if it's computed every time the page is rendered. Maybe we should try to move the logic so it gets fetched by BookWithData (we should also come up with a better name 😅)

Comment thread apps/web/src/utils/book-progress.ts Outdated
Comment on lines +29 to +49
export function normalizeRanges(ranges: Range[]): Range[] {
const epsilon = 1e-9;
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
const result: Range[] = [];

for (const [start, end] of sorted) {
if (result.length === 0) {
result.push([start, end]);
continue;
}

const last = result[result.length - 1];
if (start <= last[1] + epsilon) {
last[1] = Math.max(last[1], end);
} else {
result.push([start, end]);
}
}

return result;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is duplicated from the server side? One more reason to keep the computation there

@GeorgeSG GeorgeSG left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants