Added archive and unarchive

This commit is contained in:
Juan Gilsanz Polo
2024-02-26 22:14:41 +01:00
parent fa0441a0e4
commit 5faf08e597
9 changed files with 73 additions and 35 deletions

View File

@@ -129,17 +129,18 @@ class SearchBookmarks extends _$SearchBookmarks {
}
void archiveUnarchive(Bookmark bookmark) async {
final result = await BookmarkCommonFunctions.markAsReadUnread<SearchBookmarksModel>(
final result = await BookmarkCommonFunctions.archiveUnarchive<SearchBookmarksModel>(
ref: ref,
bookmark: bookmark,
apiClient: ref.read(apiClientProvider)!,
);
if (result != null) {
state.bookmarks = state.bookmarks.map((b) => b.id == result.id ? result : b).toList();
if (result == true) {
// 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
.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());
}
}
}