forked from Nexus/nexus
added subprofile search
This commit is contained in:
parent
7435ecd5f0
commit
d5f04122eb
1 changed files with 105 additions and 38 deletions
|
|
@ -2,12 +2,11 @@ import "package:flutter_hooks/flutter_hooks.dart";
|
|||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/controllers/account_data.dart";
|
||||
import "package:nexus/controllers/subprofiles.dart";
|
||||
import "package:nexus/controllers/settings.dart";
|
||||
import "package:nexus/main.dart";
|
||||
import "package:nexus/models/room_subprofiles.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/composer/subprofile_picker.dart";
|
||||
|
||||
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are
|
||||
/// on. It shows the one the text in [controller] would trigger, if any.
|
||||
|
|
@ -32,29 +31,7 @@ class const SubprofileButton(
|
|||
if (!enabled || profiles.isEmpty) return const SizedBox.shrink();
|
||||
final shown = triggered ?? current;
|
||||
|
||||
Future<void> choose(String profileId) => ref
|
||||
.read(AccountDataController.provider.notifier)
|
||||
.setRoomProfile(roomId, profileId)
|
||||
.onError(showError);
|
||||
|
||||
PopupMenuItem<void> item({
|
||||
required String id,
|
||||
required Widget leading,
|
||||
required String title,
|
||||
}) {
|
||||
final selected = (current?.id ?? "") == id;
|
||||
return PopupMenuItem(
|
||||
onTap: () => choose(id),
|
||||
child: ListTile(
|
||||
selected: selected,
|
||||
leading: leading,
|
||||
title: Text(title),
|
||||
trailing: selected ? Icon(Icons.check) : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AdaptiveMenuButton<void>(
|
||||
return IconButton(
|
||||
tooltip: switch ((triggered, current)) {
|
||||
(final triggered?, _) =>
|
||||
"Sending this message as ${triggered.displayName ?? triggered.id}",
|
||||
|
|
@ -69,19 +46,8 @@ class const SubprofileButton(
|
|||
),
|
||||
null => Icon(Icons.person),
|
||||
},
|
||||
itemBuilder: (_) => [
|
||||
item(id: "", leading: Icon(Icons.person), title: "Account Profile"),
|
||||
...profiles.map(
|
||||
(profile) => item(
|
||||
id: profile.id,
|
||||
leading: AvatarOrHash(
|
||||
profile.avatarUrl,
|
||||
profile.displayName ?? profile.id,
|
||||
),
|
||||
title: profile.displayName ?? profile.id,
|
||||
),
|
||||
),
|
||||
],
|
||||
onPressed: () =>
|
||||
context.showAdaptivePopover((_) => SubprofilePicker(roomId)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue