Skip to content

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

Open
binarymelon wants to merge 2 commits into
Ko-Insight:masterfrom
binarymelon:feature/calendar-pages-read
Open

Display pages read as tooltip on books and book calendar#124
binarymelon wants to merge 2 commits into
Ko-Insight:masterfrom
binarymelon:feature/calendar-pages-read

Conversation

@binarymelon

Copy link
Copy Markdown
Contributor

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants