From 207b1b593a4689f257c7bef5c705ce2510cf9844 Mon Sep 17 00:00:00 2001
From: Philipinho <16838612+Philipinho@users.noreply.github.com>
Date: Sat, 31 Jan 2026 23:59:40 +0000
Subject: [PATCH] cleanup diff count
---
.../components/history-editor.tsx | 61 +++++--------------
.../components/history-modal-body.tsx | 27 ++++++--
.../page-history/components/history-view.tsx | 14 ++++-
3 files changed, 49 insertions(+), 53 deletions(-)
diff --git a/apps/client/src/features/page-history/components/history-editor.tsx b/apps/client/src/features/page-history/components/history-editor.tsx
index b9db1a6b..8905e43c 100644
--- a/apps/client/src/features/page-history/components/history-editor.tsx
+++ b/apps/client/src/features/page-history/components/history-editor.tsx
@@ -1,20 +1,22 @@
import "@/features/editor/styles/index.css";
-import { useEffect, useState } from "react";
+import { useEffect } from "react";
import { EditorContent, useEditor } from "@tiptap/react";
import { mainExtensions } from "@/features/editor/extensions/extensions";
-import { Badge, Divider, Group, Text, Title } from "@mantine/core";
+import { Title } from "@mantine/core";
import { Decoration, DecorationSet } from "@tiptap/pm/view";
-import classes from "./history-diff.module.css";
import historyClasses from "./history.module.css";
import { recreateTransform } from "@docmost/editor-ext";
import { DOMSerializer, Node } from "@tiptap/pm/model";
import { ChangeSet, simplifyChanges } from "prosemirror-changeset";
+export type DiffCounts = { added: number; deleted: number };
+
export interface HistoryEditorProps {
title: string;
content: any;
previousContent?: any;
highlightChanges?: boolean;
+ onDiffCalculated?: (counts: DiffCounts) => void;
}
export function HistoryEditor({
@@ -22,20 +24,13 @@ export function HistoryEditor({
content,
previousContent,
highlightChanges = true,
+ onDiffCalculated,
}: HistoryEditorProps) {
const editor = useEditor({
extensions: mainExtensions,
editable: false,
});
- const [diffCounts, setDiffCounts] = useState<{
- added: number;
- deleted: number;
- }>({
- added: 0,
- deleted: 0,
- });
-
useEffect(() => {
if (!editor || !content) return;
@@ -164,7 +159,7 @@ export function HistoryEditor({
editor.commands.setContent(content);
}
- setDiffCounts({ added: addedCount, deleted: deletedCount });
+ onDiffCalculated?.({ added: addedCount, deleted: deletedCount });
editor.setOptions({
editorProps: {
@@ -176,38 +171,14 @@ export function HistoryEditor({
}, [title, content, editor, previousContent, highlightChanges]);
return (
- <>
-
-
{title}
-
- {previousContent && (
- <>
-
-
-
- Changes
-
- +{diffCounts.added} added
-
-
- -{diffCounts.deleted} deleted
-
-
- (added = green, deleted = red/strikethrough)
-
-
-
-
- >
- )}
-
- {editor && (
-
- )}
-
- >
+
+
{title}
+ {editor && (
+
+ )}
+
);
}
diff --git a/apps/client/src/features/page-history/components/history-modal-body.tsx b/apps/client/src/features/page-history/components/history-modal-body.tsx
index 2724308b..a2787526 100644
--- a/apps/client/src/features/page-history/components/history-modal-body.tsx
+++ b/apps/client/src/features/page-history/components/history-modal-body.tsx
@@ -1,4 +1,5 @@
-import { Paper, ScrollArea, Switch } from "@mantine/core";
+import { Badge, Group, Paper, ScrollArea, Switch } from "@mantine/core";
+import { DiffCounts } from "@/features/page-history/components/history-editor";
import HistoryList from "@/features/page-history/components/history-list";
import classes from "./history.module.css";
import { useAtom } from "jotai";
@@ -19,6 +20,7 @@ export default function HistoryModalBody({ pageId }: Props) {
activeHistoryPrevIdAtom,
);
const [highlightChanges, setHighlightChanges] = useState(true);
+ const [diffCounts, setDiffCounts] = useState(null);
useEffect(() => {
setActiveHistoryId("");
@@ -41,6 +43,7 @@ export default function HistoryModalBody({ pageId }: Props) {
historyId={activeHistoryId}
prevHistoryId={activeHistoryPrevId}
highlightChanges={highlightChanges}
+ onDiffCalculated={setDiffCounts}
/>
)}
@@ -59,11 +62,23 @@ export default function HistoryModalBody({ pageId }: Props) {
transform: "translateX(-50%)",
}}
>
- setHighlightChanges(e.currentTarget.checked)}
- />
+
+ {diffCounts && (
+
+
+ +{diffCounts.added}
+
+
+ -{diffCounts.deleted}
+
+
+ )}
+ setHighlightChanges(e.currentTarget.checked)}
+ />
+
)}
diff --git a/apps/client/src/features/page-history/components/history-view.tsx b/apps/client/src/features/page-history/components/history-view.tsx
index 1a265757..7b749bc5 100644
--- a/apps/client/src/features/page-history/components/history-view.tsx
+++ b/apps/client/src/features/page-history/components/history-view.tsx
@@ -1,14 +1,23 @@
import { usePageHistoryQuery } from "@/features/page-history/queries/page-history-query";
-import { HistoryEditor } from "@/features/page-history/components/history-editor";
+import {
+ DiffCounts,
+ HistoryEditor,
+} from "@/features/page-history/components/history-editor";
import { useTranslation } from "react-i18next";
interface HistoryProps {
historyId: string;
prevHistoryId?: string;
highlightChanges?: boolean;
+ onDiffCalculated?: (counts: DiffCounts) => void;
}
-function HistoryView({ historyId, prevHistoryId, highlightChanges }: HistoryProps) {
+function HistoryView({
+ historyId,
+ prevHistoryId,
+ highlightChanges,
+ onDiffCalculated,
+}: HistoryProps) {
const { t } = useTranslation();
const {
data,
@@ -37,6 +46,7 @@ function HistoryView({ historyId, prevHistoryId, highlightChanges }: HistoryProp
title={data.title}
previousContent={!isErrorPrev ? prevData?.content : undefined}
highlightChanges={highlightChanges}
+ onDiffCalculated={onDiffCalculated}
/>
)