mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* feat: Live document stats in the corner of the editor Moves word and character counts out of the Insights dialog into an optional bar in the bottom corner of the document that updates as you type, adding paragraph count and reading time. Enabled with a new "Show editing stats" preference, or toggled with Cmd+Shift+G. The counts switch to the selection while text is selected, and fade out while idle. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: Stats bar should not intercept clicks in the editor Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Add toggle to document menu and command menu * fix: Empty documents should not report a one minute read Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { EyeIcon } from "outline-icons";
|
|
import { useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTextStats } from "~/hooks/useTextStats";
|
|
import type Document from "~/models/Document";
|
|
import { ProsemirrorHelper } from "~/models/helpers/ProsemirrorHelper";
|
|
|
|
const ReadingTime = ({ document }: { document: Document }) => {
|
|
const { t } = useTranslation();
|
|
const markdown = useMemo(
|
|
() => ProsemirrorHelper.toMarkdown(document),
|
|
[document]
|
|
);
|
|
const stats = useTextStats(markdown);
|
|
|
|
const readingTimeMinutes = stats.readingTime;
|
|
const hours = Math.floor(readingTimeMinutes / 60);
|
|
const minutes = readingTimeMinutes % 60;
|
|
|
|
if (!readingTimeMinutes) {
|
|
return null;
|
|
}
|
|
|
|
let readingTimeText;
|
|
if (hours > 0) {
|
|
if (minutes > 0) {
|
|
readingTimeText = t(`{{ hours }}h {{ minutes }}m read`, {
|
|
hours,
|
|
minutes,
|
|
});
|
|
} else {
|
|
readingTimeText = t(`{{ hours }}h read`, { hours });
|
|
}
|
|
} else {
|
|
readingTimeText = t(`{{ minutes }}m read`, { minutes: readingTimeMinutes });
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<EyeIcon size={18} />
|
|
{readingTimeText}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ReadingTime;
|