Skip to content

Commit

Permalink
fix: e.current.name is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Jan 14, 2024
1 parent fea7442 commit c77fd94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/src/components/SelectGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ function SelectGroupMobile(props: SelectGroupProps) {
return (
<div className={`mb-2 w-full`}>
<Select
value={props.current.name || ""}
value={props.current?.name || ""}
onValueChange={(value: string) => {
props.onChange?.(value);
}}
>
<SelectTrigger className="select-group mobile">
<SelectValue placeholder={props.current.value} />
<SelectValue placeholder={props.current?.value || ""} />
</SelectTrigger>
<SelectContent
className={`${props.className} ${props.classNameMobile}`}
Expand Down
12 changes: 11 additions & 1 deletion app/src/components/home/ModelFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function ModelFinder(props: ModelSelectorProps) {
? supportModels.filter((model) => list.includes(model.id))
: supportModels.filter((model) => model.default);

if (raw.length === 0) raw.push({
name: "default",
id: "default",
} as Model);

return [
...raw.map((model: Model): SelectItemProps => filterModel(model, level)),
{
Expand All @@ -80,6 +85,11 @@ function ModelFinder(props: ModelSelectorProps) {
];
}, [supportModels, level, student, sync]);

const current = useMemo((): SelectItemProps => {
const raw = models.find((item) => item.name === model);
return raw || models[0];
}, [models, model]);

useEffect(() => {
setInterval(() => {
if (supportModels.length === 0) return;
Expand All @@ -89,7 +99,7 @@ function ModelFinder(props: ModelSelectorProps) {

return (
<SelectGroup
current={models.find((item) => item.name === model) as SelectItemProps}
current={current}
list={models}
maxElements={3}
side={props.side}
Expand Down

0 comments on commit c77fd94

Please sign in to comment.