Validate URL after import
This commit is contained in:
@@ -66,9 +66,12 @@ class BookmarkForm extends _$BookmarkForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initializeProviderUrl(String url) {
|
void initializeProviderUrl(String url) {
|
||||||
state.urlController.text = url;
|
final decoded = Uri.decodeComponent(url);
|
||||||
if (Regexps.urlWithoutProtocol.hasMatch(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;
|
state.urlError = null;
|
||||||
|
checkUrlDetails(updateState: false);
|
||||||
} else {
|
} else {
|
||||||
state.urlError = t.bookmarks.addBookmark.invalidUrl;
|
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 != "") {
|
if (state.urlError == null && state.urlController.text != "") {
|
||||||
state.checkBookmarkLoadStatus = LoadStatus.loading;
|
state.checkBookmarkLoadStatus = LoadStatus.loading;
|
||||||
state.checkBookmark = null;
|
state.checkBookmark = null;
|
||||||
ref.notifyListeners();
|
if (updateState == true) {
|
||||||
|
ref.notifyListeners();
|
||||||
|
}
|
||||||
final result = await ref.read(checkBookmarkProvider(state.urlController.text).future);
|
final result = await ref.read(checkBookmarkProvider(state.urlController.text).future);
|
||||||
if (result.successful == true) {
|
if (result.successful == true) {
|
||||||
state.checkBookmark = result.content;
|
state.checkBookmark = result.content;
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class _ModalContent extends ConsumerWidget {
|
|||||||
onPressed: provider.checkBookmarkLoadStatus == null &&
|
onPressed: provider.checkBookmarkLoadStatus == null &&
|
||||||
provider.urlError == null &&
|
provider.urlError == null &&
|
||||||
provider.urlController.text != ""
|
provider.urlController.text != ""
|
||||||
? () => ref.read(bookmarkFormProvider.notifier).checkUrlDetails()
|
? () => ref.read(bookmarkFormProvider.notifier).checkUrlDetails(updateState: true)
|
||||||
: null,
|
: null,
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
foregroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
foregroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||||
|
|||||||
Reference in New Issue
Block a user