diff --git a/gui/src/renderer/components/select-location/CustomListDialogs.tsx b/gui/src/renderer/components/select-location/CustomListDialogs.tsx index 56244e73ebcf..4f97706210a0 100644 --- a/gui/src/renderer/components/select-location/CustomListDialogs.tsx +++ b/gui/src/renderer/components/select-location/CustomListDialogs.tsx @@ -147,21 +147,25 @@ export function EditListDialog(props: EditListProps) { const { updateCustomList } = useAppContext(); const [newName, setNewName] = useState(props.list.name); + const newNameTrimmed = newName.trim(); + const newNameValid = newNameTrimmed !== ''; const [error, setError, unsetError] = useBoolean(); // Update name in list and save it. const save = useCallback(async () => { - try { - const updatedList = { ...props.list, name: newName }; - const result = await updateCustomList(updatedList); - if (result && result.type === 'name already exists') { - setError(); - } else { - props.hide(); + if (newNameValid) { + try { + const updatedList = { ...props.list, name: newNameTrimmed }; + const result = await updateCustomList(updatedList); + if (result && result.type === 'name already exists') { + setError(); + } else { + props.hide(); + } + } catch (e) { + const error = e as Error; + log.error(`Failed to edit custom list ${props.list.id}: ${error.message}`); } - } catch (e) { - const error = e as Error; - log.error(`Failed to edit custom list ${props.list.id}: ${error.message}`); } }, [props.list, newName, props.hide]); @@ -175,7 +179,7 @@ export function EditListDialog(props: EditListProps) { + {messages.gettext('Save')} , diff --git a/gui/src/renderer/components/select-location/CustomLists.tsx b/gui/src/renderer/components/select-location/CustomLists.tsx index eafcb161b21b..f335f7ae87af 100644 --- a/gui/src/renderer/components/select-location/CustomLists.tsx +++ b/gui/src/renderer/components/select-location/CustomLists.tsx @@ -123,7 +123,8 @@ interface AddListFormProps { function AddListForm(props: AddListFormProps) { const [name, setName] = useState(''); - const nameValid = name.trim() !== ''; + const nameTrimmed = name.trim(); + const nameValid = nameTrimmed !== ''; const [error, setError, unsetError] = useBoolean(); const containerRef = useStyledRef(); const inputRef = useStyledRef(); @@ -137,7 +138,7 @@ function AddListForm(props: AddListFormProps) { const createList = useCallback(async () => { if (nameValid) { try { - const result = await props.onCreateList(name); + const result = await props.onCreateList(nameTrimmed); if (result) { setError(); }