Change cleanUpUrl name
This commit is contained in:
parent
fbb8ff3a33
commit
88e1f8324f
|
@ -25,7 +25,7 @@ class AddInstancePage extends HookWidget {
|
|||
final debounce = useDebounce(() async {
|
||||
if (prevInput == instanceController.text) return;
|
||||
|
||||
final inst = cleanUpUrl(instanceController.text);
|
||||
final inst = normalizeInstanceHost(instanceController.text);
|
||||
if (inst.isEmpty) {
|
||||
isSite.value = null;
|
||||
return;
|
||||
|
@ -47,7 +47,7 @@ class AddInstancePage extends HookWidget {
|
|||
instanceController.removeListener(debounce);
|
||||
};
|
||||
}, []);
|
||||
final inst = cleanUpUrl(instanceController.text);
|
||||
final inst = normalizeInstanceHost(instanceController.text);
|
||||
handleOnAdd() async {
|
||||
try {
|
||||
await accountsStore.addInstance(inst, assumeValid: true);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/// Returns host of a url without a leading 'www.' or protocol if present also
|
||||
/// removes trailing '/'
|
||||
String cleanUpUrl(String url) {
|
||||
/// Returns a normalized host of a (maybe) url without a leading www.
|
||||
String normalizeInstanceHost(String maybeUrl) {
|
||||
try {
|
||||
return urlHost(url.startsWith('https://') ? url : 'https://$url');
|
||||
} on FormatException catch (_) {
|
||||
return urlHost(
|
||||
maybeUrl.startsWith('https://') ? maybeUrl : 'https://$maybeUrl');
|
||||
} on FormatException {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue