( state: AtCompletionState, action: AtCompletionAction, )
| 49 | }; |
| 50 | |
| 51 | function atCompletionReducer( |
| 52 | state: AtCompletionState, |
| 53 | action: AtCompletionAction, |
| 54 | ): AtCompletionState { |
| 55 | switch (action.type) { |
| 56 | case 'INITIALIZE': |
| 57 | return { |
| 58 | ...state, |
| 59 | status: AtCompletionStatus.INITIALIZING, |
| 60 | isLoading: true, |
| 61 | }; |
| 62 | case 'INITIALIZE_SUCCESS': |
| 63 | return { ...state, status: AtCompletionStatus.READY, isLoading: false }; |
| 64 | case 'SEARCH': |
| 65 | // Keep old suggestions, don't set loading immediately |
| 66 | return { |
| 67 | ...state, |
| 68 | status: AtCompletionStatus.SEARCHING, |
| 69 | pattern: action.payload, |
| 70 | }; |
| 71 | case 'SEARCH_SUCCESS': |
| 72 | return { |
| 73 | ...state, |
| 74 | status: AtCompletionStatus.READY, |
| 75 | suggestions: action.payload, |
| 76 | isLoading: false, |
| 77 | }; |
| 78 | case 'SET_LOADING': |
| 79 | // Only show loading if we are still in a searching state |
| 80 | if (state.status === AtCompletionStatus.SEARCHING) { |
| 81 | return { ...state, isLoading: action.payload, suggestions: [] }; |
| 82 | } |
| 83 | return state; |
| 84 | case 'ERROR': |
| 85 | return { |
| 86 | ...state, |
| 87 | status: AtCompletionStatus.ERROR, |
| 88 | isLoading: false, |
| 89 | suggestions: [], |
| 90 | }; |
| 91 | case 'RESET': |
| 92 | return initialState; |
| 93 | default: |
| 94 | return state; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | export interface UseAtCompletionProps { |
| 99 | enabled: boolean; |
nothing calls this directly
no outgoing calls
no test coverage detected