mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 20:14:44 -07:00
feat: introduce useRewindLogic hook for conversation history navigation (#15716)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import type {
|
||||
ConversationRecord,
|
||||
MessageRecord,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
calculateTurnStats,
|
||||
calculateRewindImpact,
|
||||
type FileChangeStats,
|
||||
} from '../utils/rewindFileOps.js';
|
||||
|
||||
export function useRewind(conversation: ConversationRecord) {
|
||||
const [selectedMessageId, setSelectedMessageId] = useState<string | null>(
|
||||
null,
|
||||
);
|
||||
const [confirmationStats, setConfirmationStats] =
|
||||
useState<FileChangeStats | null>(null);
|
||||
|
||||
const getStats = useCallback(
|
||||
(userMessage: MessageRecord) =>
|
||||
calculateTurnStats(conversation, userMessage),
|
||||
[conversation],
|
||||
);
|
||||
|
||||
const selectMessage = useCallback(
|
||||
(messageId: string) => {
|
||||
const msg = conversation.messages.find((m) => m.id === messageId);
|
||||
if (msg) {
|
||||
setSelectedMessageId(messageId);
|
||||
setConfirmationStats(calculateRewindImpact(conversation, msg));
|
||||
}
|
||||
},
|
||||
[conversation],
|
||||
);
|
||||
|
||||
const clearSelection = useCallback(() => {
|
||||
setSelectedMessageId(null);
|
||||
setConfirmationStats(null);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
selectedMessageId,
|
||||
getStats,
|
||||
confirmationStats,
|
||||
selectMessage,
|
||||
clearSelection,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user