mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 21:02:20 +10:00
feat(client): add compare state atoms for page history
This commit is contained in:
@@ -7,3 +7,8 @@ export const highlightChangesAtom = atom<boolean>(true);
|
|||||||
|
|
||||||
export type DiffCounts = { added: number; deleted: number; total: number };
|
export type DiffCounts = { added: number; deleted: number; total: number };
|
||||||
export const diffCountsAtom = atom<DiffCounts | null>(null);
|
export const diffCountsAtom = atom<DiffCounts | null>(null);
|
||||||
|
|
||||||
|
export type ComparePair = { newerId: string; olderId: string };
|
||||||
|
export const compareModeAtom = atom<boolean>(false);
|
||||||
|
export const compareSelectionAtom = atom<string[]>([]);
|
||||||
|
export const comparePairAtom = atom<ComparePair | null>(null);
|
||||||
|
|||||||
@@ -3,22 +3,47 @@ import { useEffect } from "react";
|
|||||||
import {
|
import {
|
||||||
activeHistoryIdAtom,
|
activeHistoryIdAtom,
|
||||||
activeHistoryPrevIdAtom,
|
activeHistoryPrevIdAtom,
|
||||||
|
compareModeAtom,
|
||||||
|
comparePairAtom,
|
||||||
|
compareSelectionAtom,
|
||||||
diffCountsAtom,
|
diffCountsAtom,
|
||||||
} from "@/features/page-history/atoms/history-atoms";
|
} from "@/features/page-history/atoms/history-atoms";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets history state when pageId changes.
|
* Resets history state when pageId changes.
|
||||||
* Clears active selection and diff counts.
|
* Clears active selection, diff counts, and compare state.
|
||||||
|
* Compare state also resets on unmount so reopening the modal starts clean.
|
||||||
*/
|
*/
|
||||||
export function useHistoryReset(pageId: string) {
|
export function useHistoryReset(pageId: string) {
|
||||||
const [, setActiveHistoryId] = useAtom(activeHistoryIdAtom);
|
const [, setActiveHistoryId] = useAtom(activeHistoryIdAtom);
|
||||||
const [, setActiveHistoryPrevId] = useAtom(activeHistoryPrevIdAtom);
|
const [, setActiveHistoryPrevId] = useAtom(activeHistoryPrevIdAtom);
|
||||||
const [, setDiffCounts] = useAtom(diffCountsAtom);
|
const [, setDiffCounts] = useAtom(diffCountsAtom);
|
||||||
|
const [, setCompareMode] = useAtom(compareModeAtom);
|
||||||
|
const [, setCompareSelection] = useAtom(compareSelectionAtom);
|
||||||
|
const [, setComparePair] = useAtom(comparePairAtom);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const resetCompare = () => {
|
||||||
|
setCompareMode(false);
|
||||||
|
setCompareSelection([]);
|
||||||
|
// @ts-ignore
|
||||||
|
setComparePair(null);
|
||||||
|
};
|
||||||
|
|
||||||
setActiveHistoryId("");
|
setActiveHistoryId("");
|
||||||
setActiveHistoryPrevId("");
|
setActiveHistoryPrevId("");
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
setDiffCounts(null);
|
setDiffCounts(null);
|
||||||
}, [pageId, setActiveHistoryId, setActiveHistoryPrevId, setDiffCounts]);
|
resetCompare();
|
||||||
|
|
||||||
|
return resetCompare;
|
||||||
|
}, [
|
||||||
|
pageId,
|
||||||
|
setActiveHistoryId,
|
||||||
|
setActiveHistoryPrevId,
|
||||||
|
setDiffCounts,
|
||||||
|
setCompareMode,
|
||||||
|
setCompareSelection,
|
||||||
|
setComparePair,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user