Added lazy loading bookmarks per tag
This commit is contained in:
@@ -1,9 +1,25 @@
|
|||||||
|
import 'package:linkdy/constants/enums.dart';
|
||||||
|
import 'package:linkdy/models/data/bookmarks.dart';
|
||||||
|
import 'package:linkdy/models/data/tags.dart';
|
||||||
|
|
||||||
class TagBookmarksModel {
|
class TagBookmarksModel {
|
||||||
|
String? tagId;
|
||||||
|
Tag? tag;
|
||||||
int currentPage;
|
int currentPage;
|
||||||
int limit;
|
int limit;
|
||||||
|
LoadStatus initialLoadStatus;
|
||||||
|
List<Bookmark> bookmarks;
|
||||||
|
int maxNumber;
|
||||||
|
bool loadingMore;
|
||||||
|
|
||||||
TagBookmarksModel({
|
TagBookmarksModel({
|
||||||
|
this.tagId,
|
||||||
|
this.tag,
|
||||||
this.currentPage = 0,
|
this.currentPage = 0,
|
||||||
this.limit = 100,
|
this.limit = 30,
|
||||||
|
this.initialLoadStatus = LoadStatus.loading,
|
||||||
|
required this.bookmarks,
|
||||||
|
this.maxNumber = 0,
|
||||||
|
this.loadingMore = false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,39 +2,68 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|||||||
|
|
||||||
import 'package:linkdy/screens/tag_bookmarks/model/tag_bookmarks.model.dart';
|
import 'package:linkdy/screens/tag_bookmarks/model/tag_bookmarks.model.dart';
|
||||||
|
|
||||||
|
import 'package:linkdy/constants/enums.dart';
|
||||||
import 'package:linkdy/models/data/tags.dart';
|
import 'package:linkdy/models/data/tags.dart';
|
||||||
import 'package:linkdy/models/data/bookmarks.dart';
|
|
||||||
import 'package:linkdy/models/api_response.dart';
|
|
||||||
import 'package:linkdy/models/data/tag_bookmarks.dart';
|
|
||||||
import 'package:linkdy/providers/api_client_provider.dart';
|
import 'package:linkdy/providers/api_client_provider.dart';
|
||||||
|
|
||||||
part 'tag_bookmarks.provider.g.dart';
|
part 'tag_bookmarks.provider.g.dart';
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
FutureOr<ApiResponse<TagBookmarksResponse?>> tagIdBookmarksRequest(TagIdBookmarksRequestRef ref, String tagId) async {
|
FutureOr<void> tagBookmarksRequest(TagBookmarksRequestRef ref, Tag? tag, String? tagId, int limit) async {
|
||||||
final tagResult = await ref.watch(apiClientProvider)!.fetchTagById(tagId);
|
final tagResult = tag == null ? await ref.watch(apiClientProvider)!.fetchTagById(tagId!) : null;
|
||||||
if (tagResult.content == null) return const ApiResponse(successful: false);
|
if (tagResult != null && tagResult.successful == false) {
|
||||||
final bookmarksResult = await ref.watch(apiClientProvider)!.fetchBookmarks(q: tagResult.content!.name);
|
ref.read(tagBookmarksProvider.notifier).setInitialLoadStatus(LoadStatus.error);
|
||||||
return ApiResponse(
|
return;
|
||||||
successful: bookmarksResult.successful,
|
}
|
||||||
content: TagBookmarksResponse(
|
|
||||||
bookmarksResponse: bookmarksResult.content,
|
final bookmarksResult = await ref.watch(apiClientProvider)!.fetchBookmarks(
|
||||||
tag: tagResult.content,
|
q: tag != null ? tag.name : tagResult!.content!.name,
|
||||||
),
|
limit: limit,
|
||||||
|
offset: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (bookmarksResult.successful == true) {
|
||||||
|
ref.read(tagBookmarksProvider).bookmarks = bookmarksResult.content!.results!;
|
||||||
|
ref.read(tagBookmarksProvider).maxNumber = bookmarksResult.content!.count!;
|
||||||
|
if (tag == null) ref.read(tagBookmarksProvider).tag = tagResult!.content!;
|
||||||
|
ref.read(tagBookmarksProvider).currentPage = 0;
|
||||||
|
ref.read(tagBookmarksProvider).loadingMore = false;
|
||||||
|
ref.read(tagBookmarksProvider).initialLoadStatus = LoadStatus.loaded;
|
||||||
|
} else {
|
||||||
|
ref.read(tagBookmarksProvider).initialLoadStatus = LoadStatus.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(tagBookmarksProvider.notifier).notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
FutureOr<ApiResponse<BookmarksResponse>> tagBookmarksRequest(TagBookmarksRequestRef ref, Tag tag) async {
|
FutureOr<void> tagBookmarksRequestLoadMore(TagBookmarksRequestLoadMoreRef ref) async {
|
||||||
final bookmarksResult = await ref.watch(apiClientProvider)!.fetchBookmarks(q: tag.name);
|
final provider = ref.watch(tagBookmarksProvider);
|
||||||
return bookmarksResult;
|
|
||||||
|
final newOffset = provider.limit * (provider.currentPage + 1);
|
||||||
|
|
||||||
|
final result = await ref.watch(apiClientProvider)!.fetchBookmarks(
|
||||||
|
q: provider.tag!.name,
|
||||||
|
limit: provider.limit,
|
||||||
|
offset: newOffset,
|
||||||
|
);
|
||||||
|
await Future.delayed(Duration(seconds: 4));
|
||||||
|
if (result.successful == true) {
|
||||||
|
provider.bookmarks = [...provider.bookmarks, ...result.content!.results!];
|
||||||
|
provider.maxNumber = result.content!.count!;
|
||||||
|
provider.currentPage = provider.currentPage + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(tagBookmarksProvider.notifier).setLoadingMore(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
class TagBookmarks extends _$TagBookmarks {
|
class TagBookmarks extends _$TagBookmarks {
|
||||||
@override
|
@override
|
||||||
TagBookmarksModel build() {
|
TagBookmarksModel build() {
|
||||||
return TagBookmarksModel();
|
return TagBookmarksModel(
|
||||||
|
bookmarks: [],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentPage(int page) {
|
void setCurrentPage(int page) {
|
||||||
@@ -44,4 +73,22 @@ class TagBookmarks extends _$TagBookmarks {
|
|||||||
void setLimit(int limit) {
|
void setLimit(int limit) {
|
||||||
state.limit = limit;
|
state.limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setInitialLoadStatus(LoadStatus status) {
|
||||||
|
state.initialLoadStatus = status;
|
||||||
|
ref.notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLoadingMore(bool status) {
|
||||||
|
state.loadingMore = status;
|
||||||
|
ref.notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> refresh() async {
|
||||||
|
await ref.read(tagBookmarksRequestProvider(state.tag, state.tagId, state.limit).future);
|
||||||
|
}
|
||||||
|
|
||||||
|
void notifyListeners() {
|
||||||
|
ref.notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ part of 'tag_bookmarks.provider.dart';
|
|||||||
// RiverpodGenerator
|
// RiverpodGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$tagIdBookmarksRequestHash() =>
|
String _$tagBookmarksRequestHash() =>
|
||||||
r'2deadbe50293503ac94cd5d8656d6055c6bdc190';
|
r'92613aa119dadb65b7b399b9c779197673689908';
|
||||||
|
|
||||||
/// Copied from Dart SDK
|
/// Copied from Dart SDK
|
||||||
class _SystemHash {
|
class _SystemHash {
|
||||||
@@ -30,158 +30,25 @@ class _SystemHash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
@ProviderFor(tagIdBookmarksRequest)
|
|
||||||
const tagIdBookmarksRequestProvider = TagIdBookmarksRequestFamily();
|
|
||||||
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
class TagIdBookmarksRequestFamily
|
|
||||||
extends Family<AsyncValue<ApiResponse<TagBookmarksResponse?>>> {
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
const TagIdBookmarksRequestFamily();
|
|
||||||
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
TagIdBookmarksRequestProvider call(
|
|
||||||
String tagId,
|
|
||||||
) {
|
|
||||||
return TagIdBookmarksRequestProvider(
|
|
||||||
tagId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
TagIdBookmarksRequestProvider getProviderOverride(
|
|
||||||
covariant TagIdBookmarksRequestProvider provider,
|
|
||||||
) {
|
|
||||||
return call(
|
|
||||||
provider.tagId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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'tagIdBookmarksRequestProvider';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
class TagIdBookmarksRequestProvider
|
|
||||||
extends AutoDisposeFutureProvider<ApiResponse<TagBookmarksResponse?>> {
|
|
||||||
/// See also [tagIdBookmarksRequest].
|
|
||||||
TagIdBookmarksRequestProvider(
|
|
||||||
String tagId,
|
|
||||||
) : this._internal(
|
|
||||||
(ref) => tagIdBookmarksRequest(
|
|
||||||
ref as TagIdBookmarksRequestRef,
|
|
||||||
tagId,
|
|
||||||
),
|
|
||||||
from: tagIdBookmarksRequestProvider,
|
|
||||||
name: r'tagIdBookmarksRequestProvider',
|
|
||||||
debugGetCreateSourceHash:
|
|
||||||
const bool.fromEnvironment('dart.vm.product')
|
|
||||||
? null
|
|
||||||
: _$tagIdBookmarksRequestHash,
|
|
||||||
dependencies: TagIdBookmarksRequestFamily._dependencies,
|
|
||||||
allTransitiveDependencies:
|
|
||||||
TagIdBookmarksRequestFamily._allTransitiveDependencies,
|
|
||||||
tagId: tagId,
|
|
||||||
);
|
|
||||||
|
|
||||||
TagIdBookmarksRequestProvider._internal(
|
|
||||||
super._createNotifier, {
|
|
||||||
required super.name,
|
|
||||||
required super.dependencies,
|
|
||||||
required super.allTransitiveDependencies,
|
|
||||||
required super.debugGetCreateSourceHash,
|
|
||||||
required super.from,
|
|
||||||
required this.tagId,
|
|
||||||
}) : super.internal();
|
|
||||||
|
|
||||||
final String tagId;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Override overrideWith(
|
|
||||||
FutureOr<ApiResponse<TagBookmarksResponse?>> Function(
|
|
||||||
TagIdBookmarksRequestRef provider)
|
|
||||||
create,
|
|
||||||
) {
|
|
||||||
return ProviderOverride(
|
|
||||||
origin: this,
|
|
||||||
override: TagIdBookmarksRequestProvider._internal(
|
|
||||||
(ref) => create(ref as TagIdBookmarksRequestRef),
|
|
||||||
from: from,
|
|
||||||
name: null,
|
|
||||||
dependencies: null,
|
|
||||||
allTransitiveDependencies: null,
|
|
||||||
debugGetCreateSourceHash: null,
|
|
||||||
tagId: tagId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
AutoDisposeFutureProviderElement<ApiResponse<TagBookmarksResponse?>>
|
|
||||||
createElement() {
|
|
||||||
return _TagIdBookmarksRequestProviderElement(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return other is TagIdBookmarksRequestProvider && other.tagId == tagId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
|
||||||
hash = _SystemHash.combine(hash, tagId.hashCode);
|
|
||||||
|
|
||||||
return _SystemHash.finish(hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mixin TagIdBookmarksRequestRef
|
|
||||||
on AutoDisposeFutureProviderRef<ApiResponse<TagBookmarksResponse?>> {
|
|
||||||
/// The parameter `tagId` of this provider.
|
|
||||||
String get tagId;
|
|
||||||
}
|
|
||||||
|
|
||||||
class _TagIdBookmarksRequestProviderElement
|
|
||||||
extends AutoDisposeFutureProviderElement<ApiResponse<TagBookmarksResponse?>>
|
|
||||||
with TagIdBookmarksRequestRef {
|
|
||||||
_TagIdBookmarksRequestProviderElement(super.provider);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get tagId => (origin as TagIdBookmarksRequestProvider).tagId;
|
|
||||||
}
|
|
||||||
|
|
||||||
String _$tagBookmarksRequestHash() =>
|
|
||||||
r'd198a94eafd0a78ef19de4064da4ddfba26ec1d3';
|
|
||||||
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
@ProviderFor(tagBookmarksRequest)
|
@ProviderFor(tagBookmarksRequest)
|
||||||
const tagBookmarksRequestProvider = TagBookmarksRequestFamily();
|
const tagBookmarksRequestProvider = TagBookmarksRequestFamily();
|
||||||
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
class TagBookmarksRequestFamily
|
class TagBookmarksRequestFamily extends Family<AsyncValue<void>> {
|
||||||
extends Family<AsyncValue<ApiResponse<BookmarksResponse>>> {
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
const TagBookmarksRequestFamily();
|
const TagBookmarksRequestFamily();
|
||||||
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
TagBookmarksRequestProvider call(
|
TagBookmarksRequestProvider call(
|
||||||
Tag tag,
|
Tag? tag,
|
||||||
|
String? tagId,
|
||||||
|
int limit,
|
||||||
) {
|
) {
|
||||||
return TagBookmarksRequestProvider(
|
return TagBookmarksRequestProvider(
|
||||||
tag,
|
tag,
|
||||||
|
tagId,
|
||||||
|
limit,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,6 +58,8 @@ class TagBookmarksRequestFamily
|
|||||||
) {
|
) {
|
||||||
return call(
|
return call(
|
||||||
provider.tag,
|
provider.tag,
|
||||||
|
provider.tagId,
|
||||||
|
provider.limit,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,15 +79,18 @@ class TagBookmarksRequestFamily
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
class TagBookmarksRequestProvider
|
class TagBookmarksRequestProvider extends AutoDisposeFutureProvider<void> {
|
||||||
extends AutoDisposeFutureProvider<ApiResponse<BookmarksResponse>> {
|
|
||||||
/// See also [tagBookmarksRequest].
|
/// See also [tagBookmarksRequest].
|
||||||
TagBookmarksRequestProvider(
|
TagBookmarksRequestProvider(
|
||||||
Tag tag,
|
Tag? tag,
|
||||||
|
String? tagId,
|
||||||
|
int limit,
|
||||||
) : this._internal(
|
) : this._internal(
|
||||||
(ref) => tagBookmarksRequest(
|
(ref) => tagBookmarksRequest(
|
||||||
ref as TagBookmarksRequestRef,
|
ref as TagBookmarksRequestRef,
|
||||||
tag,
|
tag,
|
||||||
|
tagId,
|
||||||
|
limit,
|
||||||
),
|
),
|
||||||
from: tagBookmarksRequestProvider,
|
from: tagBookmarksRequestProvider,
|
||||||
name: r'tagBookmarksRequestProvider',
|
name: r'tagBookmarksRequestProvider',
|
||||||
@@ -230,6 +102,8 @@ class TagBookmarksRequestProvider
|
|||||||
allTransitiveDependencies:
|
allTransitiveDependencies:
|
||||||
TagBookmarksRequestFamily._allTransitiveDependencies,
|
TagBookmarksRequestFamily._allTransitiveDependencies,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
|
tagId: tagId,
|
||||||
|
limit: limit,
|
||||||
);
|
);
|
||||||
|
|
||||||
TagBookmarksRequestProvider._internal(
|
TagBookmarksRequestProvider._internal(
|
||||||
@@ -240,15 +114,17 @@ class TagBookmarksRequestProvider
|
|||||||
required super.debugGetCreateSourceHash,
|
required super.debugGetCreateSourceHash,
|
||||||
required super.from,
|
required super.from,
|
||||||
required this.tag,
|
required this.tag,
|
||||||
|
required this.tagId,
|
||||||
|
required this.limit,
|
||||||
}) : super.internal();
|
}) : super.internal();
|
||||||
|
|
||||||
final Tag tag;
|
final Tag? tag;
|
||||||
|
final String? tagId;
|
||||||
|
final int limit;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Override overrideWith(
|
Override overrideWith(
|
||||||
FutureOr<ApiResponse<BookmarksResponse>> Function(
|
FutureOr<void> Function(TagBookmarksRequestRef provider) create,
|
||||||
TagBookmarksRequestRef provider)
|
|
||||||
create,
|
|
||||||
) {
|
) {
|
||||||
return ProviderOverride(
|
return ProviderOverride(
|
||||||
origin: this,
|
origin: this,
|
||||||
@@ -260,46 +136,77 @@ class TagBookmarksRequestProvider
|
|||||||
allTransitiveDependencies: null,
|
allTransitiveDependencies: null,
|
||||||
debugGetCreateSourceHash: null,
|
debugGetCreateSourceHash: null,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
|
tagId: tagId,
|
||||||
|
limit: limit,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
AutoDisposeFutureProviderElement<ApiResponse<BookmarksResponse>>
|
AutoDisposeFutureProviderElement<void> createElement() {
|
||||||
createElement() {
|
|
||||||
return _TagBookmarksRequestProviderElement(this);
|
return _TagBookmarksRequestProviderElement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return other is TagBookmarksRequestProvider && other.tag == tag;
|
return other is TagBookmarksRequestProvider &&
|
||||||
|
other.tag == tag &&
|
||||||
|
other.tagId == tagId &&
|
||||||
|
other.limit == limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode {
|
int get hashCode {
|
||||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||||
hash = _SystemHash.combine(hash, tag.hashCode);
|
hash = _SystemHash.combine(hash, tag.hashCode);
|
||||||
|
hash = _SystemHash.combine(hash, tagId.hashCode);
|
||||||
|
hash = _SystemHash.combine(hash, limit.hashCode);
|
||||||
|
|
||||||
return _SystemHash.finish(hash);
|
return _SystemHash.finish(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin TagBookmarksRequestRef
|
mixin TagBookmarksRequestRef on AutoDisposeFutureProviderRef<void> {
|
||||||
on AutoDisposeFutureProviderRef<ApiResponse<BookmarksResponse>> {
|
|
||||||
/// The parameter `tag` of this provider.
|
/// The parameter `tag` of this provider.
|
||||||
Tag get tag;
|
Tag? get tag;
|
||||||
|
|
||||||
|
/// The parameter `tagId` of this provider.
|
||||||
|
String? get tagId;
|
||||||
|
|
||||||
|
/// The parameter `limit` of this provider.
|
||||||
|
int get limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TagBookmarksRequestProviderElement
|
class _TagBookmarksRequestProviderElement
|
||||||
extends AutoDisposeFutureProviderElement<ApiResponse<BookmarksResponse>>
|
extends AutoDisposeFutureProviderElement<void> with TagBookmarksRequestRef {
|
||||||
with TagBookmarksRequestRef {
|
|
||||||
_TagBookmarksRequestProviderElement(super.provider);
|
_TagBookmarksRequestProviderElement(super.provider);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Tag get tag => (origin as TagBookmarksRequestProvider).tag;
|
Tag? get tag => (origin as TagBookmarksRequestProvider).tag;
|
||||||
|
@override
|
||||||
|
String? get tagId => (origin as TagBookmarksRequestProvider).tagId;
|
||||||
|
@override
|
||||||
|
int get limit => (origin as TagBookmarksRequestProvider).limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$tagBookmarksHash() => r'bcfcc986b8d58ccff54ed6dec3ab2a1a8c33a4f7';
|
String _$tagBookmarksRequestLoadMoreHash() =>
|
||||||
|
r'3235c66b13a41c52611b86c2b26ecf9376ca1524';
|
||||||
|
|
||||||
|
/// See also [tagBookmarksRequestLoadMore].
|
||||||
|
@ProviderFor(tagBookmarksRequestLoadMore)
|
||||||
|
final tagBookmarksRequestLoadMoreProvider =
|
||||||
|
AutoDisposeFutureProvider<void>.internal(
|
||||||
|
tagBookmarksRequestLoadMore,
|
||||||
|
name: r'tagBookmarksRequestLoadMoreProvider',
|
||||||
|
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||||
|
? null
|
||||||
|
: _$tagBookmarksRequestLoadMoreHash,
|
||||||
|
dependencies: null,
|
||||||
|
allTransitiveDependencies: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef TagBookmarksRequestLoadMoreRef = AutoDisposeFutureProviderRef<void>;
|
||||||
|
String _$tagBookmarksHash() => r'74e6463830052de2f05c628455d5ccca9faef765';
|
||||||
|
|
||||||
/// See also [TagBookmarks].
|
/// See also [TagBookmarks].
|
||||||
@ProviderFor(TagBookmarks)
|
@ProviderFor(TagBookmarks)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||||
@@ -7,15 +6,13 @@ import 'package:linkdy/screens/tag_bookmarks/provider/tag_bookmarks.provider.dar
|
|||||||
import 'package:linkdy/widgets/error_screen.dart';
|
import 'package:linkdy/widgets/error_screen.dart';
|
||||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||||
|
|
||||||
import 'package:linkdy/models/api_response.dart';
|
|
||||||
import 'package:linkdy/models/data/bookmarks.dart';
|
|
||||||
import 'package:linkdy/models/data/tag_bookmarks.dart';
|
|
||||||
import 'package:linkdy/models/data/tags.dart';
|
import 'package:linkdy/models/data/tags.dart';
|
||||||
|
import 'package:linkdy/constants/enums.dart';
|
||||||
import 'package:linkdy/providers/router_provider.dart';
|
import 'package:linkdy/providers/router_provider.dart';
|
||||||
import 'package:linkdy/router/paths.dart';
|
import 'package:linkdy/router/paths.dart';
|
||||||
import 'package:linkdy/i18n/strings.g.dart';
|
import 'package:linkdy/i18n/strings.g.dart';
|
||||||
|
|
||||||
class TagBookmarksScreen extends ConsumerWidget {
|
class TagBookmarksScreen extends ConsumerStatefulWidget {
|
||||||
final String? tagId;
|
final String? tagId;
|
||||||
final Tag? tag;
|
final Tag? tag;
|
||||||
|
|
||||||
@@ -26,31 +23,48 @@ class TagBookmarksScreen extends ConsumerWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
TagBookmarksScreenState createState() => TagBookmarksScreenState();
|
||||||
// Redirect to initial screen if no tagId or tag
|
}
|
||||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
|
||||||
if (tag == null && tagId == null) {
|
class TagBookmarksScreenState extends ConsumerState<TagBookmarksScreen> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (widget.tag == null && widget.tagId == null) {
|
||||||
final router = ref.watch(routerProvider);
|
final router = ref.watch(routerProvider);
|
||||||
while (router.canPop() == true) {
|
while (router.canPop() == true) {
|
||||||
router.pop();
|
router.pop();
|
||||||
}
|
}
|
||||||
router.pushReplacement(RoutesPaths.bookmarks);
|
router.pushReplacement(RoutesPaths.bookmarks);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
if (widget.tag != null) {
|
||||||
|
ref.read(tagBookmarksProvider).tag = widget.tag;
|
||||||
|
}
|
||||||
|
if (widget.tagId != null) {
|
||||||
|
ref.read(tagBookmarksProvider).tagId = widget.tagId;
|
||||||
|
}
|
||||||
|
ref.read(tagBookmarksRequestProvider(widget.tag, widget.tagId, ref.read(tagBookmarksProvider).limit));
|
||||||
|
|
||||||
if (tag == null && tagId == null) return const Material();
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
final bookmarksResponse =
|
@override
|
||||||
tag != null ? ref.watch(tagBookmarksRequestProvider(tag!)) : ref.watch(tagIdBookmarksRequestProvider(tagId!));
|
Widget build(BuildContext context) {
|
||||||
|
if (widget.tag == null && widget.tagId == null) return const Material();
|
||||||
|
|
||||||
final bookmarks = tag != null
|
final provider = ref.watch(tagBookmarksProvider);
|
||||||
? (bookmarksResponse.value as ApiResponse<BookmarksResponse>?)?.content
|
|
||||||
: (bookmarksResponse.value as ApiResponse<TagBookmarksResponse?>?)?.content?.bookmarksResponse;
|
|
||||||
|
|
||||||
final title = tag != null
|
bool scrollListener(ScrollUpdateNotification scrollNotification) {
|
||||||
? tag!.name!
|
if (scrollNotification.metrics.extentAfter < 100 &&
|
||||||
: ((bookmarksResponse.value as ApiResponse<TagBookmarksResponse?>?)?.content?.tag?.name ?? '');
|
provider.loadingMore == false &&
|
||||||
|
provider.bookmarks.length < provider.maxNumber) {
|
||||||
|
ref.read(tagBookmarksProvider.notifier).setLoadingMore(true);
|
||||||
|
ref.watch(tagBookmarksRequestLoadMoreProvider);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
print(provider.maxNumber);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: NestedScrollView(
|
body: NestedScrollView(
|
||||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||||
@@ -61,50 +75,62 @@ class TagBookmarksScreen extends ConsumerWidget {
|
|||||||
floating: true,
|
floating: true,
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
forceElevated: innerBoxIsScrolled,
|
forceElevated: innerBoxIsScrolled,
|
||||||
title: Text(title != "" ? "#$title" : ""),
|
title: Text(
|
||||||
|
widget.tag != null
|
||||||
|
? "#${widget.tag!.name}"
|
||||||
|
: provider.tag != null
|
||||||
|
? "#${provider.tag!.name}"
|
||||||
|
: '',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
bottom: false,
|
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) => RefreshIndicator(
|
builder: (context) => RefreshIndicator(
|
||||||
displacement: 120,
|
displacement: 120,
|
||||||
onRefresh: () => tag != null
|
onRefresh: () => ref.read(tagBookmarksProvider.notifier).refresh(),
|
||||||
? ref.watch(tagBookmarksRequestProvider(tag!).future)
|
child: NotificationListener(
|
||||||
: ref.watch(tagIdBookmarksRequestProvider(tagId!).future),
|
onNotification: scrollListener,
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverOverlapInjector(
|
SliverOverlapInjector(
|
||||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||||
),
|
),
|
||||||
if (bookmarksResponse.isLoading && !bookmarksResponse.isRefreshing)
|
if (provider.initialLoadStatus == LoadStatus.loading)
|
||||||
const SliverFillRemaining(
|
const SliverFillRemaining(
|
||||||
child: Center(child: CircularProgressIndicator()),
|
child: Center(child: CircularProgressIndicator()),
|
||||||
),
|
),
|
||||||
if (bookmarksResponse.value != null && bookmarksResponse.value!.successful == false)
|
if (provider.initialLoadStatus == LoadStatus.error)
|
||||||
SliverFillRemaining(
|
SliverFillRemaining(
|
||||||
child: ErrorScreen(
|
child: ErrorScreen(
|
||||||
error: t.bookmarks.cannotLoadBookmarks,
|
error: t.bookmarks.cannotLoadBookmarks,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (bookmarksResponse.value != null &&
|
if (provider.bookmarks.isEmpty)
|
||||||
bookmarksResponse.value!.successful == true &&
|
|
||||||
bookmarks!.results!.isEmpty)
|
|
||||||
SliverFillRemaining(
|
SliverFillRemaining(
|
||||||
child: NoDataScreen(
|
child: NoDataScreen(
|
||||||
message: t.tags.tagBookmarks.noBookmarksWithThisTag,
|
message: t.tags.tagBookmarks.noBookmarksWithThisTag,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (bookmarksResponse.value != null &&
|
if (provider.bookmarks.isNotEmpty)
|
||||||
bookmarksResponse.value!.successful == true &&
|
|
||||||
bookmarks!.results!.isNotEmpty)
|
|
||||||
SliverList.builder(
|
SliverList.builder(
|
||||||
itemCount: bookmarks.results!.length,
|
itemCount:
|
||||||
itemBuilder: (context, index) => BookmarkItem(
|
provider.loadingMore == true ? provider.bookmarks.length + 1 : provider.bookmarks.length,
|
||||||
bookmark: bookmarks.results![index],
|
itemBuilder: (context, index) {
|
||||||
|
if (provider.loadingMore == true && index == provider.bookmarks.length) {
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return BookmarkItem(
|
||||||
|
bookmark: provider.bookmarks[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -112,6 +138,7 @@ class TagBookmarksScreen extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user