persist bookmarks ui state
This commit is contained in:
+11
@@ -19,15 +19,21 @@
|
|||||||
*/
|
*/
|
||||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
import 'package:fast_equatable/fast_equatable.dart';
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_sort_type.dart';
|
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_sort_type.dart';
|
||||||
|
|
||||||
part 'bookmark_list_ui_state.g.dart';
|
part 'bookmark_list_ui_state.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
@CopyWith()
|
@CopyWith()
|
||||||
class BookmarkListUiState with FastEquatable {
|
class BookmarkListUiState with FastEquatable {
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
final bool selectionMode;
|
final bool selectionMode;
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
final Set<String> selectedGuids;
|
final Set<String> selectedGuids;
|
||||||
|
@JsonKey(defaultValue: BookmarkSortType.manual)
|
||||||
final BookmarkSortType sortType;
|
final BookmarkSortType sortType;
|
||||||
|
@JsonKey(defaultValue: false)
|
||||||
final bool foldersOnly;
|
final bool foldersOnly;
|
||||||
|
|
||||||
BookmarkListUiState({
|
BookmarkListUiState({
|
||||||
@@ -37,6 +43,11 @@ class BookmarkListUiState with FastEquatable {
|
|||||||
this.foldersOnly = false,
|
this.foldersOnly = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
factory BookmarkListUiState.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$BookmarkListUiStateFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$BookmarkListUiStateToJson(this);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get hashParameters => [
|
List<Object?> get hashParameters => [
|
||||||
selectionMode,
|
selectionMode,
|
||||||
|
|||||||
+29
@@ -98,3 +98,32 @@ extension $BookmarkListUiStateCopyWith on BookmarkListUiState {
|
|||||||
_$BookmarkListUiStateCWProxy get copyWith =>
|
_$BookmarkListUiStateCWProxy get copyWith =>
|
||||||
_$BookmarkListUiStateCWProxyImpl(this);
|
_$BookmarkListUiStateCWProxyImpl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
BookmarkListUiState _$BookmarkListUiStateFromJson(Map<String, dynamic> json) =>
|
||||||
|
BookmarkListUiState(
|
||||||
|
sortType:
|
||||||
|
$enumDecodeNullable(_$BookmarkSortTypeEnumMap, json['sortType']) ??
|
||||||
|
BookmarkSortType.manual,
|
||||||
|
foldersOnly: json['foldersOnly'] as bool? ?? false,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$BookmarkListUiStateToJson(
|
||||||
|
BookmarkListUiState instance,
|
||||||
|
) => <String, dynamic>{
|
||||||
|
'sortType': _$BookmarkSortTypeEnumMap[instance.sortType]!,
|
||||||
|
'foldersOnly': instance.foldersOnly,
|
||||||
|
};
|
||||||
|
|
||||||
|
const _$BookmarkSortTypeEnumMap = {
|
||||||
|
BookmarkSortType.manual: 'manual',
|
||||||
|
BookmarkSortType.titleAsc: 'titleAsc',
|
||||||
|
BookmarkSortType.titleDesc: 'titleDesc',
|
||||||
|
BookmarkSortType.urlAsc: 'urlAsc',
|
||||||
|
BookmarkSortType.urlDesc: 'urlDesc',
|
||||||
|
BookmarkSortType.dateAddedDesc: 'dateAddedDesc',
|
||||||
|
BookmarkSortType.dateAddedAsc: 'dateAddedAsc',
|
||||||
|
};
|
||||||
|
|||||||
+12
-1
@@ -17,16 +17,27 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import 'package:riverpod/experimental/persist.dart';
|
||||||
|
import 'package:riverpod_annotation/experimental/json_persist.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_list_ui_state.dart';
|
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_list_ui_state.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_sort_type.dart';
|
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_sort_type.dart';
|
||||||
|
import 'package:weblibre/features/user/data/providers.dart';
|
||||||
|
|
||||||
part 'bookmark_list_ui_state.g.dart';
|
part 'bookmark_list_ui_state.g.dart';
|
||||||
|
|
||||||
@Riverpod()
|
@Riverpod()
|
||||||
|
@JsonPersist()
|
||||||
class BookmarkListUiStateNotifier extends _$BookmarkListUiStateNotifier {
|
class BookmarkListUiStateNotifier extends _$BookmarkListUiStateNotifier {
|
||||||
@override
|
@override
|
||||||
BookmarkListUiState build() => BookmarkListUiState();
|
BookmarkListUiState build() {
|
||||||
|
persist(
|
||||||
|
ref.watch(riverpodDatabaseStorageProvider),
|
||||||
|
key: 'BookmarkListUiState',
|
||||||
|
);
|
||||||
|
|
||||||
|
return stateOrNull ?? BookmarkListUiState();
|
||||||
|
}
|
||||||
|
|
||||||
void enterSelectionMode({String? initialGuid}) {
|
void enterSelectionMode({String? initialGuid}) {
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
|
|||||||
+43
-2
@@ -10,8 +10,10 @@ part of 'bookmark_list_ui_state.dart';
|
|||||||
// ignore_for_file: type=lint, type=warning
|
// ignore_for_file: type=lint, type=warning
|
||||||
|
|
||||||
@ProviderFor(BookmarkListUiStateNotifier)
|
@ProviderFor(BookmarkListUiStateNotifier)
|
||||||
|
@JsonPersist()
|
||||||
final bookmarkListUiStateProvider = BookmarkListUiStateNotifierProvider._();
|
final bookmarkListUiStateProvider = BookmarkListUiStateNotifierProvider._();
|
||||||
|
|
||||||
|
@JsonPersist()
|
||||||
final class BookmarkListUiStateNotifierProvider
|
final class BookmarkListUiStateNotifierProvider
|
||||||
extends
|
extends
|
||||||
$NotifierProvider<BookmarkListUiStateNotifier, BookmarkListUiState> {
|
$NotifierProvider<BookmarkListUiStateNotifier, BookmarkListUiState> {
|
||||||
@@ -43,9 +45,10 @@ final class BookmarkListUiStateNotifierProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$bookmarkListUiStateNotifierHash() =>
|
String _$bookmarkListUiStateNotifierHash() =>
|
||||||
r'7c764fc2f1deb178063ca95764775ca237471f9f';
|
r'13f01daba9d1591c700e956428f0e0e8cb2bfe92';
|
||||||
|
|
||||||
abstract class _$BookmarkListUiStateNotifier
|
@JsonPersist()
|
||||||
|
abstract class _$BookmarkListUiStateNotifierBase
|
||||||
extends $Notifier<BookmarkListUiState> {
|
extends $Notifier<BookmarkListUiState> {
|
||||||
BookmarkListUiState build();
|
BookmarkListUiState build();
|
||||||
@$mustCallSuper
|
@$mustCallSuper
|
||||||
@@ -63,3 +66,41 @@ abstract class _$BookmarkListUiStateNotifier
|
|||||||
return element.handleCreate(ref, build);
|
return element.handleCreate(ref, build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
abstract class _$BookmarkListUiStateNotifier
|
||||||
|
extends _$BookmarkListUiStateNotifierBase {
|
||||||
|
/// The default key used by [persist].
|
||||||
|
String get key {
|
||||||
|
const resolvedKey = "BookmarkListUiStateNotifier";
|
||||||
|
return resolvedKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A variant of [persist], for JSON-specific encoding.
|
||||||
|
///
|
||||||
|
/// You can override [key] to customize the key used for storage.
|
||||||
|
PersistResult persist(
|
||||||
|
FutureOr<Storage<String, String>> storage, {
|
||||||
|
String? key,
|
||||||
|
String Function(BookmarkListUiState state)? encode,
|
||||||
|
BookmarkListUiState Function(String encoded)? decode,
|
||||||
|
StorageOptions options = const StorageOptions(),
|
||||||
|
}) {
|
||||||
|
return NotifierPersistX(this).persist<String, String>(
|
||||||
|
storage,
|
||||||
|
key: key ?? this.key,
|
||||||
|
encode: encode ?? $jsonCodex.encode,
|
||||||
|
decode:
|
||||||
|
decode ??
|
||||||
|
(encoded) {
|
||||||
|
final e = $jsonCodex.decode(encoded);
|
||||||
|
return BookmarkListUiState.fromJson(e as Map<String, Object?>);
|
||||||
|
},
|
||||||
|
options: options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user