Skip to content

Commit

Permalink
feat: shared user picker modal (#517)
Browse files Browse the repository at this point in the history
## Description
This PR introduces a new reusable UserPickerSheet component to
standardize user selection across the app.

## Additional Notes
N/A

## Type of Change
- [x] Bug fix
- [x] New feature
- [ ] Breaking change
- [x] Refactoring
- [ ] Documentation
- [ ] Chore

## Screenshots (if applicable)
<!-- Include screenshots to demonstrate any UI changes. -->
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/ed9985b2-2278-48be-8e44-aa298b7eb7ab">
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/fa1832e0-3f01-449f-9b97-54b79395ec24">
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/9fa1894f-e59b-48c5-8b55-1ad7450bf2f2">
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/35fe96cb-e3bb-4637-b4b3-c307409e23ec">
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/f70eaba0-5c38-4b80-a53e-0000057cb28a">
<img width="180" alt="image"
src="https://github.com/user-attachments/assets/3fec955d-93ad-401f-982b-d80ac1b364b9">
  • Loading branch information
ice-kreios authored Jan 9, 2025
1 parent f140289 commit 6739eac
Show file tree
Hide file tree
Showing 22 changed files with 513 additions and 397 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/chat/providers/messaging_bottom_bar_state_provider.c.dart';
import 'package:ion/app/router/app_routes.c.dart';
import 'package:ion/app/services/logger/logger.dart';
import 'package:ion/generated/assets.gen.dart';

final double moreContentHeight = 206.0.s;
Expand Down Expand Up @@ -48,14 +47,8 @@ class MoreContentView extends ConsumerWidget {
_MoreContentItem(
iconPath: Assets.svg.walletChatPerson,
title: context.i18n.common_profile,
onTap: () async {
final contactId = await ShareProfileModalRoute(
title: context.i18n.chat_profile_share_modal_title,
).push<String>(context);

//TODO: use contactId to share profile
Logger.log(contactId ?? 'No contact selected');

onTap: () {
ShareProfileModalRoute().push<String>(context);
ref.read(messagingBottomBarActiveStateProvider.notifier).setText();
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/components/button/button.dart';
import 'package:ion/app/components/separated/separator.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/auth/providers/content_creators_data_source_provider.c.dart';
import 'package:ion/app/features/chat/model/channel_admin_type.dart';
import 'package:ion/app/features/chat/providers/channel_admins_provider.c.dart';
import 'package:ion/app/features/chat/views/components/selectable_user_list.dart';
import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart';
import 'package:ion/app/features/user/model/user_metadata.c.dart';
import 'package:ion/app/features/user/pages/user_picker_sheet/user_picker_sheet.dart';
import 'package:ion/app/router/components/navigation_app_bar/navigation_app_bar.dart';
import 'package:ion/app/router/components/navigation_app_bar/navigation_close_button.dart';
import 'package:ion/generated/assets.gen.dart';

class AddAdminModal extends HookConsumerWidget {
Expand All @@ -22,73 +22,49 @@ class AddAdminModal extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final searchValue = useState('');
final selectedPubkey = useState<String?>(null);

final dataSource = ref.watch(contentCreatorsDataSourceProvider);
final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource));
final contentCreators = entitiesPagedData?.data.items;

final isLoading = contentCreators?.isEmpty ?? true;
final userEntries = useMemoized(
() => (contentCreators
?.whereType<UserMetadataEntity>()
.where(
(entity) =>
entity.data.displayName
.toLowerCase()
.contains(searchValue.value.toLowerCase()) ||
entity.data.name.toLowerCase().contains(searchValue.value.toLowerCase()),
)
.toList() ??
[])
..sort(
(a, b) => a.data.displayName.toLowerCase().compareTo(b.data.displayName.toLowerCase()),
),
[contentCreators, searchValue.value],
);

return SizedBox(
height: MediaQuery.sizeOf(context).height * 0.8,
child: Column(
children: [
Expanded(
child: SelectableUserList(
title: context.i18n.channel_create_admins_action,
isLoading: isLoading,
selected: [
if (selectedPubkey.value != null) selectedPubkey.value!,
],
userEntries: userEntries,
onSelect: (String value) => selectedPubkey.value = value,
onSearchValueChanged: (String value) => searchValue.value = value,
),
),
const HorizontalSeparator(),
Padding(
padding: EdgeInsets.symmetric(
vertical: 16.0.s,
horizontal: 44.0.s,
),
child: Button(
type: selectedPubkey.value == null ? ButtonType.disabled : ButtonType.primary,
mainAxisSize: MainAxisSize.max,
minimumSize: Size(56.0.s, 56.0.s),
leadingIcon: Assets.svg.iconProfileSave.icon(
color: context.theme.appColors.onPrimaryAccent,
child: UserPickerSheet(
onUserSelected: (UserMetadataEntity user) => selectedPubkey.value = user.masterPubkey,
selectedPubkeys: selectedPubkey.value != null ? [selectedPubkey.value!] : null,
selectable: true,
navigationBar: NavigationAppBar.modal(
title: Text(context.i18n.channel_create_admins_action),
showBackButton: false,
actions: const [
NavigationCloseButton(),
],
),
bottomContent: Column(
children: [
const HorizontalSeparator(),
Padding(
padding: EdgeInsets.symmetric(
vertical: 16.0.s,
horizontal: 44.0.s,
),
label: Text(
context.i18n.button_confirm,
child: Button(
type: selectedPubkey.value == null ? ButtonType.disabled : ButtonType.primary,
mainAxisSize: MainAxisSize.max,
minimumSize: Size(56.0.s, 56.0.s),
leadingIcon: Assets.svg.iconProfileSave.icon(
color: context.theme.appColors.onPrimaryAccent,
),
label: Text(
context.i18n.button_confirm,
),
onPressed: () {
ref
.read(channelAdminsProvider().notifier)
.setAdmin(selectedPubkey.value!, ChannelAdminType.admin);
context.pop();
},
),
onPressed: () {
ref
.read(channelAdminsProvider().notifier)
.setAdmin(selectedPubkey.value!, ChannelAdminType.admin);
context.pop();
},
),
),
],
],
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,50 @@
// SPDX-License-Identifier: ice License 1.0

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:ion/app/components/button/button.dart';
import 'package:ion/app/components/inputs/search_input/search_input.dart';
import 'package:ion/app/components/screen_offset/screen_side_offset.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/chat/components/following_user_list/following_user_list.dart';
import 'package:ion/app/features/chat/components/searched_user_list/searched_user_list.dart';
import 'package:ion/app/features/chat/providers/users_data_source_provider.c.dart';
import 'package:ion/app/features/user/pages/user_picker_sheet/user_picker_sheet.dart';
import 'package:ion/app/router/app_routes.c.dart';
import 'package:ion/app/router/components/navigation_app_bar/navigation_app_bar.dart';
import 'package:ion/app/router/components/navigation_app_bar/navigation_close_button.dart';
import 'package:ion/app/router/components/sheet_content/sheet_content.dart';
import 'package:ion/generated/assets.gen.dart';

class NewChatModal extends HookConsumerWidget {
class NewChatModal extends StatelessWidget {
const NewChatModal({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final searchText = ref.watch(usersSearchTextProvider);

Widget build(BuildContext context) {
return SheetContent(
topPadding: 0,
body: Column(
children: [
NavigationAppBar.modal(
showBackButton: false,
title: Text(context.i18n.new_chat_modal_title),
actions: const [NavigationCloseButton()],
),
SizedBox(height: 9.0.s),
Expanded(
child: ScreenSideOffset.small(
child: Column(
children: [
SearchInput(
textInputAction: TextInputAction.search,
onTextChanged: (text) {
ref.read(usersSearchTextProvider.notifier).text = text;
},
),
SizedBox(height: 12.0.s),
Row(
children: [
_HeaderButton(
icon: Assets.svg.iconSearchGroups,
title: context.i18n.new_chat_modal_new_group_button,
onTap: () {
AddParticipantsToGroupModalRoute().push<void>(context);
},
),
SizedBox(width: 20.0.s),
_HeaderButton(
icon: Assets.svg.iconSearchChannel,
title: context.i18n.new_chat_modal_new_channel_button,
onTap: () {
NewChannelModalRoute().replace(context);
},
),
],
),
SizedBox(height: 12.0.s),
//TODO: update user list when figma design is ready
Expanded(
child:
searchText.isEmpty ? const FollowingUsersList() : const SearchedUsersList(),
),
],
),
body: UserPickerSheet(
navigationBar: NavigationAppBar.modal(
showBackButton: false,
title: Text(context.i18n.new_chat_modal_title),
actions: const [NavigationCloseButton()],
),
initialUserListType: UserListType.follower,
onUserSelected: (_) => context.pop(),
header: Row(
children: [
_HeaderButton(
icon: Assets.svg.iconSearchGroups,
title: context.i18n.new_chat_modal_new_group_button,
onTap: () {
AddParticipantsToGroupModalRoute().push<void>(context);
},
),
),
],
SizedBox(width: 20.0.s),
_HeaderButton(
icon: Assets.svg.iconSearchChannel,
title: context.i18n.new_chat_modal_new_channel_button,
onTap: () {
NewChannelModalRoute().replace(context);
},
),
],
),
),
);
}
Expand Down
Loading

0 comments on commit 6739eac

Please sign in to comment.