Skip to content

Commit

Permalink
fix: add live refresh to reply list so that fresh created replies are…
Browse files Browse the repository at this point in the history
… visible
  • Loading branch information
ice-ajax committed Dec 31, 2024
1 parent 9c6ff28 commit 49c9b99
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
35 changes: 35 additions & 0 deletions lib/app/features/feed/providers/replies_provider.c.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: ice License 1.0

import 'package:ion/app/features/feed/data/models/entities/post_data.c.dart';
import 'package:ion/app/features/feed/providers/replies_data_source_provider.c.dart';
import 'package:ion/app/features/nostr/model/event_reference.c.dart';
import 'package:ion/app/features/nostr/model/nostr_entity.dart';
import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart';
import 'package:ion/app/features/nostr/providers/nostr_cache.c.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'replies_provider.c.g.dart';

@riverpod
class Replies extends _$Replies {
@override
EntitiesPagedDataState? build(EventReference eventReference) {
final dataSource = ref.watch(repliesDataSourceProvider(eventReference: eventReference));
final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource));

final subscription = ref
.watch(nostrCacheStreamProvider)
.where((entity) => _isReply(entity, eventReference))
.distinct()
.listen((entity) {
state = state?.copyWith.data(items: {entity, ...state?.data.items ?? {}});
});
ref.onDispose(subscription.cancel);

return entitiesPagedData;
}

bool _isReply(NostrEntity entity, EventReference parentEventReference) {
return entity is PostEntity && entity.data.parentEvent?.eventId == parentEventReference.eventId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/components/entities_list/entities_list.dart';
import 'package:ion/app/features/components/entities_list/entities_list_skeleton.dart';
import 'package:ion/app/features/feed/providers/replies_data_source_provider.c.dart';
import 'package:ion/app/features/feed/providers/replies_provider.c.dart';
import 'package:ion/app/features/nostr/model/event_reference.c.dart';
import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart';

class ReplyList extends ConsumerWidget {
const ReplyList({required this.eventReference, super.key});
Expand All @@ -16,9 +15,8 @@ class ReplyList extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final dataSource = ref.watch(repliesDataSourceProvider(eventReference: eventReference));
final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource));
final entities = entitiesPagedData?.data.items;
final replies = ref.watch(repliesProvider(eventReference));
final entities = replies?.data.items;

if (entities == null) {
return const EntitiesListSkeleton();
Expand Down

0 comments on commit 49c9b99

Please sign in to comment.