diff --git a/invokeai/frontend/src/features/system/store/systemSelectors.ts b/invokeai/frontend/src/features/system/store/systemSelectors.ts index 9c1322cf92..2c8cd68d40 100644 --- a/invokeai/frontend/src/features/system/store/systemSelectors.ts +++ b/invokeai/frontend/src/features/system/store/systemSelectors.ts @@ -1,6 +1,31 @@ +import { createSelector } from '@reduxjs/toolkit'; import { RootState } from 'app/store'; import { SystemState } from './systemSlice'; +import _ from 'lodash'; export const systemSelector = (state: RootState): SystemState => state.system; export const toastQueueSelector = (state: RootState) => state.system.toastQueue; + +export const activeModelSelector = createSelector( + systemSelector, + (system) => { + const { model_list } = system; + const activeModel = _.reduce( + model_list, + (acc, model, key) => { + if (model.status === 'active') { + acc = key; + } + return acc; + }, + '' + ); + return { ...model_list[activeModel], name: activeModel }; + }, + { + memoizeOptions: { + resultEqualityCheck: _.isEqual, + }, + } +);