Renamed links to bookmarks
This commit is contained in:
32
lib/screens/bookmarks/model/add_link.model.dart
Normal file
32
lib/screens/bookmarks/model/add_link.model.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
import 'package:linkdy/models/data/check_bookmark.dart';
|
||||
|
||||
class AddBookmarkModel {
|
||||
final TextEditingController urlController;
|
||||
String? urlError;
|
||||
CheckBookmark? checkBookmark;
|
||||
LoadStatus? checkBookmarkLoadStatus;
|
||||
final TextEditingController titleController;
|
||||
final TextEditingController descriptionController;
|
||||
bool markAsUnread;
|
||||
final TextEditingController tagsController;
|
||||
String? tagsError;
|
||||
List<String> tags;
|
||||
final TextEditingController notesController;
|
||||
|
||||
AddBookmarkModel({
|
||||
required this.urlController,
|
||||
this.urlError,
|
||||
this.checkBookmark,
|
||||
this.checkBookmarkLoadStatus,
|
||||
required this.titleController,
|
||||
required this.descriptionController,
|
||||
this.markAsUnread = false,
|
||||
required this.tagsController,
|
||||
this.tagsError,
|
||||
required this.tags,
|
||||
required this.notesController,
|
||||
});
|
||||
}
|
||||
9
lib/screens/bookmarks/model/links.model.dart
Normal file
9
lib/screens/bookmarks/model/links.model.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
class BookmarksModel {
|
||||
int currentPage;
|
||||
int limit;
|
||||
|
||||
BookmarksModel({
|
||||
this.currentPage = 0,
|
||||
this.limit = 100,
|
||||
});
|
||||
}
|
||||
129
lib/screens/bookmarks/provider/add_bookmark.provider.dart
Normal file
129
lib/screens/bookmarks/provider/add_bookmark.provider.dart
Normal file
@@ -0,0 +1,129 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/model/add_link.model.dart';
|
||||
|
||||
import 'package:linkdy/models/data/tags.dart';
|
||||
import 'package:linkdy/utils/snackbar.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/utils/process_modal.dart';
|
||||
import 'package:linkdy/models/data/post_bookmark.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
import 'package:linkdy/constants/regexp.dart';
|
||||
import 'package:linkdy/models/api_response.dart';
|
||||
import 'package:linkdy/models/data/check_bookmark.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
|
||||
part 'add_bookmark.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
Future<ApiResponse<CheckBookmark>> checkBookmark(CheckBookmarkRef ref, String url) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchCheckAddBookmark(url: url);
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
FutureOr<ApiResponse<TagsResponse>> getTags(GetTagsRef ref) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchTags();
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class AddBookmark extends _$AddBookmark {
|
||||
@override
|
||||
AddBookmarkModel build() {
|
||||
return AddBookmarkModel(
|
||||
urlController: TextEditingController(),
|
||||
titleController: TextEditingController(),
|
||||
descriptionController: TextEditingController(),
|
||||
tagsController: TextEditingController(),
|
||||
tags: [],
|
||||
notesController: TextEditingController(),
|
||||
);
|
||||
}
|
||||
|
||||
void validateUrl(String value) {
|
||||
state.checkBookmark = null;
|
||||
state.checkBookmarkLoadStatus = null;
|
||||
if (Regexps.urlWithoutProtocol.hasMatch(value)) {
|
||||
state.urlError = null;
|
||||
ref.notifyListeners();
|
||||
} else {
|
||||
state.urlError = t.bookmarks.addBookmark.invalidUrl;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void checkUrlDetails() async {
|
||||
if (state.urlError == null && state.urlController.text != "") {
|
||||
state.checkBookmarkLoadStatus = LoadStatus.loading;
|
||||
state.checkBookmark = null;
|
||||
ref.notifyListeners();
|
||||
final result = await ref.read(checkBookmarkProvider(state.urlController.text).future);
|
||||
if (result.successful == true) {
|
||||
state.checkBookmark = result.content;
|
||||
state.checkBookmarkLoadStatus = LoadStatus.loaded;
|
||||
} else {
|
||||
state.checkBookmarkLoadStatus = LoadStatus.error;
|
||||
}
|
||||
ref.notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateMarkAsUnread(bool value) {
|
||||
state.markAsUnread = value;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void addBookmark() async {
|
||||
final newBookmark = PostBookmark(
|
||||
url: state.urlController.text,
|
||||
title: state.titleController.text != "" ? state.titleController.text : state.checkBookmark?.metadata?.title ?? '',
|
||||
description: state.descriptionController.text != ""
|
||||
? state.descriptionController.text
|
||||
: state.checkBookmark?.metadata?.description ?? '',
|
||||
isArchived: false,
|
||||
unread: state.markAsUnread,
|
||||
shared: false,
|
||||
tagNames: state.tags.join(","),
|
||||
);
|
||||
|
||||
final processModal = ProcessModal();
|
||||
processModal.open(t.bookmarks.addBookmark.savingBookmark);
|
||||
|
||||
final result = await ref.watch(apiClientProvider)!.fetchPostBookmark(newBookmark);
|
||||
|
||||
processModal.close();
|
||||
|
||||
if (result.successful == true) {
|
||||
ref.invalidate(bookmarksRequestProvider);
|
||||
ref.watch(routerProvider).pop();
|
||||
} else {
|
||||
showSnacbkar(
|
||||
label: t.bookmarks.addBookmark.errorSavingBookmark,
|
||||
color: Colors.red,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void validateTagInput(String value) {
|
||||
if (value.contains(" ")) {
|
||||
state.tagsError = t.bookmarks.addBookmark.tagNoWhitespaces;
|
||||
} else {
|
||||
state.tagsError = null;
|
||||
}
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void setTags(List<String> tags) {
|
||||
state.tags = tags;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void clearTagsController() {
|
||||
state.tagsController.clear();
|
||||
ref.notifyListeners();
|
||||
}
|
||||
}
|
||||
194
lib/screens/bookmarks/provider/add_bookmark.provider.g.dart
Normal file
194
lib/screens/bookmarks/provider/add_bookmark.provider.g.dart
Normal file
@@ -0,0 +1,194 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'add_bookmark.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$checkBookmarkHash() => r'8eeb8cb7ee801ca7ed1b604b56a4301a86568c54';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
/// See also [checkBookmark].
|
||||
@ProviderFor(checkBookmark)
|
||||
const checkBookmarkProvider = CheckBookmarkFamily();
|
||||
|
||||
/// See also [checkBookmark].
|
||||
class CheckBookmarkFamily
|
||||
extends Family<AsyncValue<ApiResponse<CheckBookmark>>> {
|
||||
/// See also [checkBookmark].
|
||||
const CheckBookmarkFamily();
|
||||
|
||||
/// See also [checkBookmark].
|
||||
CheckBookmarkProvider call(
|
||||
String url,
|
||||
) {
|
||||
return CheckBookmarkProvider(
|
||||
url,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
CheckBookmarkProvider getProviderOverride(
|
||||
covariant CheckBookmarkProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.url,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'checkBookmarkProvider';
|
||||
}
|
||||
|
||||
/// See also [checkBookmark].
|
||||
class CheckBookmarkProvider
|
||||
extends AutoDisposeFutureProvider<ApiResponse<CheckBookmark>> {
|
||||
/// See also [checkBookmark].
|
||||
CheckBookmarkProvider(
|
||||
String url,
|
||||
) : this._internal(
|
||||
(ref) => checkBookmark(
|
||||
ref as CheckBookmarkRef,
|
||||
url,
|
||||
),
|
||||
from: checkBookmarkProvider,
|
||||
name: r'checkBookmarkProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$checkBookmarkHash,
|
||||
dependencies: CheckBookmarkFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
CheckBookmarkFamily._allTransitiveDependencies,
|
||||
url: url,
|
||||
);
|
||||
|
||||
CheckBookmarkProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.url,
|
||||
}) : super.internal();
|
||||
|
||||
final String url;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
FutureOr<ApiResponse<CheckBookmark>> Function(CheckBookmarkRef provider)
|
||||
create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: CheckBookmarkProvider._internal(
|
||||
(ref) => create(ref as CheckBookmarkRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
url: url,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeFutureProviderElement<ApiResponse<CheckBookmark>> createElement() {
|
||||
return _CheckBookmarkProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is CheckBookmarkProvider && other.url == url;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, url.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin CheckBookmarkRef
|
||||
on AutoDisposeFutureProviderRef<ApiResponse<CheckBookmark>> {
|
||||
/// The parameter `url` of this provider.
|
||||
String get url;
|
||||
}
|
||||
|
||||
class _CheckBookmarkProviderElement
|
||||
extends AutoDisposeFutureProviderElement<ApiResponse<CheckBookmark>>
|
||||
with CheckBookmarkRef {
|
||||
_CheckBookmarkProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get url => (origin as CheckBookmarkProvider).url;
|
||||
}
|
||||
|
||||
String _$getTagsHash() => r'16138d28ed9ee5b99f5c84935f7a1eb98fad2a3b';
|
||||
|
||||
/// See also [getTags].
|
||||
@ProviderFor(getTags)
|
||||
final getTagsProvider =
|
||||
AutoDisposeFutureProvider<ApiResponse<TagsResponse>>.internal(
|
||||
getTags,
|
||||
name: r'getTagsProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$getTagsHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef GetTagsRef = AutoDisposeFutureProviderRef<ApiResponse<TagsResponse>>;
|
||||
String _$addBookmarkHash() => r'2953a4223fe70809fbcf37af23b4f61a62f0de9f';
|
||||
|
||||
/// See also [AddBookmark].
|
||||
@ProviderFor(AddBookmark)
|
||||
final addBookmarkProvider =
|
||||
AutoDisposeNotifierProvider<AddBookmark, AddBookmarkModel>.internal(
|
||||
AddBookmark.new,
|
||||
name: r'addBookmarkProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$addBookmarkHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$AddBookmark = AutoDisposeNotifier<AddBookmarkModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
31
lib/screens/bookmarks/provider/bookmarks.provider.dart
Normal file
31
lib/screens/bookmarks/provider/bookmarks.provider.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/model/links.model.dart';
|
||||
|
||||
import 'package:linkdy/models/api_response.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
|
||||
part 'bookmarks.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
FutureOr<ApiResponse<BookmarksResponse>> bookmarksRequest(BookmarksRequestRef ref) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchBookmarks();
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class Bookmarks extends _$Bookmarks {
|
||||
@override
|
||||
BookmarksModel build() {
|
||||
return BookmarksModel();
|
||||
}
|
||||
|
||||
void setCurrentPage(int page) {
|
||||
state.currentPage = page;
|
||||
}
|
||||
|
||||
void setLimit(int limit) {
|
||||
state.limit = limit;
|
||||
}
|
||||
}
|
||||
42
lib/screens/bookmarks/provider/bookmarks.provider.g.dart
Normal file
42
lib/screens/bookmarks/provider/bookmarks.provider.g.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bookmarks.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$bookmarksRequestHash() => r'c80328ae148c39617997a44ac5c34f27daf25a8a';
|
||||
|
||||
/// See also [bookmarksRequest].
|
||||
@ProviderFor(bookmarksRequest)
|
||||
final bookmarksRequestProvider =
|
||||
AutoDisposeFutureProvider<ApiResponse<BookmarksResponse>>.internal(
|
||||
bookmarksRequest,
|
||||
name: r'bookmarksRequestProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$bookmarksRequestHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef BookmarksRequestRef
|
||||
= AutoDisposeFutureProviderRef<ApiResponse<BookmarksResponse>>;
|
||||
String _$bookmarksHash() => r'4a1726830b4e7bbc131d69761aeb4702ca6b7180';
|
||||
|
||||
/// See also [Bookmarks].
|
||||
@ProviderFor(Bookmarks)
|
||||
final bookmarksProvider =
|
||||
AutoDisposeNotifierProvider<Bookmarks, BookmarksModel>.internal(
|
||||
Bookmarks.new,
|
||||
name: r'bookmarksProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$bookmarksHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$Bookmarks = AutoDisposeNotifier<BookmarksModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
314
lib/screens/bookmarks/ui/add_bookmark_modal.dart
Normal file
314
lib/screens/bookmarks/ui/add_bookmark_modal.dart
Normal file
@@ -0,0 +1,314 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:easy_autocomplete/easy_autocomplete.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/add_bookmark.provider.dart';
|
||||
import 'package:linkdy/widgets/section_label.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
|
||||
class AddBookmarkModal extends ConsumerWidget {
|
||||
final bool fullscreen;
|
||||
|
||||
const AddBookmarkModal({
|
||||
Key? key,
|
||||
required this.fullscreen,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Dialog.fullscreen(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: CloseButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: Text(t.bookmarks.addBookmark.addBookmark),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: ref.watch(addBookmarkProvider).checkBookmark != null
|
||||
? () => ref.read(addBookmarkProvider.notifier).addBookmark()
|
||||
: null,
|
||||
icon: const Icon(Icons.save_rounded),
|
||||
tooltip: t.generic.save,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: const _ModalContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ModalContent extends ConsumerWidget {
|
||||
const _ModalContent({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = ref.watch(addBookmarkProvider);
|
||||
|
||||
final tags = ref.watch(getTagsProvider);
|
||||
|
||||
return ListView(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.bookmarkUrl,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.urlController,
|
||||
onChanged: ref.read(addBookmarkProvider.notifier).validateUrl,
|
||||
enabled: provider.checkBookmarkLoadStatus != LoadStatus.loading,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.link_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
errorText: provider.urlError,
|
||||
labelText: t.bookmarks.addBookmark.url,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: provider.checkBookmarkLoadStatus == null &&
|
||||
provider.urlError == null &&
|
||||
provider.urlController.text != ""
|
||||
? () => ref.read(addBookmarkProvider.notifier).checkUrlDetails()
|
||||
: null,
|
||||
style: ButtonStyle(
|
||||
foregroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? const MaterialStatePropertyAll(Colors.green)
|
||||
: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? const MaterialStatePropertyAll(Colors.red)
|
||||
: null,
|
||||
backgroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? MaterialStatePropertyAll(Colors.green.withOpacity(0.15))
|
||||
: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? MaterialStatePropertyAll(Colors.red.withOpacity(0.15))
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (provider.checkBookmarkLoadStatus == null) Text(t.bookmarks.addBookmark.validateUrl),
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.loading) ...[
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
height: 12,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.checkingUrl),
|
||||
],
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.loaded) ...[
|
||||
const Icon(Icons.check_circle_rounded),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.urlValid),
|
||||
],
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.error) ...[
|
||||
const Icon(Icons.error_rounded),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.cannotCheckUrl),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.bookmarkDetails,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.titleController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.title_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.title,
|
||||
hintText: provider.checkBookmark?.metadata?.title,
|
||||
floatingLabelBehavior:
|
||||
provider.checkBookmark != null ? FloatingLabelBehavior.always : FloatingLabelBehavior.auto,
|
||||
helperText: t.bookmarks.addBookmark.leaveEmptyUseWebsiteTitle,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.descriptionController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.description_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.description,
|
||||
hintText: provider.checkBookmark?.metadata?.description,
|
||||
floatingLabelBehavior:
|
||||
provider.checkBookmark != null ? FloatingLabelBehavior.always : FloatingLabelBehavior.auto,
|
||||
helperText: t.bookmarks.addBookmark.leaveEmptyUseWebsiteDescription,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.tags,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
if (tags.isLoading == false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
if (provider.checkBookmark != null)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: EasyAutocomplete(
|
||||
controller: provider.tagsController,
|
||||
onChanged: ref.read(addBookmarkProvider.notifier).validateTagInput,
|
||||
suggestions: tags.value?.content?.results?.map((t) => t.name!).toList() ?? [],
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.tags,
|
||||
errorText: provider.tagsError,
|
||||
),
|
||||
suggestionBuilder: (data) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
data,
|
||||
style: TextStyle(fontSize: 16, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
onSubmitted: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? (v) {
|
||||
ref.read(addBookmarkProvider.notifier).setTags([...provider.tags, v]);
|
||||
ref.read(addBookmarkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
onPressed: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? () {
|
||||
ref
|
||||
.read(addBookmarkProvider.notifier)
|
||||
.setTags([...provider.tags, provider.tagsController.text]);
|
||||
ref.read(addBookmarkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.check_rounded),
|
||||
tooltip: t.bookmarks.addBookmark.addTag,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (provider.checkBookmark != null) const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: provider.tags.isNotEmpty
|
||||
? ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: provider.tags.length,
|
||||
separatorBuilder: (context, index) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) => InputChip(
|
||||
label: Text(provider.tags[index]),
|
||||
onDeleted: () => ref
|
||||
.read(addBookmarkProvider.notifier)
|
||||
.setTags(provider.tags.where((tag) => tag != provider.tags[index]).toList()),
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
t.bookmarks.addBookmark.noTagsAdded,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.others,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
child: TextFormField(
|
||||
controller: provider.notesController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.note_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.notes,
|
||||
helperText: t.generic.optional,
|
||||
),
|
||||
autocorrect: false,
|
||||
expands: true,
|
||||
minLines: null,
|
||||
maxLines: null,
|
||||
textAlignVertical: TextAlignVertical.top,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
title: Text(t.bookmarks.addBookmark.markAsUnread),
|
||||
value: provider.markAsUnread,
|
||||
onChanged: provider.checkBookmark != null
|
||||
? (v) => ref.read(addBookmarkProvider.notifier).updateMarkAsUnread(v)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
98
lib/screens/bookmarks/ui/bookmark_item.dart
Normal file
98
lib/screens/bookmarks/ui/bookmark_item.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
import 'package:linkdy/providers/app_status_provider.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/utils/date_to_string.dart';
|
||||
import 'package:linkdy/utils/open_url.dart';
|
||||
|
||||
class LinkItem extends ConsumerWidget {
|
||||
final Bookmark bookmark;
|
||||
|
||||
const LinkItem({
|
||||
Key? key,
|
||||
required this.bookmark,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
String validateStrings(String? string1, String? string2) {
|
||||
if (string1 != null && string1.isNotEmpty) {
|
||||
return string1;
|
||||
} else if (string2 != null && string2.isNotEmpty) {
|
||||
return string2;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
onTap: ref.watch(appStatusProvider).useInAppBrowser == true
|
||||
? () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: bookmark)
|
||||
: () => openUrl(bookmark.url!),
|
||||
isThreeLine: true,
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
validateStrings(bookmark.title, bookmark.websiteTitle),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
validateStrings(bookmark.description, bookmark.websiteDescription),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
bookmark.tagNames?.map((tag) => "#$tag").join(" ") ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (bookmark.dateModified != null) ...[
|
||||
if (bookmark.tagNames?.isNotEmpty == true)
|
||||
Container(
|
||||
width: 1,
|
||||
height: 12,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
Text(
|
||||
dateToString(bookmark.dateModified!),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
119
lib/screens/bookmarks/ui/bookmarks.dart
Normal file
119
lib/screens/bookmarks/ui/bookmarks.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/add_bookmark_modal.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class BookmarksScreen extends ConsumerWidget {
|
||||
const BookmarksScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bookmarks = ref.watch(bookmarksRequestProvider);
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
void openAddModal() {
|
||||
showGeneralDialog(
|
||||
context: context,
|
||||
barrierColor: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)) ? Colors.transparent : Colors.black54,
|
||||
transitionBuilder: (context, anim1, anim2, child) {
|
||||
return SlideTransition(
|
||||
position: Tween(begin: const Offset(0, 1), end: const Offset(0, 0)).animate(
|
||||
CurvedAnimation(parent: anim1, curve: Curves.easeInOutCubicEmphasized),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
pageBuilder: (context, animation, secondaryAnimation) => AddBookmarkModal(fullscreen: width <= 700),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: SliverAppBar.large(
|
||||
pinned: true,
|
||||
floating: true,
|
||||
centerTitle: false,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
title: Text(t.bookmarks.bookmarks),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (context) => RefreshIndicator(
|
||||
displacement: 120,
|
||||
onRefresh: () => ref.refresh(bookmarksRequestProvider.future),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
if (bookmarks.isLoading && !bookmarks.isRefreshing)
|
||||
const SliverFillRemaining(
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (bookmarks.value != null && bookmarks.value!.successful == false)
|
||||
const SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Icon(Icons.error),
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isEmpty)
|
||||
const SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Text("No bookmarks"),
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isNotEmpty)
|
||||
SliverList.builder(
|
||||
itemCount: bookmarks.value!.content!.results!.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
// index == bookmarks.value!.content!.results!.length -> itemCount + 1
|
||||
if (index == bookmarks.value!.content!.results!.length) {
|
||||
// Bottom gap for FAB
|
||||
return const SizedBox(height: 80);
|
||||
}
|
||||
final link = bookmarks.value?.content?.results?[index];
|
||||
return Column(
|
||||
children: [
|
||||
LinkItem(bookmark: link!),
|
||||
if (index < bookmarks.value!.content!.results!.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Divider(
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: openAddModal,
|
||||
child: const Icon(Icons.add_rounded),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user