Added archive and unarchive
This commit is contained in:
@@ -118,8 +118,9 @@ class Bookmarks extends _$Bookmarks {
|
|||||||
bookmark: bookmark,
|
bookmark: bookmark,
|
||||||
apiClient: ref.read(apiClientProvider)!,
|
apiClient: ref.read(apiClientProvider)!,
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (result == true) {
|
||||||
state.bookmarks = state.bookmarks.map((b) => b.id == result.id ? result : b).toList();
|
// On this case the bookmark always will pass from unarchived to archived
|
||||||
|
state.bookmarks = state.bookmarks.where((b) => b.id != bookmark.id).toList();
|
||||||
ref.notifyListeners();
|
ref.notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,30 +75,21 @@ class BookmarkCommonFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Bookmark?> archiveUnarchive<T>({
|
static Future<bool> archiveUnarchive<T>({
|
||||||
required AutoDisposeNotifierProviderRef<T> ref,
|
required AutoDisposeNotifierProviderRef<T> ref,
|
||||||
required Bookmark bookmark,
|
required Bookmark bookmark,
|
||||||
required ApiClientService apiClient,
|
required ApiClientService apiClient,
|
||||||
}) async {
|
}) async {
|
||||||
final processModal = ProcessModal();
|
final processModal = ProcessModal();
|
||||||
processModal.open(
|
processModal.open(
|
||||||
bookmark.unread == true
|
bookmark.isArchived == true
|
||||||
? t.bookmarks.bookmarkOptions.archivingBookmark
|
? t.bookmarks.bookmarkOptions.unarchivingBookmark
|
||||||
: t.bookmarks.bookmarkOptions.unarchivingBookmark,
|
: t.bookmarks.bookmarkOptions.archivingBookmark,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = await apiClient.putUpdateBookmark(
|
final result = bookmark.isArchived == true
|
||||||
bookmark.id!,
|
? await apiClient.postUnrchiveBookmark(bookmark.id!)
|
||||||
SetBookmarkData(
|
: await apiClient.postArchiveBookmark(bookmark.id!);
|
||||||
url: bookmark.url!,
|
|
||||||
description: bookmark.description ?? '',
|
|
||||||
unread: bookmark.unread ?? false,
|
|
||||||
shared: bookmark.shared ?? false,
|
|
||||||
isArchived: bookmark.isArchived == true ? false : true,
|
|
||||||
tagNames: bookmark.tagNames?.join(",") ?? '',
|
|
||||||
title: bookmark.title ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
processModal.close();
|
processModal.close();
|
||||||
if (result.successful == true) {
|
if (result.successful == true) {
|
||||||
@@ -108,7 +99,6 @@ class BookmarkCommonFunctions {
|
|||||||
: t.bookmarks.bookmarkOptions.bookmarkArchivedSuccessfully,
|
: t.bookmarks.bookmarkOptions.bookmarkArchivedSuccessfully,
|
||||||
color: Colors.green,
|
color: Colors.green,
|
||||||
);
|
);
|
||||||
return result.content;
|
|
||||||
} else {
|
} else {
|
||||||
ref.read(snackbarProvider.notifier).showSnacbkar(
|
ref.read(snackbarProvider.notifier).showSnacbkar(
|
||||||
label: bookmark.isArchived == true
|
label: bookmark.isArchived == true
|
||||||
@@ -116,7 +106,7 @@ class BookmarkCommonFunctions {
|
|||||||
: t.bookmarks.bookmarkOptions.bookmarkNotArchived,
|
: t.bookmarks.bookmarkOptions.bookmarkNotArchived,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
);
|
);
|
||||||
return null;
|
}
|
||||||
}
|
return result.successful;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,17 +129,18 @@ class SearchBookmarks extends _$SearchBookmarks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void archiveUnarchive(Bookmark bookmark) async {
|
void archiveUnarchive(Bookmark bookmark) async {
|
||||||
final result = await BookmarkCommonFunctions.markAsReadUnread<SearchBookmarksModel>(
|
final result = await BookmarkCommonFunctions.archiveUnarchive<SearchBookmarksModel>(
|
||||||
ref: ref,
|
ref: ref,
|
||||||
bookmark: bookmark,
|
bookmark: bookmark,
|
||||||
apiClient: ref.read(apiClientProvider)!,
|
apiClient: ref.read(apiClientProvider)!,
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (result == true) {
|
||||||
state.bookmarks = state.bookmarks.map((b) => b.id == result.id ? result : b).toList();
|
// On this case the bookmark always will pass from unarchived to archived
|
||||||
|
state.bookmarks = state.bookmarks.where((b) => b.id != bookmark.id).toList();
|
||||||
ref.notifyListeners();
|
ref.notifyListeners();
|
||||||
ref
|
ref
|
||||||
.read(bookmarksProvider.notifier)
|
.read(bookmarksProvider.notifier)
|
||||||
.setBookmarks(ref.read(bookmarksProvider).bookmarks.map((b) => b.id == result.id ? result : b).toList());
|
.setBookmarks(ref.read(bookmarksProvider).bookmarks.where((b) => b.id != bookmark.id).toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ class BookmarkItem extends ConsumerWidget {
|
|||||||
final Bookmark bookmark;
|
final Bookmark bookmark;
|
||||||
final void Function(Bookmark bookmark) onDelete;
|
final void Function(Bookmark bookmark) onDelete;
|
||||||
final void Function(Bookmark bookmark) onReadUnread;
|
final void Function(Bookmark bookmark) onReadUnread;
|
||||||
|
final void Function(Bookmark bookmark) onArchiveUnarchive;
|
||||||
|
|
||||||
const BookmarkItem({
|
const BookmarkItem({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.bookmark,
|
required this.bookmark,
|
||||||
required this.onDelete,
|
required this.onDelete,
|
||||||
required this.onReadUnread,
|
required this.onReadUnread,
|
||||||
|
required this.onArchiveUnarchive,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -45,7 +47,7 @@ class BookmarkItem extends ConsumerWidget {
|
|||||||
groupTag: ConfigOptions.slidableGroupTag,
|
groupTag: ConfigOptions.slidableGroupTag,
|
||||||
startActionPane: ActionPane(
|
startActionPane: ActionPane(
|
||||||
motion: const DrawerMotion(),
|
motion: const DrawerMotion(),
|
||||||
extentRatio: 0.5,
|
extentRatio: 0.75,
|
||||||
children: [
|
children: [
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
onPressed: (_) => onReadUnread(bookmark),
|
onPressed: (_) => onReadUnread(bookmark),
|
||||||
@@ -54,13 +56,13 @@ class BookmarkItem extends ConsumerWidget {
|
|||||||
icon: bookmark.unread == true ? Icons.mark_email_read_rounded : Icons.mark_as_unread_rounded,
|
icon: bookmark.unread == true ? Icons.mark_email_read_rounded : Icons.mark_as_unread_rounded,
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
),
|
),
|
||||||
// SlidableAction(
|
SlidableAction(
|
||||||
// onPressed: (ctx) => {},
|
onPressed: (ctx) => onArchiveUnarchive(bookmark),
|
||||||
// backgroundColor: Colors.grey,
|
backgroundColor: Colors.grey,
|
||||||
// label: t.bookmarks.bookmarkOptions.archive,
|
label: t.bookmarks.bookmarkOptions.archive,
|
||||||
// icon: Icons.archive_rounded,
|
icon: Icons.archive_rounded,
|
||||||
// padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
// ),
|
),
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
onPressed: (ctx) => Share.shareUri(Uri.parse(bookmark.url!)),
|
onPressed: (ctx) => Share.shareUri(Uri.parse(bookmark.url!)),
|
||||||
backgroundColor: Colors.orange,
|
backgroundColor: Colors.orange,
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ class BookmarksScreen extends ConsumerWidget {
|
|||||||
onDelete: ref.read(bookmarksProvider.notifier).deleteBookmark,
|
onDelete: ref.read(bookmarksProvider.notifier).deleteBookmark,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
onArchiveUnarchive: ref.read(bookmarksProvider.notifier).archiveUnarchive,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ class SearchBookmarksScreen extends ConsumerWidget {
|
|||||||
onDelete: ref.read(searchBookmarksProvider.notifier).deleteBookmark,
|
onDelete: ref.read(searchBookmarksProvider.notifier).deleteBookmark,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
onArchiveUnarchive: ref.read(searchBookmarksProvider.notifier).archiveUnarchive,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -122,13 +122,14 @@ class TagBookmarks extends _$TagBookmarks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void archiveUnarchive(Bookmark bookmark) async {
|
void archiveUnarchive(Bookmark bookmark) async {
|
||||||
final result = await BookmarkCommonFunctions.markAsReadUnread<TagBookmarksModel>(
|
final result = await BookmarkCommonFunctions.archiveUnarchive<TagBookmarksModel>(
|
||||||
ref: ref,
|
ref: ref,
|
||||||
bookmark: bookmark,
|
bookmark: bookmark,
|
||||||
apiClient: ref.read(apiClientProvider)!,
|
apiClient: ref.read(apiClientProvider)!,
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (result == true) {
|
||||||
state.bookmarks = state.bookmarks.map((b) => b.id == result.id ? result : b).toList();
|
// On this case the bookmark always will pass from unarchived to archived
|
||||||
|
state.bookmarks = state.bookmarks.where((b) => b.id != bookmark.id).toList();
|
||||||
ref.notifyListeners();
|
ref.notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ class TagBookmarksScreenState extends ConsumerState<TagBookmarksScreen> {
|
|||||||
onDelete: ref.read(tagBookmarksProvider.notifier).deleteBookmark,
|
onDelete: ref.read(tagBookmarksProvider.notifier).deleteBookmark,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
onArchiveUnarchive: ref.read(tagBookmarksProvider.notifier).archiveUnarchive,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: BookmarksResponse.fromJson(response.data),
|
content: BookmarksResponse.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -64,6 +66,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: CheckBookmark.fromJson(response.data),
|
content: CheckBookmark.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -80,6 +84,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: Bookmark.fromJson(response.data),
|
content: Bookmark.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -100,6 +106,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: TagsResponse.fromJson(response.data),
|
content: TagsResponse.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -116,6 +124,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: Tag.fromJson(response.data),
|
content: Tag.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -129,6 +139,8 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: Tag.fromJson(response.data),
|
content: Tag.fromJson(response.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -139,6 +151,8 @@ class ApiClientService {
|
|||||||
try {
|
try {
|
||||||
await dioInstance.delete("/bookmarks/$bookmarkId/");
|
await dioInstance.delete("/bookmarks/$bookmarkId/");
|
||||||
return const ApiResponse(successful: true);
|
return const ApiResponse(successful: true);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
@@ -155,6 +169,32 @@ class ApiClientService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
content: Bookmark.fromJson(result.data),
|
content: Bookmark.fromJson(result.data),
|
||||||
);
|
);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ApiResponse<bool>> postArchiveBookmark(int bookmarkId) async {
|
||||||
|
try {
|
||||||
|
await dioInstance.post("/bookmarks/$bookmarkId/archive/");
|
||||||
|
return const ApiResponse(successful: true);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ApiResponse<bool>> postUnrchiveBookmark(int bookmarkId) async {
|
||||||
|
try {
|
||||||
|
await dioInstance.post("/bookmarks/$bookmarkId/unarchive/");
|
||||||
|
return const ApiResponse(successful: true);
|
||||||
|
} on DioException {
|
||||||
|
return const ApiResponse(successful: false);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
Sentry.captureException(e, stackTrace: stackTrace);
|
Sentry.captureException(e, stackTrace: stackTrace);
|
||||||
return const ApiResponse(successful: false);
|
return const ApiResponse(successful: false);
|
||||||
|
|||||||
Reference in New Issue
Block a user