[mob][photos] Refactor add participant page (#5940)

This commit is contained in:
Aman Raj Singh Mourya
2025-05-16 17:49:02 +05:30
committed by GitHub
4 changed files with 69 additions and 72 deletions

View File

@@ -18,18 +18,26 @@ import 'package:photos/ui/components/models/button_type.dart';
import "package:photos/ui/notification/toast.dart";
import 'package:photos/ui/sharing/user_avator_widget.dart';
import "package:photos/ui/sharing/verify_identity_dialog.dart";
import "package:photos/utils/separators_util.dart";
enum ActionTypesToShow {
addViewer,
addCollaborator,
}
class AddParticipantPage extends StatefulWidget {
final bool isAddingViewer;
/// Cannot be empty
final List<ActionTypesToShow> actionTypesToShow;
final List<Collection> collections;
const AddParticipantPage(
AddParticipantPage(
this.collections,
this.isAddingViewer, {
this.actionTypesToShow, {
super.key,
});
bool get isToMultipleCollections => collections.length > 1;
}) : assert(
actionTypesToShow.isNotEmpty,
'actionTypesToShow cannot be empty',
);
@override
State<StatefulWidget> createState() => _AddParticipantPage();
@@ -78,11 +86,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
resizeToAvoidBottomInset: isKeypadOpen,
appBar: AppBar(
title: Text(
widget.isToMultipleCollections
? S.of(context).addParticipants
: widget.isAddingViewer
? S.of(context).addViewer
: S.of(context).addCollaborator,
_getTitle(),
),
),
body: Column(
@@ -132,13 +136,15 @@ class _AddParticipantPage extends State<AddParticipantPage> {
.longPressAnEmailToVerifyEndToEndEncryption,
)
: const SizedBox.shrink(),
widget.isAddingViewer
? const SizedBox.shrink()
: MenuSectionDescriptionWidget(
widget.actionTypesToShow.contains(
ActionTypesToShow.addCollaborator,
)
? MenuSectionDescriptionWidget(
content: S
.of(context)
.collaboratorsCanAddPhotosAndVideosToTheSharedAlbum,
),
)
: const SizedBox.shrink(),
],
),
);
@@ -224,9 +230,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 8),
widget.isToMultipleCollections
? _multipleActionButton()
: _singleActionButton(),
..._actionButtons(),
const SizedBox(height: 12),
],
),
@@ -237,53 +241,10 @@ class _AddParticipantPage extends State<AddParticipantPage> {
);
}
Widget _singleActionButton() {
return ButtonWidget(
buttonType: ButtonType.primary,
buttonSize: ButtonSize.large,
labelText: widget.isAddingViewer
? S.of(context).addViewers(_selectedEmails.length)
: S.of(context).addCollaborators(_selectedEmails.length),
isDisabled: _selectedEmails.isEmpty,
onTap: () async {
final results = <bool>[];
final collections = widget.collections;
for (String email in _selectedEmails) {
for (Collection collection in collections) {
results.add(
await collectionActions.addEmailToCollection(
context,
collection,
email,
widget.isAddingViewer
? CollectionParticipantRole.viewer
: CollectionParticipantRole.collaborator,
),
);
}
}
final noOfSuccessfullAdds = results.where((e) => e).length;
showToast(
context,
widget.isAddingViewer
? S.of(context).viewersSuccessfullyAdded(noOfSuccessfullAdds)
: S.of(context).collaboratorsSuccessfullyAdded(
noOfSuccessfullAdds,
),
);
if (!results.any((e) => e == false) && mounted) {
Navigator.of(context).pop(true);
}
},
);
}
Widget _multipleActionButton() {
return Column(
children: [
List<Widget> _actionButtons() {
final widgets = <Widget>[];
if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {
widgets.add(
ButtonWidget(
buttonType: ButtonType.primary,
buttonSize: ButtonSize.large,
@@ -317,9 +278,17 @@ class _AddParticipantPage extends State<AddParticipantPage> {
}
},
),
const SizedBox(height: 8),
);
}
if (widget.actionTypesToShow.contains(
ActionTypesToShow.addCollaborator,
)) {
widgets.add(
ButtonWidget(
buttonType: ButtonType.neutral,
buttonType:
widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)
? ButtonType.neutral
: ButtonType.primary,
buttonSize: ButtonSize.large,
labelText: S.of(context).addCollaborators(_selectedEmails.length),
isDisabled: _selectedEmails.isEmpty,
@@ -351,8 +320,15 @@ class _AddParticipantPage extends State<AddParticipantPage> {
}
},
),
],
);
}
final widgetsWithSpaceBetween = addSeparators(
widgets,
const SizedBox(
height: 8,
),
);
return widgetsWithSpaceBetween;
}
void clearFocus() {
@@ -479,4 +455,14 @@ class _AddParticipantPage extends State<AddParticipantPage> {
return suggestedUsers;
}
String _getTitle() {
if (widget.actionTypesToShow.length > 1) {
return S.of(context).addParticipants;
} else if (widget.actionTypesToShow.first == ActionTypesToShow.addViewer) {
return S.of(context).addViewer;
} else {
return S.of(context).addCollaborator;
}
}
}

View File

@@ -54,7 +54,12 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {
Future<void> _navigateToAddUser(bool addingViewer) async {
await routeToPage(
context,
AddParticipantPage([widget.collection], addingViewer),
AddParticipantPage(
[widget.collection],
addingViewer
? [ActionTypesToShow.addViewer]
: [ActionTypesToShow.addCollaborator],
),
);
if (mounted) {
setState(() => {});

View File

@@ -92,7 +92,10 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
// ignore: unawaited_futures
routeToPage(
context,
AddParticipantPage([widget.collection], true),
AddParticipantPage(
[widget.collection],
const [ActionTypesToShow.addViewer],
),
).then(
(value) => {
if (mounted) {setState(() => {})},
@@ -120,7 +123,10 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
// ignore: unawaited_futures
routeToPage(
context,
AddParticipantPage([widget.collection], false),
AddParticipantPage(
[widget.collection],
const [ActionTypesToShow.addCollaborator],
),
).then(
(value) => {
if (mounted) {setState(() => {})},

View File

@@ -162,7 +162,7 @@ class _AlbumSelectionActionWidgetState
context,
AddParticipantPage(
widget.selectedAlbums.albums.toList(),
false,
const [ActionTypesToShow.addViewer, ActionTypesToShow.addCollaborator],
),
);
widget.selectedAlbums.clearAll();