Added read status selector
This commit is contained in:
@@ -9,6 +9,7 @@ class BookmarksModel {
|
||||
LoadStatus inialLoadStatus;
|
||||
bool loadingMore;
|
||||
int maxNumber;
|
||||
ReadStatus readStatus;
|
||||
|
||||
BookmarksModel({
|
||||
this.currentPage = 0,
|
||||
@@ -17,5 +18,6 @@ class BookmarksModel {
|
||||
this.inialLoadStatus = LoadStatus.loading,
|
||||
this.loadingMore = false,
|
||||
this.maxNumber = 0,
|
||||
this.readStatus = ReadStatus.all,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,10 +12,11 @@ import 'package:linkdy/constants/enums.dart';
|
||||
part 'bookmarks.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
FutureOr<void> bookmarksRequest(BookmarksRequestRef ref, int limit) async {
|
||||
FutureOr<void> bookmarksRequest(BookmarksRequestRef ref, ReadStatus readStatus, int limit) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchBookmarks(
|
||||
limit: limit,
|
||||
offset: 0,
|
||||
unread: readStatus,
|
||||
);
|
||||
|
||||
if (result.successful == true) {
|
||||
@@ -40,6 +41,7 @@ FutureOr<void> bookmarksRequestLoadMore(BookmarksRequestLoadMoreRef ref) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchBookmarks(
|
||||
limit: provider.limit,
|
||||
offset: newOffset,
|
||||
unread: ref.read(bookmarksProvider).readStatus,
|
||||
);
|
||||
|
||||
if (result.successful == true) {
|
||||
@@ -59,7 +61,7 @@ class Bookmarks extends _$Bookmarks {
|
||||
final model = BookmarksModel(
|
||||
bookmarks: [],
|
||||
);
|
||||
ref.read(bookmarksRequestProvider(model.limit));
|
||||
ref.read(bookmarksRequestProvider(model.readStatus, model.limit));
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -85,8 +87,14 @@ class Bookmarks extends _$Bookmarks {
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void setReadStatus(ReadStatus status) {
|
||||
state.readStatus = status;
|
||||
ref.read(bookmarksRequestProvider(status, state.limit));
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
await ref.read(bookmarksRequestProvider(state.limit).future);
|
||||
await ref.read(bookmarksRequestProvider(state.readStatus, state.limit).future);
|
||||
}
|
||||
|
||||
void deleteBookmark(Bookmark bookmark) async {
|
||||
|
||||
@@ -6,7 +6,7 @@ part of 'bookmarks.provider.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$bookmarksRequestHash() => r'2da88ec52b4f959e6355f5f5fa8660d6cebd157d';
|
||||
String _$bookmarksRequestHash() => r'eb1ddffb83edc0fa433fae76859bde4206e59940';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
@@ -40,9 +40,11 @@ class BookmarksRequestFamily extends Family<AsyncValue<void>> {
|
||||
|
||||
/// See also [bookmarksRequest].
|
||||
BookmarksRequestProvider call(
|
||||
ReadStatus readStatus,
|
||||
int limit,
|
||||
) {
|
||||
return BookmarksRequestProvider(
|
||||
readStatus,
|
||||
limit,
|
||||
);
|
||||
}
|
||||
@@ -52,6 +54,7 @@ class BookmarksRequestFamily extends Family<AsyncValue<void>> {
|
||||
covariant BookmarksRequestProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.readStatus,
|
||||
provider.limit,
|
||||
);
|
||||
}
|
||||
@@ -75,10 +78,12 @@ class BookmarksRequestFamily extends Family<AsyncValue<void>> {
|
||||
class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
/// See also [bookmarksRequest].
|
||||
BookmarksRequestProvider(
|
||||
ReadStatus readStatus,
|
||||
int limit,
|
||||
) : this._internal(
|
||||
(ref) => bookmarksRequest(
|
||||
ref as BookmarksRequestRef,
|
||||
readStatus,
|
||||
limit,
|
||||
),
|
||||
from: bookmarksRequestProvider,
|
||||
@@ -90,6 +95,7 @@ class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
dependencies: BookmarksRequestFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
BookmarksRequestFamily._allTransitiveDependencies,
|
||||
readStatus: readStatus,
|
||||
limit: limit,
|
||||
);
|
||||
|
||||
@@ -100,9 +106,11 @@ class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.readStatus,
|
||||
required this.limit,
|
||||
}) : super.internal();
|
||||
|
||||
final ReadStatus readStatus;
|
||||
final int limit;
|
||||
|
||||
@override
|
||||
@@ -118,6 +126,7 @@ class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
readStatus: readStatus,
|
||||
limit: limit,
|
||||
),
|
||||
);
|
||||
@@ -130,12 +139,15 @@ class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is BookmarksRequestProvider && other.limit == limit;
|
||||
return other is BookmarksRequestProvider &&
|
||||
other.readStatus == readStatus &&
|
||||
other.limit == limit;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, readStatus.hashCode);
|
||||
hash = _SystemHash.combine(hash, limit.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
@@ -143,6 +155,9 @@ class BookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||
}
|
||||
|
||||
mixin BookmarksRequestRef on AutoDisposeFutureProviderRef<void> {
|
||||
/// The parameter `readStatus` of this provider.
|
||||
ReadStatus get readStatus;
|
||||
|
||||
/// The parameter `limit` of this provider.
|
||||
int get limit;
|
||||
}
|
||||
@@ -151,12 +166,14 @@ class _BookmarksRequestProviderElement
|
||||
extends AutoDisposeFutureProviderElement<void> with BookmarksRequestRef {
|
||||
_BookmarksRequestProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
ReadStatus get readStatus => (origin as BookmarksRequestProvider).readStatus;
|
||||
@override
|
||||
int get limit => (origin as BookmarksRequestProvider).limit;
|
||||
}
|
||||
|
||||
String _$bookmarksRequestLoadMoreHash() =>
|
||||
r'36b0703684218e1c6bf01643788d5f9d3da32327';
|
||||
r'1a206bd974677fd862eb4d5b5f453df9f566d995';
|
||||
|
||||
/// See also [bookmarksRequestLoadMore].
|
||||
@ProviderFor(bookmarksRequestLoadMore)
|
||||
@@ -172,7 +189,7 @@ final bookmarksRequestLoadMoreProvider =
|
||||
);
|
||||
|
||||
typedef BookmarksRequestLoadMoreRef = AutoDisposeFutureProviderRef<void>;
|
||||
String _$bookmarksHash() => r'602a50d02cde9a67335372659f8e2f656ac21995';
|
||||
String _$bookmarksHash() => r'0a1d73459b3c148ba31655347364ee3a9e70b68a';
|
||||
|
||||
/// See also [Bookmarks].
|
||||
@ProviderFor(Bookmarks)
|
||||
|
||||
@@ -6,7 +6,7 @@ part of 'favicon_loader.provider.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$faviconStoreHash() => r'aeda388d2c7d220a43a29825a9850d8d7433d84f';
|
||||
String _$faviconStoreHash() => r'459949315bf6a236946c8b03ba90ce047b691b7e';
|
||||
|
||||
/// See also [FaviconStore].
|
||||
@ProviderFor(FaviconStore)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:quds_popup_menu/quds_popup_menu.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
@@ -50,6 +51,22 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
String readStatus() {
|
||||
switch (bookmarks.readStatus) {
|
||||
case ReadStatus.all:
|
||||
return t.bookmarks.all;
|
||||
|
||||
case ReadStatus.unread:
|
||||
return t.bookmarks.unread;
|
||||
|
||||
case ReadStatus.read:
|
||||
return t.bookmarks.read;
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return ScaffoldMessenger(
|
||||
key: ScaffoldMessengerKeys.bookmarks,
|
||||
child: Scaffold(
|
||||
@@ -62,7 +79,44 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
floating: true,
|
||||
centerTitle: false,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
title: Text(t.bookmarks.bookmarks),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(t.bookmarks.bookmarks),
|
||||
if (bookmarks.readStatus == ReadStatus.read || bookmarks.readStatus == ReadStatus.unread)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
bookmarks.readStatus == ReadStatus.read
|
||||
? Icons.mark_email_read_rounded
|
||||
: Icons.mark_as_unread_rounded,
|
||||
size: 14,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
bookmarks.readStatus == ReadStatus.read ? t.bookmarks.read : t.bookmarks.unread,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
key: _searchButtonKey,
|
||||
@@ -70,31 +124,76 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
icon: const Icon(Icons.search_rounded),
|
||||
tooltip: t.bookmarks.search.searchBookmarks,
|
||||
),
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.archivedBookmarks),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.archive_rounded),
|
||||
const SizedBox(width: 16),
|
||||
Text(t.bookmarks.archived),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
QudsPopupButton(
|
||||
radius: 22,
|
||||
backgroundColor: Theme.of(context).popupMenuTheme.surfaceTintColor,
|
||||
items: [
|
||||
QudsPopupMenuItem(
|
||||
leading: const Icon(Icons.archive_rounded),
|
||||
title: Text(t.bookmarks.archived),
|
||||
onPressed: () => ref.read(routerProvider).push(RoutesPaths.archivedBookmarks),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.sharedBookmarks),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.share_rounded),
|
||||
const SizedBox(width: 16),
|
||||
Text(t.bookmarks.shared),
|
||||
],
|
||||
),
|
||||
QudsPopupMenuItem(
|
||||
leading: const Icon(Icons.share_rounded),
|
||||
title: Text(t.bookmarks.shared),
|
||||
onPressed: () => ref.read(routerProvider).push(RoutesPaths.sharedBookmarks),
|
||||
),
|
||||
QudsPopupMenuDivider(),
|
||||
QudsPopupMenuSection(
|
||||
leading: const Icon(Icons.list_rounded),
|
||||
titleText: t.bookmarks.readStatus,
|
||||
subTitle: Text(readStatus()),
|
||||
subItems: [
|
||||
QudsPopupMenuItem(
|
||||
leading: const Icon(Icons.list_rounded),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(t.bookmarks.showAllBookmarks)),
|
||||
if (bookmarks.readStatus == ReadStatus.all) ...[
|
||||
const SizedBox(width: 8),
|
||||
const Icon(Icons.check_rounded),
|
||||
],
|
||||
],
|
||||
),
|
||||
onPressed: () => ref.read(bookmarksProvider.notifier).setReadStatus(ReadStatus.all),
|
||||
),
|
||||
QudsPopupMenuItem(
|
||||
leading: const Icon(Icons.mark_as_unread_rounded),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(t.bookmarks.showOnlyUnread)),
|
||||
if (bookmarks.readStatus == ReadStatus.unread) ...[
|
||||
const SizedBox(width: 8),
|
||||
const Icon(Icons.check_rounded),
|
||||
],
|
||||
],
|
||||
),
|
||||
onPressed: () => ref.read(bookmarksProvider.notifier).setReadStatus(ReadStatus.unread),
|
||||
),
|
||||
QudsPopupMenuItem(
|
||||
leading: const Icon(Icons.mark_email_read_rounded),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(t.bookmarks.showOnlyRead)),
|
||||
if (bookmarks.readStatus == ReadStatus.read) ...[
|
||||
const SizedBox(width: 8),
|
||||
const Icon(Icons.check_rounded),
|
||||
],
|
||||
],
|
||||
),
|
||||
onPressed: () => ref.read(bookmarksProvider.notifier).setReadStatus(ReadStatus.read),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
tooltip: t.generic.options,
|
||||
child: const Icon(Icons.more_vert_rounded),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user