ui: map aspect ratios instead of manually creating the array

This commit is contained in:
blessedcoolant 2023-08-30 08:52:11 +12:00
parent 8e4d288f02
commit b13a06f650
2 changed files with 5 additions and 2 deletions

View File

@ -15,6 +15,8 @@ const aspectRatios = [
{ name: '1:1', value: 1 / 1 },
];
export const mappedAspectRatios = aspectRatios.map((ar) => ar.value);
export default function ParamAspectRatio() {
const aspectRatio = useAppSelector(
(state: RootState) => state.generation.aspectRatio

View File

@ -5,6 +5,7 @@ import { configChanged } from 'features/system/store/configSlice';
import { clamp } from 'lodash-es';
import { ImageDTO } from 'services/api/types';
import { mappedAspectRatios } from '../components/Parameters/Core/ParamAspectRatio';
import { clipSkipMap } from '../types/constants';
import {
CfgScaleParam,
@ -152,7 +153,7 @@ export const generationSlice = createSlice({
},
toggleSize: (state) => {
const [width, height] = [state.width, state.height];
if (![null, 2 / 3, 16 / 9, 1 / 1].includes(height / width)) {
if (!mappedAspectRatios.includes(height / width)) {
state.aspectRatio = null;
}
state.width = height;
@ -280,7 +281,7 @@ export const generationSlice = createSlice({
setShouldLockAspectRatio: (state, action: PayloadAction<boolean>) => {
if (
action.payload === false &&
![null, 2 / 3, 16 / 9, 1 / 1].includes(state.aspectRatio)
!mappedAspectRatios.includes(state.aspectRatio)
) {
state.aspectRatio = null;
}