add --disable-model-switch

This commit is contained in:
Qing
2022-11-13 13:14:37 +08:00
parent 8cdac238b4
commit 0666a32947
6 changed files with 41 additions and 2 deletions

View File

@@ -75,6 +75,12 @@ export default async function inpaint(
}
}
export function getIsDisableModelSwitch() {
return fetch(`${API_ENDPOINT}/is_disable_model_switch`, {
method: 'GET',
})
}
export function switchModel(name: string) {
const fd = new FormData()
fd.append('name', name)

View File

@@ -1,5 +1,6 @@
import React, { ReactNode } from 'react'
import React, { ReactNode, useEffect, useState } from 'react'
import { useRecoilState } from 'recoil'
import { getIsDisableModelSwitch } from '../../adapters/inpainting'
import { AIModel, CV2Flag, SDSampler, settingState } from '../../store/Atoms'
import Selector from '../shared/Selector'
import { Switch, SwitchThumb } from '../shared/Switch'
@@ -10,6 +11,18 @@ import SettingBlock from './SettingBlock'
function ModelSettingBlock() {
const [setting, setSettingState] = useRecoilState(settingState)
const [isDisableModelSwitch, setIsDisableModelSwitch] = useState(false)
useEffect(() => {
const fetchData = async () => {
const isDisable: string = await getIsDisableModelSwitch().then(res =>
res.text()
)
setIsDisableModelSwitch(isDisable === 'true')
}
fetchData()
}, [])
const onModelChange = (value: AIModel) => {
setSettingState(old => {
@@ -250,6 +263,7 @@ function ModelSettingBlock() {
value={setting.model as string}
options={Object.values(AIModel)}
onChange={val => onModelChange(val as AIModel)}
disabled={isDisableModelSwitch}
/>
}
optionDesc={renderOptionDesc()}

View File

@@ -24,6 +24,11 @@
// &:focus-visible {
// border-color: var(--yellow-accent);
// }
&:disabled {
color: var(--border-color);
border-color: var(--border-color);
}
}
.select-content {

View File

@@ -15,6 +15,7 @@ interface Props {
chevronDirection?: SelectorChevronDirection
autoFocusAfterClose?: boolean
onChange: (value: string) => void
disabled?: boolean
}
const Selector = (props: Props) => {
@@ -25,6 +26,7 @@ const Selector = (props: Props) => {
options,
autoFocusAfterClose,
onChange,
disabled,
} = props
const contentRef = useRef<HTMLButtonElement>(null)
@@ -52,6 +54,7 @@ const Selector = (props: Props) => {
style={{ width }}
ref={contentRef}
onKeyDown={e => e.preventDefault()}
disabled={disabled}
>
<Select.Value />
<Select.Icon>
@@ -78,6 +81,7 @@ const Selector = (props: Props) => {
const selectorDefaultProps = {
chevronDirection: 'down',
autoFocusAfterClose: true,
disabled: false,
}
Selector.defaultProps = selectorDefaultProps