Validate URL after import

This commit is contained in:
Juan Gilsanz Polo
2024-04-03 16:18:02 +02:00
parent a37d0866f4
commit 340b37d6e6
2 changed files with 10 additions and 5 deletions

View File

@@ -66,9 +66,12 @@ class BookmarkForm extends _$BookmarkForm {
}
void initializeProviderUrl(String url) {
state.urlController.text = url;
if (Regexps.urlWithoutProtocol.hasMatch(url)) {
final decoded = Uri.decodeComponent(url);
var value = decoded.contains(":~:text=") ? decoded.split(":~:text=")[1] : null;
state.urlController.text = value ?? decoded;
if (Regexps.urlWithoutProtocol.hasMatch(value ?? decoded)) {
state.urlError = null;
checkUrlDetails(updateState: false);
} else {
state.urlError = t.bookmarks.addBookmark.invalidUrl;
}
@@ -86,11 +89,13 @@ class BookmarkForm extends _$BookmarkForm {
}
}
void checkUrlDetails() async {
void checkUrlDetails({required bool updateState}) async {
if (state.urlError == null && state.urlController.text != "") {
state.checkBookmarkLoadStatus = LoadStatus.loading;
state.checkBookmark = null;
if (updateState == true) {
ref.notifyListeners();
}
final result = await ref.read(checkBookmarkProvider(state.urlController.text).future);
if (result.successful == true) {
state.checkBookmark = result.content;

View File

@@ -197,7 +197,7 @@ class _ModalContent extends ConsumerWidget {
onPressed: provider.checkBookmarkLoadStatus == null &&
provider.urlError == null &&
provider.urlController.text != ""
? () => ref.read(bookmarkFormProvider.notifier).checkUrlDetails()
? () => ref.read(bookmarkFormProvider.notifier).checkUrlDetails(updateState: true)
: null,
style: ButtonStyle(
foregroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded