prevent duplicates

This commit is contained in:
2025-03-15 08:42:11 -05:00
parent 492ccfbdfb
commit d209b52848
4 changed files with 75 additions and 17 deletions

View File

@ -145,7 +145,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"'$key' is not valid",
"Setting '$key' is not valid",
textAlign: TextAlign.center,
),
),
@ -154,17 +154,11 @@ class _AddMountScreenState extends State<AddMountScreen> {
return;
}
final existingMount = mountList.items.firstWhereOrNull(
(item) =>
item.name.toLowerCase() ==
_mountNameController.text.toLowerCase(),
);
if (existingMount != null) {
if (mountList.hasConfigName(_mountNameController.text)) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"'${_mountNameController.text}' already exists",
"Configuration '${_mountNameController.text}' already exists",
textAlign: TextAlign.center,
),
),
@ -172,6 +166,23 @@ class _AddMountScreenState extends State<AddMountScreen> {
return;
}
if (_mountType == "Sia" || _mountType == "S3") {
final bucket =
_settings[_mountType]!["${_mountType}Config"]["Bucket"]
as String;
if (mountList.hasBucketName(_mountType, bucket)) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Bucket '$bucket' already exists",
textAlign: TextAlign.center,
),
),
);
return;
}
}
mountList.add(
_mountType,
_mountNameController.text,