💄 Improve performance and bugs
This commit is contained in:
@@ -50,7 +50,7 @@ final class MessagesNotifierProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$messagesNotifierHash() => r'2f3f19cb99357184e82d66e74a31863fcfc48856';
|
String _$messagesNotifierHash() => r'284625cff963ff26375d50d7202a33184e810fcb';
|
||||||
|
|
||||||
final class MessagesNotifierFamily extends $Family
|
final class MessagesNotifierFamily extends $Family
|
||||||
with
|
with
|
||||||
|
|||||||
@@ -185,7 +185,9 @@ class NotificationListNotifier extends AsyncNotifier<List<SnNotification>>
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
final unreadCount = notifications.where((n) => n.viewedAt == null).length;
|
final unreadCount = notifications.where((n) => n.viewedAt == null).length;
|
||||||
ref.read(notificationUnreadCountProvider.notifier).decrement(unreadCount);
|
if (ref.mounted) {
|
||||||
|
ref.read(notificationUnreadCountProvider.notifier).decrement(unreadCount);
|
||||||
|
}
|
||||||
|
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ final class PublisherSubscriptionStatusProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$publisherSubscriptionStatusHash() =>
|
String _$publisherSubscriptionStatusHash() =>
|
||||||
r'accf6a0cdf98f8b0474d94ac575e8b20448adc79';
|
r'688bf38554afea9e68b2cb59c5f08c6e8dd31b62';
|
||||||
|
|
||||||
final class PublisherSubscriptionStatusFamily extends $Family
|
final class PublisherSubscriptionStatusFamily extends $Family
|
||||||
with $FunctionalFamilyOverride<FutureOr<SnPublisherSubscription?>, String> {
|
with $FunctionalFamilyOverride<FutureOr<SnPublisherSubscription?>, String> {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'package:island/widgets/content/cloud_files.dart';
|
|||||||
import 'package:island/widgets/navigation/conditional_bottom_nav.dart';
|
import 'package:island/widgets/navigation/conditional_bottom_nav.dart';
|
||||||
import 'package:material_symbols_icons/symbols.dart';
|
import 'package:material_symbols_icons/symbols.dart';
|
||||||
import 'package:island/pods/chat/chat_summary.dart';
|
import 'package:island/pods/chat/chat_summary.dart';
|
||||||
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
|
|
||||||
final currentRouteProvider = NotifierProvider<CurrentRouteNotifier, String?>(
|
final currentRouteProvider = NotifierProvider<CurrentRouteNotifier, String?>(
|
||||||
CurrentRouteNotifier.new,
|
CurrentRouteNotifier.new,
|
||||||
@@ -237,7 +238,7 @@ class TabsScreen extends HookConsumerWidget {
|
|||||||
indicatorColor: Theme.of(
|
indicatorColor: Theme.of(
|
||||||
context,
|
context,
|
||||||
).colorScheme.primary.withOpacity(0.2),
|
).colorScheme.primary.withOpacity(0.2),
|
||||||
),
|
).padding(horizontal: 12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -24,6 +24,46 @@ part 'post_shared.g.dart';
|
|||||||
|
|
||||||
const kMessageEnableEmbedTypes = ['text', 'messages.new'];
|
const kMessageEnableEmbedTypes = ['text', 'messages.new'];
|
||||||
|
|
||||||
|
class RepliesState {
|
||||||
|
final List<SnPost> posts;
|
||||||
|
final bool loading;
|
||||||
|
|
||||||
|
RepliesState({required this.posts, required this.loading});
|
||||||
|
|
||||||
|
RepliesState copyWith({List<SnPost>? posts, bool? loading}) {
|
||||||
|
return RepliesState(
|
||||||
|
posts: posts ?? this.posts,
|
||||||
|
loading: loading ?? this.loading,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@riverpod
|
||||||
|
class RepliesNotifier extends _$RepliesNotifier {
|
||||||
|
@override
|
||||||
|
RepliesState build(String parentId) {
|
||||||
|
return RepliesState(posts: [], loading: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> fetchMore(int pageSize) async {
|
||||||
|
state = state.copyWith(loading: true);
|
||||||
|
|
||||||
|
final client = ref.read(apiClientProvider);
|
||||||
|
|
||||||
|
final response = await client.get(
|
||||||
|
'/sphere/posts/$parentId/replies',
|
||||||
|
queryParameters: {'offset': state.posts.length, 'take': pageSize},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!ref.mounted) return;
|
||||||
|
|
||||||
|
state = state.copyWith(
|
||||||
|
posts: [...state.posts, ...response.data.map((e) => SnPost.fromJson(e))],
|
||||||
|
loading: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
Future<SnPost?> postFeaturedReply(Ref ref, String id) async {
|
Future<SnPost?> postFeaturedReply(Ref ref, String id) async {
|
||||||
final client = ref.watch(apiClientProvider);
|
final client = ref.watch(apiClientProvider);
|
||||||
@@ -82,39 +122,18 @@ class PostReplyPreview extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final posts = useState<List<SnPost>>([]);
|
final repliesState = ref.watch(repliesProvider(parent.id));
|
||||||
final loading = useState(false);
|
|
||||||
|
|
||||||
Future<void> fetchMoreReplies({int pageSize = 3}) async {
|
|
||||||
final client = ref.read(apiClientProvider);
|
|
||||||
loading.value = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
final response = await client.get(
|
|
||||||
'/sphere/posts/${parent.id}/replies',
|
|
||||||
queryParameters: {'offset': posts.value.length, 'take': pageSize},
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
posts.value = [
|
|
||||||
...posts.value,
|
|
||||||
...response.data.map((e) => SnPost.fromJson(e)),
|
|
||||||
];
|
|
||||||
} catch (_) {
|
|
||||||
// ignore disposed
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
showErrorAlert(err);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
loading.value = false;
|
|
||||||
} catch (_) {
|
|
||||||
// ignore disposed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
if (isAutoload) fetchMoreReplies();
|
if (isAutoload) {
|
||||||
|
Future(() async {
|
||||||
|
try {
|
||||||
|
await ref.read(repliesProvider(parent.id).notifier).fetchMore(3);
|
||||||
|
} catch (err) {
|
||||||
|
showErrorAlert(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}, [parent]);
|
}, [parent]);
|
||||||
|
|
||||||
@@ -127,7 +146,7 @@ class PostReplyPreview extends HookConsumerWidget {
|
|||||||
? Column(
|
? Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
for (final post in posts.value)
|
for (final post in repliesState.posts)
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -183,7 +202,7 @@ class PostReplyPreview extends HookConsumerWidget {
|
|||||||
).padding(left: 24),
|
).padding(left: 24),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (loading.value)
|
if (repliesState.loading)
|
||||||
Row(
|
Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
@@ -196,7 +215,7 @@ class PostReplyPreview extends HookConsumerWidget {
|
|||||||
Text('loading').tr(),
|
Text('loading').tr(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
else if (posts.value.length < parent.repliesCount)
|
else if (repliesState.posts.length < parent.repliesCount)
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -206,8 +225,14 @@ class PostReplyPreview extends HookConsumerWidget {
|
|||||||
Text('repliesLoadMore').tr(),
|
Text('repliesLoadMore').tr(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
fetchMoreReplies();
|
try {
|
||||||
|
await ref
|
||||||
|
.read(repliesProvider(parent.id).notifier)
|
||||||
|
.fetchMore(3);
|
||||||
|
} catch (err) {
|
||||||
|
showErrorAlert(err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -9,6 +9,104 @@ part of 'post_shared.dart';
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
// ignore_for_file: type=lint, type=warning
|
// ignore_for_file: type=lint, type=warning
|
||||||
|
|
||||||
|
@ProviderFor(RepliesNotifier)
|
||||||
|
const repliesProvider = RepliesNotifierFamily._();
|
||||||
|
|
||||||
|
final class RepliesNotifierProvider
|
||||||
|
extends $NotifierProvider<RepliesNotifier, RepliesState> {
|
||||||
|
const RepliesNotifierProvider._({
|
||||||
|
required RepliesNotifierFamily super.from,
|
||||||
|
required String super.argument,
|
||||||
|
}) : super(
|
||||||
|
retry: null,
|
||||||
|
name: r'repliesProvider',
|
||||||
|
isAutoDispose: true,
|
||||||
|
dependencies: null,
|
||||||
|
$allTransitiveDependencies: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String debugGetCreateSourceHash() => _$repliesNotifierHash();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return r'repliesProvider'
|
||||||
|
''
|
||||||
|
'($argument)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@$internal
|
||||||
|
@override
|
||||||
|
RepliesNotifier create() => RepliesNotifier();
|
||||||
|
|
||||||
|
/// {@macro riverpod.override_with_value}
|
||||||
|
Override overrideWithValue(RepliesState value) {
|
||||||
|
return $ProviderOverride(
|
||||||
|
origin: this,
|
||||||
|
providerOverride: $SyncValueProvider<RepliesState>(value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return other is RepliesNotifierProvider && other.argument == argument;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return argument.hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _$repliesNotifierHash() => r'2fa51bc3b8cc640e68fa316f61d00f8a0a3740ed';
|
||||||
|
|
||||||
|
final class RepliesNotifierFamily extends $Family
|
||||||
|
with
|
||||||
|
$ClassFamilyOverride<
|
||||||
|
RepliesNotifier,
|
||||||
|
RepliesState,
|
||||||
|
RepliesState,
|
||||||
|
RepliesState,
|
||||||
|
String
|
||||||
|
> {
|
||||||
|
const RepliesNotifierFamily._()
|
||||||
|
: super(
|
||||||
|
retry: null,
|
||||||
|
name: r'repliesProvider',
|
||||||
|
dependencies: null,
|
||||||
|
$allTransitiveDependencies: null,
|
||||||
|
isAutoDispose: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
RepliesNotifierProvider call(String parentId) =>
|
||||||
|
RepliesNotifierProvider._(argument: parentId, from: this);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => r'repliesProvider';
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _$RepliesNotifier extends $Notifier<RepliesState> {
|
||||||
|
late final _$args = ref.$arg as String;
|
||||||
|
String get parentId => _$args;
|
||||||
|
|
||||||
|
RepliesState build(String parentId);
|
||||||
|
@$mustCallSuper
|
||||||
|
@override
|
||||||
|
void runBuild() {
|
||||||
|
final created = build(_$args);
|
||||||
|
final ref = this.ref as $Ref<RepliesState, RepliesState>;
|
||||||
|
final element =
|
||||||
|
ref.element
|
||||||
|
as $ClassProviderElement<
|
||||||
|
AnyNotifier<RepliesState, RepliesState>,
|
||||||
|
RepliesState,
|
||||||
|
Object?,
|
||||||
|
Object?
|
||||||
|
>;
|
||||||
|
element.handleValue(ref, created);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ProviderFor(postFeaturedReply)
|
@ProviderFor(postFeaturedReply)
|
||||||
const postFeaturedReplyProvider = PostFeaturedReplyFamily._();
|
const postFeaturedReplyProvider = PostFeaturedReplyFamily._();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user