Cleanup: Remove low value StreamingContextType interface. (#585)

This commit is contained in:
Jacob Richman 2025-05-28 19:46:08 +00:00 committed by GitHub
parent 05a49702d8
commit 00805cb2cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 41 deletions

View File

@ -41,10 +41,7 @@ import { useHistory } from './hooks/useHistoryManager.js';
import process from 'node:process';
import { getErrorMessage, type Config } from '@gemini-code/server';
import { useLogger } from './hooks/useLogger.js';
import {
StreamingContext,
StreamingContextType,
} from './contexts/StreamingContext.js';
import { StreamingContext } from './contexts/StreamingContext.js';
interface AppProps {
config: Config;
@ -182,11 +179,6 @@ export const App = ({
useLoadingIndicator(streamingState);
const showAutoAcceptIndicator = useAutoAcceptIndicator({ config });
const streamingContextValue: StreamingContextType = useMemo(
() => ({ streamingState }),
[streamingState],
);
const handleFinalSubmit = useCallback(
(submittedValue: string) => {
const trimmedValue = submittedValue.trim();
@ -278,7 +270,7 @@ export const App = ({
}, [consoleMessages, config]);
return (
<StreamingContext.Provider value={streamingContextValue}>
<StreamingContext.Provider value={streamingState}>
<Box flexDirection="column" marginBottom={1} width="90%">
{/*
* The Static component is an Ink intrinsic in which there can only be 1 per application.

View File

@ -23,7 +23,7 @@ interface GeminiRespondingSpinnerProps {
export const GeminiRespondingSpinner: React.FC<
GeminiRespondingSpinnerProps
> = ({ nonRespondingDisplay, spinnerType = 'dots' }) => {
const { streamingState } = useStreamingContext();
const streamingState = useStreamingContext();
if (streamingState === StreamingState.Responding) {
return <Spinner type={spinnerType} />;

View File

@ -8,10 +8,7 @@ import React from 'react';
import { render } from 'ink-testing-library';
import { Text } from 'ink';
import { LoadingIndicator } from './LoadingIndicator.js';
import {
StreamingContext,
StreamingContextType,
} from '../contexts/StreamingContext.js';
import { StreamingContext } from '../contexts/StreamingContext.js';
import { StreamingState } from '../types.js';
import { vi } from 'vitest';
@ -22,7 +19,7 @@ vi.mock('./GeminiRespondingSpinner.js', () => ({
}: {
nonRespondingDisplay?: string;
}) => {
const { streamingState } = React.useContext(StreamingContext)!;
const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>;
} else if (nonRespondingDisplay) {
@ -36,9 +33,7 @@ const renderWithContext = (
ui: React.ReactElement,
streamingStateValue: StreamingState,
) => {
const contextValue: StreamingContextType = {
streamingState: streamingStateValue,
};
const contextValue: StreamingState = streamingStateValue;
return render(
<StreamingContext.Provider value={contextValue}>
{ui}
@ -129,9 +124,7 @@ describe('<LoadingIndicator />', () => {
// Transition to Responding
rerender(
<StreamingContext.Provider
value={{ streamingState: StreamingState.Responding }}
>
<StreamingContext.Provider value={StreamingState.Responding}>
<LoadingIndicator
currentLoadingPhrase="Now Responding"
elapsedTime={2}
@ -145,9 +138,7 @@ describe('<LoadingIndicator />', () => {
// Transition to WaitingForConfirmation
rerender(
<StreamingContext.Provider
value={{ streamingState: StreamingState.WaitingForConfirmation }}
>
<StreamingContext.Provider value={StreamingState.WaitingForConfirmation}>
<LoadingIndicator
currentLoadingPhrase="Please Confirm"
elapsedTime={15}
@ -162,9 +153,7 @@ describe('<LoadingIndicator />', () => {
// Transition back to Idle
rerender(
<StreamingContext.Provider
value={{ streamingState: StreamingState.Idle }}
>
<StreamingContext.Provider value={StreamingState.Idle}>
<LoadingIndicator {...defaultProps} />
</StreamingContext.Provider>,
);

View File

@ -22,7 +22,7 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
elapsedTime,
rightContent,
}) => {
const { streamingState } = useStreamingContext();
const streamingState = useStreamingContext();
if (streamingState === StreamingState.Idle) {
return null;

View File

@ -9,10 +9,7 @@ import { render } from 'ink-testing-library';
import { ToolMessage, ToolMessageProps } from './ToolMessage.js';
import { StreamingState, ToolCallStatus } from '../../types.js';
import { Text } from 'ink';
import {
StreamingContext,
StreamingContextType,
} from '../../contexts/StreamingContext.js';
import { StreamingContext } from '../../contexts/StreamingContext.js';
// Mock child components or utilities if they are complex or have side effects
vi.mock('../GeminiRespondingSpinner.js', () => ({
@ -21,7 +18,7 @@ vi.mock('../GeminiRespondingSpinner.js', () => ({
}: {
nonRespondingDisplay?: string;
}) => {
const { streamingState } = React.useContext(StreamingContext)!;
const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>;
}
@ -48,7 +45,7 @@ const renderWithContext = (
ui: React.ReactElement,
streamingState: StreamingState,
) => {
const contextValue: StreamingContextType = { streamingState };
const contextValue: StreamingState = streamingState;
return render(
<StreamingContext.Provider value={contextValue}>
{ui}

View File

@ -7,15 +7,11 @@
import React, { createContext } from 'react';
import { StreamingState } from '../types.js';
export interface StreamingContextType {
streamingState: StreamingState;
}
export const StreamingContext = createContext<StreamingContextType | undefined>(
export const StreamingContext = createContext<StreamingState | undefined>(
undefined,
);
export const useStreamingContext = (): StreamingContextType => {
export const useStreamingContext = (): StreamingState => {
const context = React.useContext(StreamingContext);
if (context === undefined) {
throw new Error(