Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-4597: adds a description of the selected drive privacy #1366

Merged
merged 8 commits into from
Sep 21, 2023
23 changes: 18 additions & 5 deletions lib/blocs/drive_create/drive_create_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart'
show DrivePrivacy;
import 'package:ardrive/entities/constants.dart' as constants;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of the class that holds on it the static strings, and use instead the enums?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are implementing the constants for tags, entity types, and more in a couple of new packages: arfs and ardrive_utils that we will release on the large uploads initiative.

import 'package:ardrive/entities/drive_entity.dart';
import 'package:ardrive/entities/folder_entity.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
Expand All @@ -15,7 +19,9 @@ part 'drive_create_state.dart';
class DriveCreateCubit extends Cubit<DriveCreateState> {
final form = FormGroup({
'privacy': FormControl<String>(
value: DrivePrivacy.private, validators: [Validators.required]),
value: DrivePrivacy.private.name,
validators: [Validators.required],
),
});

final ArweaveService _arweave;
Expand All @@ -35,7 +41,14 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
_driveDao = driveDao,
_profileCubit = profileCubit,
_drivesCubit = drivesCubit,
super(DriveCreateInitial());
super(DriveCreateInitial(privacy: DrivePrivacy.private));

void onPrivacyChanged() {
final privacy = form.control('privacy').value == DrivePrivacy.private.name
? DrivePrivacy.private
: DrivePrivacy.public;
emit((state as DriveCreateInitial).copyWith(privacy: privacy));
}

Future<void> submit(
String driveName,
Expand Down Expand Up @@ -72,8 +85,8 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
name: driveName,
rootFolderId: createRes.rootFolderId,
privacy: drivePrivacy,
authMode: drivePrivacy == DrivePrivacy.private
? DriveAuthMode.password
authMode: drivePrivacy == constants.DrivePrivacy.private
? constants.DriveAuthMode.password
: null,
);

Expand Down
13 changes: 12 additions & 1 deletion lib/blocs/drive_create/drive_create_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ abstract class DriveCreateState extends Equatable {
List<Object> get props => [];
}

class DriveCreateInitial extends DriveCreateState {}
class DriveCreateInitial extends DriveCreateState {
final DrivePrivacy privacy;

DriveCreateInitial({required this.privacy});

DriveCreateInitial copyWith({DrivePrivacy? privacy}) {
return DriveCreateInitial(privacy: privacy ?? this.privacy);
}

@override
List<Object> get props => [privacy];
}

class DriveCreateZeroBalance extends DriveCreateState {}

Expand Down
29 changes: 26 additions & 3 deletions lib/components/drive_create_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/l11n/l11n.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/congestion_warning_wrapper.dart';
Expand Down Expand Up @@ -73,6 +74,9 @@ class _DriveCreateFormState extends State<DriveCreateForm> {
],
);
} else {
final stateAsInitial = state as DriveCreateInitial;
final privacy = stateAsInitial.privacy;

return ArDriveStandardModal(
title: appLocalizationsOf(context).createDriveEmphasized,
content: SizedBox(
Expand Down Expand Up @@ -108,24 +112,43 @@ class _DriveCreateFormState extends State<DriveCreateForm> {
ReactiveDropdownField(
formControlName: 'privacy',
decoration: InputDecoration(
labelText: appLocalizationsOf(context).privacy),
labelText: appLocalizationsOf(context).privacy,
),
showErrors: (control) =>
control.dirty && control.invalid,
validationMessages:
kValidationMessages(appLocalizationsOf(context)),
items: [
DropdownMenuItem(
value: 'public',
value: DrivePrivacy.public.name,
child: Text(appLocalizationsOf(context).public),
),
DropdownMenuItem(
value: 'private',
value: DrivePrivacy.private.name,
child: Text(
appLocalizationsOf(context).private,
),
)
],
onChanged: (_) {
context.read<DriveCreateCubit>().onPrivacyChanged();
},
),
const SizedBox(height: 32),
Row(children: [
if (privacy == DrivePrivacy.private)
Flexible(
child: Text(
appLocalizationsOf(context)
.drivePrivacyDescriptionPrivate,
))
else
Flexible(
child: Text(
appLocalizationsOf(context)
.drivePrivacyDescriptionPublic,
))
]),
],
),
),
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@
"@driveName": {
"description": "The name of certain drive"
},
"drivePrivacyDescriptionPrivate": "Private Drives offer state-of-the-art security, you control access.",
"@drivePrivacyDescriptionPrivate": {
"description": "Explains private drives."
},
"drivePrivacyDescriptionPublic": "Public Drives are discoverable, others can find and view the contents.",
"@drivePrivacyDescriptionPublic": {
"description": "Explains public drives."
},
"driveRoot": "Drive root",
"@driveRoot": {
"description": "The folder entity that is at the top of the folder hierarchy"
Expand Down