Skip to content

Commit

Permalink
refactor: return UserMetadata from followersDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-orion committed Dec 11, 2024
1 parent 71aeaf8 commit 20ca372
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,44 @@ import 'package:ion/app/components/list_item/list_item.dart';
import 'package:ion/app/components/list_items_loading_state/item_loading_state.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/components/user/follow_user_button/follow_user_button.dart';
import 'package:ion/app/features/user/model/user_metadata.c.dart';
import 'package:ion/app/features/user/providers/user_metadata_provider.c.dart';
import 'package:ion/app/utils/username.dart';

class FollowListItem extends ConsumerWidget {
const FollowListItem({
required this.userMetadata,
required this.pubkey,
super.key,
});

final UserMetadataEntity? userMetadata;
final String pubkey;

static double get itemHeight => 35.0.s;

@override
Widget build(BuildContext context, WidgetRef ref) {
if (userMetadata == null) {
return ItemLoadingState(itemHeight: itemHeight);
}
final userMetadataResult = ref.watch(userMetadataProvider(pubkey));

final UserMetadataEntity(:masterPubkey, :data) = userMetadata!;

return ListItem.user(
title: Text(data.name),
trailing: FollowUserButton(pubkey: masterPubkey),
subtitle: Text(
prefixUsername(
username: data.displayName,
context: context,
),
),
profilePicture: data.picture,
onTap: () {
Navigator.of(context).pop(masterPubkey);
return userMetadataResult.maybeWhen(
data: (userMetadata) {
if (userMetadata == null) {
return const SizedBox.shrink();
}
return ListItem.user(
title: Text(userMetadata.data.name),
trailing: FollowUserButton(pubkey: pubkey),
subtitle: Text(
prefixUsername(
username: userMetadata.data.displayName,
context: context,
),
),
profilePicture: userMetadata.data.picture,
onTap: () {
Navigator.of(context).pop(userMetadata.masterPubkey);
},
);
},
orElse: () => ItemLoadingState(itemHeight: itemHeight),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import 'package:ion/app/components/screen_offset/screen_side_offset.dart';
import 'package:ion/app/components/scroll_view/load_more_builder.dart';
import 'package:ion/app/extensions/extensions.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:ion/app/features/user/model/follow_type.dart';
import 'package:ion/app/features/user/model/user_metadata.c.dart';
import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal/components/follow_app_bar.dart';
import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal/components/follow_list_item.dart';
import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal/components/follow_list_loading.dart';
Expand All @@ -35,7 +33,9 @@ class FollowersList extends ConsumerWidget {
SliverList.separated(
separatorBuilder: (_, __) => SizedBox(height: 16.0.s),
itemCount: entities.length,
itemBuilder: (context, index) => _ListItem(pubkey: entities[index].masterPubkey),
itemBuilder: (context, index) => ScreenSideOffset.small(
child: FollowListItem(pubkey: entities[index].masterPubkey),
),
)
else
const FollowListLoading(),
Expand All @@ -50,23 +50,3 @@ class FollowersList extends ConsumerWidget {
);
}
}

class _ListItem extends ConsumerWidget {
const _ListItem({required this.pubkey});

final String pubkey;

@override
Widget build(BuildContext context, WidgetRef ref) {
final userMetadata = ref.watch(
nostrCacheProvider.select(
cacheSelector<UserMetadataEntity>(
UserMetadataEntity.cacheKeyBuilder(pubkey: pubkey),
),
),
);
return ScreenSideOffset.small(
child: FollowListItem(userMetadata: userMetadata),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal
import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal/components/follow_list_loading.dart';
import 'package:ion/app/features/user/pages/profile_page/pages/follow_list_modal/components/follow_search_bar.dart';
import 'package:ion/app/features/user/providers/follow_list_provider.c.dart';
import 'package:ion/app/features/user/providers/user_metadata_provider.c.dart';

class FollowingList extends ConsumerWidget {
const FollowingList({required this.pubkey, super.key});
Expand All @@ -31,7 +30,9 @@ class FollowingList extends ConsumerWidget {
SliverList.separated(
separatorBuilder: (_, __) => SizedBox(height: 16.0.s),
itemCount: pubkeys.length,
itemBuilder: (context, index) => _ListItem(pubkey: pubkeys[index]),
itemBuilder: (context, index) => ScreenSideOffset.small(
child: FollowListItem(pubkey: pubkeys[index]),
),
)
else
const FollowListLoading(),
Expand All @@ -40,17 +41,3 @@ class FollowingList extends ConsumerWidget {
);
}
}

class _ListItem extends ConsumerWidget {
const _ListItem({required this.pubkey});

final String pubkey;

@override
Widget build(BuildContext context, WidgetRef ref) {
final userMetadata = ref.watch(userMetadataProvider(pubkey)).valueOrNull;
return ScreenSideOffset.small(
child: FollowListItem(userMetadata: userMetadata),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ List<EntitiesDataSource>? followersDataSource(Ref ref, String pubkey) {
return [
EntitiesDataSource(
actionSource: ActionSourceUser(pubkey),
entityFilter: (entity) => entity is FollowListEntity,
entityFilter: (entity) => entity is UserMetadataEntity,
requestFilters: [
RequestFilter(
kinds: const [FollowListEntity.kind],
Expand Down

0 comments on commit 20ca372

Please sign in to comment.