mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16:25:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
} from 'react'
|
||||
import { createStore, type Store } from '../state/store.js'
|
||||
import React, { createContext, useContext, useState, useSyncExternalStore } from 'react';
|
||||
import { createStore, type Store } from '../state/store.js';
|
||||
|
||||
export type VoiceState = {
|
||||
voiceState: 'idle' | 'recording' | 'processing'
|
||||
voiceError: string | null
|
||||
voiceInterimTranscript: string
|
||||
voiceAudioLevels: number[]
|
||||
voiceWarmingUp: boolean
|
||||
}
|
||||
voiceState: 'idle' | 'recording' | 'processing';
|
||||
voiceError: string | null;
|
||||
voiceInterimTranscript: string;
|
||||
voiceAudioLevels: number[];
|
||||
voiceWarmingUp: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_STATE: VoiceState = {
|
||||
voiceState: 'idle',
|
||||
@@ -20,29 +15,29 @@ const DEFAULT_STATE: VoiceState = {
|
||||
voiceInterimTranscript: '',
|
||||
voiceAudioLevels: [],
|
||||
voiceWarmingUp: false,
|
||||
}
|
||||
};
|
||||
|
||||
type VoiceStore = Store<VoiceState>
|
||||
type VoiceStore = Store<VoiceState>;
|
||||
|
||||
const VoiceContext = createContext<VoiceStore | null>(null)
|
||||
const VoiceContext = createContext<VoiceStore | null>(null);
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode
|
||||
}
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export function VoiceProvider({ children }: Props): React.ReactNode {
|
||||
// Store is created once — stable context value means the provider never
|
||||
// triggers re-renders. Consumers subscribe to slices via useVoiceState.
|
||||
const [store] = useState(() => createStore<VoiceState>(DEFAULT_STATE))
|
||||
return <VoiceContext.Provider value={store}>{children}</VoiceContext.Provider>
|
||||
const [store] = useState(() => createStore<VoiceState>(DEFAULT_STATE));
|
||||
return <VoiceContext.Provider value={store}>{children}</VoiceContext.Provider>;
|
||||
}
|
||||
|
||||
function useVoiceStore(): VoiceStore {
|
||||
const store = useContext(VoiceContext)
|
||||
const store = useContext(VoiceContext);
|
||||
if (!store) {
|
||||
throw new Error('useVoiceState must be used within a VoiceProvider')
|
||||
throw new Error('useVoiceState must be used within a VoiceProvider');
|
||||
}
|
||||
return store
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +45,9 @@ function useVoiceStore(): VoiceStore {
|
||||
* value changes (compared via Object.is).
|
||||
*/
|
||||
export function useVoiceState<T>(selector: (state: VoiceState) => T): T {
|
||||
const store = useVoiceStore()
|
||||
const get = () => selector(store.getState())
|
||||
return useSyncExternalStore(store.subscribe, get, get)
|
||||
const store = useVoiceStore();
|
||||
const get = () => selector(store.getState());
|
||||
return useSyncExternalStore(store.subscribe, get, get);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,10 +55,8 @@ export function useVoiceState<T>(selector: (state: VoiceState) => T): T {
|
||||
* store.setState is synchronous: callers can read getVoiceState() immediately
|
||||
* after to observe the new value (VoiceKeybindingHandler relies on this).
|
||||
*/
|
||||
export function useSetVoiceState(): (
|
||||
updater: (prev: VoiceState) => VoiceState,
|
||||
) => void {
|
||||
return useVoiceStore().setState
|
||||
export function useSetVoiceState(): (updater: (prev: VoiceState) => VoiceState) => void {
|
||||
return useVoiceStore().setState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,5 +65,5 @@ export function useSetVoiceState(): (
|
||||
* inside event handlers that need to read state set earlier in the same tick.
|
||||
*/
|
||||
export function useGetVoiceState(): () => VoiceState {
|
||||
return useVoiceStore().getState
|
||||
return useVoiceStore().getState;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user