Skip to content

Commit

Permalink
Merge pull request #1555 from atsign-foundation/duplicate-profile
Browse files Browse the repository at this point in the history
feat(npt_flutter): add profile duplicate button
  • Loading branch information
CurtlyCritchlow authored Nov 19, 2024
2 parents 0b87633 + 6438a35 commit 9194af3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class ProfileBloc extends LoggingBloc<ProfileEvent, ProfileState> {
profile = null;
}

if (event.copyFrom != null) {
var json = event.copyFrom!.toJson();
json["uuid"] = uuid;
profile = Profile.fromJson(json);
}

if (profile == null) {
emit(ProfileLoaded(
uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class ProfileLoadEvent extends ProfileEvent {
}

final class ProfileLoadOrCreateEvent extends ProfileEvent {
const ProfileLoadOrCreateEvent();
final Profile? copyFrom;
const ProfileLoadOrCreateEvent({this.copyFrom});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/features/profile/profile.dart';
import 'package:npt_flutter/pages/profile_form_page.dart';
import 'package:npt_flutter/features/profile_list/bloc/profile_list_bloc.dart';
import 'package:npt_flutter/styles/sizes.dart';
import 'package:npt_flutter/widgets/custom_snack_bar.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

import '../../../routes.dart';
import '../../../util/export.dart';
import '../../../util/uuid.dart';
import '../../../widgets/confirmation_dialog.dart';
import '../../../widgets/multi_select_dialog.dart';

Expand Down Expand Up @@ -41,10 +43,28 @@ class ProfilePopupMenuButton extends StatelessWidget {
}

if (context.mounted) {
Navigator.of(context).pushNamed(Routes.profileForm, arguments: state.profile.uuid);
Navigator.of(context)
.pushNamed(Routes.profileForm, arguments: ProfileFormPageArguments(state.profile.uuid));
}
},
),
PopupMenuItem(
child: Row(
children: [
PhosphorIcon(PhosphorIcons.copy()),
gapW10,
const Text("Duplicate"), // TODO: localizations
],
),
onTap: () {
var state = context.read<ProfileBloc>().state;
if (state is! ProfileLoadedState) return;
var copyFrom = state.profile;
if (context.mounted) {
Navigator.of(context).pushNamed(Routes.profileForm,
arguments: ProfileFormPageArguments(Uuid.generate(), copyFrom: copyFrom));
}
}),
PopupMenuItem(
child: Row(
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'package:npt_flutter/widgets/custom_card.dart';

class ProfileFormView extends StatelessWidget {
final String uuid;
const ProfileFormView(this.uuid, {super.key});
final Profile? copyFrom;
const ProfileFormView(this.uuid, {super.key, this.copyFrom});

@override
Widget build(BuildContext context) {
Expand All @@ -19,7 +20,7 @@ class ProfileFormView extends StatelessWidget {
create: (BuildContext context) =>

/// Local copy of the profile which is used by the form
ProfileBloc(context.read<ProfileRepository>(), uuid)..add(const ProfileLoadOrCreateEvent()),
ProfileBloc(context.read<ProfileRepository>(), uuid)..add(ProfileLoadOrCreateEvent(copyFrom: copyFrom)),
child: Padding(
padding: const EdgeInsets.only(left: Sizes.p100, right: Sizes.p100),
child: Stack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/routes.dart';
import 'package:npt_flutter/pages/profile_form_page.dart';
import 'package:npt_flutter/styles/sizes.dart';
import 'package:npt_flutter/util/uuid.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';
Expand All @@ -25,7 +26,7 @@ class ProfileListAddButton extends StatelessWidget {
onPressed: () {
final uuid = Uuid.generate();
if (context.mounted) {
Navigator.of(context).pushNamed(Routes.profileForm, arguments: uuid);
Navigator.of(context).pushNamed(Routes.profileForm, arguments: ProfileFormPageArguments(uuid));
}
},
label: Text(strings.addNew),
Expand Down
11 changes: 9 additions & 2 deletions packages/dart/npt_flutter/lib/pages/profile_form_page.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/features/profile_form/profile_form.dart';
import 'package:npt_flutter/features/profile/models/profile.dart';
import 'package:npt_flutter/widgets/npt_app_bar.dart';

class ProfileFormPageArguments {
final String uuid;
final Profile? copyFrom;
ProfileFormPageArguments(this.uuid, {this.copyFrom});
}

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

@override
Widget build(BuildContext context) {
final uuid = ModalRoute.of(context)!.settings.arguments as String;
final args = ModalRoute.of(context)!.settings.arguments as ProfileFormPageArguments;
final strings = AppLocalizations.of(context)!;
return Scaffold(
appBar: NptAppBar(title: strings.addNewProfile),
body: ProfileFormView(uuid),
body: ProfileFormView(args.uuid, copyFrom: args.copyFrom),
);
}
}
2 changes: 1 addition & 1 deletion packages/dart/npt_flutter/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
6 changes: 3 additions & 3 deletions packages/dart/npt_flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ packages:
path: "../noports_core"
relative: true
source: path
version: "6.2.0"
version: "6.2.1"
openssh_ed25519:
dependency: transitive
description:
Expand Down Expand Up @@ -1317,10 +1317,10 @@ packages:
dependency: "direct main"
description:
name: socket_connector
sha256: "3c641546699aa58e9ab8be9841627a30af3c1ffcf4461ca5d00d7c56392ab63a"
sha256: "091c83fb214f6ff48dbf38f6e011e148d996cce05487303c5e8a0cd72369b0e2"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.3.3"
source_gen:
dependency: transitive
description:
Expand Down

0 comments on commit 9194af3

Please sign in to comment.