fix: e.current.name is undefined

This commit is contained in:
Zhang Minghan 2024-01-14 15:55:36 +08:00
parent fea7442b85
commit c77fd946ee
2 changed files with 13 additions and 3 deletions

View File

@ -105,13 +105,13 @@ function SelectGroupMobile(props: SelectGroupProps) {
return ( return (
<div className={`mb-2 w-full`}> <div className={`mb-2 w-full`}>
<Select <Select
value={props.current.name || ""} value={props.current?.name || ""}
onValueChange={(value: string) => { onValueChange={(value: string) => {
props.onChange?.(value); props.onChange?.(value);
}} }}
> >
<SelectTrigger className="select-group mobile"> <SelectTrigger className="select-group mobile">
<SelectValue placeholder={props.current.value} /> <SelectValue placeholder={props.current?.value || ""} />
</SelectTrigger> </SelectTrigger>
<SelectContent <SelectContent
className={`${props.className} ${props.classNameMobile}`} className={`${props.className} ${props.classNameMobile}`}

View File

@ -70,6 +70,11 @@ function ModelFinder(props: ModelSelectorProps) {
? supportModels.filter((model) => list.includes(model.id)) ? supportModels.filter((model) => list.includes(model.id))
: supportModels.filter((model) => model.default); : supportModels.filter((model) => model.default);
if (raw.length === 0) raw.push({
name: "default",
id: "default",
} as Model);
return [ return [
...raw.map((model: Model): SelectItemProps => filterModel(model, level)), ...raw.map((model: Model): SelectItemProps => filterModel(model, level)),
{ {
@ -80,6 +85,11 @@ function ModelFinder(props: ModelSelectorProps) {
]; ];
}, [supportModels, level, student, sync]); }, [supportModels, level, student, sync]);
const current = useMemo((): SelectItemProps => {
const raw = models.find((item) => item.name === model);
return raw || models[0];
}, [models, model]);
useEffect(() => { useEffect(() => {
setInterval(() => { setInterval(() => {
if (supportModels.length === 0) return; if (supportModels.length === 0) return;
@ -89,7 +99,7 @@ function ModelFinder(props: ModelSelectorProps) {
return ( return (
<SelectGroup <SelectGroup
current={models.find((item) => item.name === model) as SelectItemProps} current={current}
list={models} list={models}
maxElements={3} maxElements={3}
side={props.side} side={props.side}