From a7dd7b4298d181f6abe8bf12663f960b2a002bb9 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:25:12 +1300 Subject: [PATCH] Add activeModelSelector Active Model details are used in multiple places. So makes sense to have a selector for it. --- .../features/system/store/systemSelectors.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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, + }, + } +);