返回 DeepSeek-Reasonix
useHistoryTurnNavigation.ts
根目录 / desktop / frontend / src / lib / useHistoryTurnNavigation.ts
1 import { useCallback, type RefObject } from "react";
2 import type { State, Action } from "./useController";
3 import type { TurnNavigationTarget } from "./historyTurnNavigation";
4
5 export function useHistoryTurnNavigation(states: RefObject<Map<string, State>>, sequences: RefObject<Map<string, number>>,
6 dispatch: (tab: string, action: Action) => void) {
7 return useCallback(async (tab: string, target: TurnNavigationTarget, current: () => boolean) => {
8 const state = states.current.get(tab);
9 if (!state) return "cancelled" as const;
10 const sequence = (sequences.current.get(tab) ?? 0) + 1;
11 sequences.current.set(tab, sequence);
12 const { navigateHistoryTurn } = await import("./historyTurnNavigation");
13 return navigateHistoryTurn(tab, state, () => states.current.get(tab), action => dispatch(tab, action), target,
14 () => current() && sequences.current.get(tab) === sequence);
15 }, [states, sequences, dispatch]);
16 }
17
17 lines TYPESCRIPT