@@ -147,21 +147,25 @@ export function EditListDialog(props: EditListProps) {
147
147
const { updateCustomList } = useAppContext ( ) ;
148
148
149
149
const [ newName , setNewName ] = useState ( props . list . name ) ;
150
+ const newNameTrimmed = newName . trim ( ) ;
151
+ const newNameValid = newNameTrimmed !== '' ;
150
152
const [ error , setError , unsetError ] = useBoolean ( ) ;
151
153
152
154
// Update name in list and save it.
153
155
const save = useCallback ( async ( ) => {
154
- try {
155
- const updatedList = { ...props . list , name : newName } ;
156
- const result = await updateCustomList ( updatedList ) ;
157
- if ( result && result . type === 'name already exists' ) {
158
- setError ( ) ;
159
- } else {
160
- props . hide ( ) ;
156
+ if ( newNameValid ) {
157
+ try {
158
+ const updatedList = { ...props . list , name : newNameTrimmed } ;
159
+ const result = await updateCustomList ( updatedList ) ;
160
+ if ( result && result . type === 'name already exists' ) {
161
+ setError ( ) ;
162
+ } else {
163
+ props . hide ( ) ;
164
+ }
165
+ } catch ( e ) {
166
+ const error = e as Error ;
167
+ log . error ( `Failed to edit custom list ${ props . list . id } : ${ error . message } ` ) ;
161
168
}
162
- } catch ( e ) {
163
- const error = e as Error ;
164
- log . error ( `Failed to edit custom list ${ props . list . id } : ${ error . message } ` ) ;
165
169
}
166
170
} , [ props . list , newName , props . hide ] ) ;
167
171
@@ -175,7 +179,7 @@ export function EditListDialog(props: EditListProps) {
175
179
< ModalAlert
176
180
isOpen = { props . isOpen }
177
181
buttons = { [
178
- < AppButton . BlueButton key = "save" onClick = { save } >
182
+ < AppButton . BlueButton key = "save" disabled = { ! newNameValid } onClick = { save } >
179
183
{ messages . gettext ( 'Save' ) }
180
184
</ AppButton . BlueButton > ,
181
185
< AppButton . BlueButton key = "cancel" onClick = { props . hide } >
0 commit comments