diff --git a/app/actions/data.ts b/app/actions/data.ts index 925887c..ee8b9e9 100644 --- a/app/actions/data.ts +++ b/app/actions/data.ts @@ -19,6 +19,7 @@ import { import { selectAIProvider, + selectAPIKeys, selectAttachedImage, selectChangesMade, selectCurrentSprout, @@ -114,7 +115,10 @@ export const selectSprout = (sprout : SproutLocation, skipCanonicalize = false) if (!skipCanonicalize) dispatch(canonicalizePath()); }; -export const setAPIKey = (provider: ModelProvider, key : string) : ThunkSomeAction => (dispatch) => { +export const setAPIKey = (provider: ModelProvider, key : string) : ThunkSomeAction => (dispatch, getState) => { + const state = getState(); + const apiKeys = selectAPIKeys(state); + if (apiKeys[provider] === key) return; dispatch({ type: SET_API_KEY, provider, diff --git a/app/components/sprout-view.ts b/app/components/sprout-view.ts index b4359f2..188e5db 100644 --- a/app/components/sprout-view.ts +++ b/app/components/sprout-view.ts @@ -651,6 +651,9 @@ class SproutView extends connect(store)(PageViewElement) { this._focusTextArea(); } if (changedProps.has('_apiKeys')) { + //This will have a few extra sets as multiple are set, but it will + //settle because the action creator checks for equality. Previously + //in bac7ad3 before the equality check this led to an infinite loop. for (const [provider, key] of TypedObject.entries(this._apiKeys)) { if (!key) continue; store.dispatch(setAPIKey(provider, key));