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-4994: Prompt Users to Create a Snapshot #1517

Merged
merged 35 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
72192f6
feat(prompt to snapshot): WIP PE-4994
matibat Dec 11, 2023
def0599
feat(prompt to snapshot): dialog PE-4994
matibat Dec 12, 2023
68efc81
feat(prompt to snapshot): removes hard-coded value PE-4994
matibat Dec 12, 2023
53339b3
feat(prompt to snapshot): removes unnecessary logs PE-4994
matibat Dec 12, 2023
7a824ef
feat(prompt to snapshot): makes the bloc testable PE-4994
matibat Dec 12, 2023
f1d8ce4
test(prompt to snapshot): unit tests for the bloc PE-4994
matibat Dec 12, 2023
e13fcf8
feat(prompt to snapshot): dont remind me again modal PE-4994
matibat Dec 12, 2023
21b6980
test(prompt to snapshot): adds test case PE-4994
matibat Dec 12, 2023
37a9646
feat(prompt to snapshot): wordings PE-4994
matibat Dec 12, 2023
0cf2625
feat(prompt to snapshot): cleans the dontremindmeagain flag on logout…
matibat Dec 12, 2023
99c1c53
chore(prompt to snapshot): removes unnecessary comment Pe4994
matibat Dec 13, 2023
bf3500f
feat(prompt to snapshot): do not prompt while sync is running PE-4994
matibat Dec 14, 2023
9665ecf
chore(drive detail page): removes unnecessary comment PE-4994
matibat Dec 14, 2023
23e2a71
feat(prompt to snapshot): logging PE-4994
matibat Dec 14, 2023
e8735b7
Merge remote-tracking branch 'origin/dev' into PE-4994
matibat Dec 14, 2023
211622e
Merge remote-tracking branch 'origin/PE-4994' into PE-4994
matibat Dec 14, 2023
c17b849
feat(prompt to snapshot bloc): uses a map for holding the TXs count P…
matibat Jan 8, 2024
6aa4a5e
Merge remote-tracking branch 'origin/dev' into PE-4994
matibat Jan 9, 2024
2f6bd6f
feat(prompt to snapshot): corrects wrong import PE-4994
matibat Jan 9, 2024
d5f058e
feat(prompt to snapshot): makes dontRemindMeAgain be in a per-wallet …
matibat Jan 10, 2024
17d651b
test(prompt to snapshot): updates unit tests PE-4994
matibat Jan 10, 2024
41fb9ca
chore(drive detail page): removes uused variable PE-4994
matibat Jan 10, 2024
78164ba
Merge remote-tracking branch 'origin/dev' into PE-4994
matibat Jan 10, 2024
9708365
test(debouncer): implements unit tests PE-4994
matibat Jan 10, 2024
8569554
chore(prompt to snapshot dialog): reverts unnecessary change PE-4994
matibat Jan 10, 2024
cf3fd77
feat(prompt to snapshot bloc): makes it check permissions by itself i…
matibat Jan 11, 2024
497bc0f
test(prompt to snapshot): updates unit test PE-5254
matibat Jan 11, 2024
06e68c1
feat(prompt to snapshot): don-t prompt while snapshotting PE-4994
matibat Jan 11, 2024
f49bd81
test(prompt to snapshot): unit tests snapshotting state PE-4994
matibat Jan 11, 2024
ccbef66
chore(cleanup): nit PE-4994
matibat Jan 11, 2024
bb67b10
fix(prompt snapshot)
thiagocarvalhodev Jan 19, 2024
be4d8e8
Merge pull request #1565 from ardriveapp/PE-5457-modal-doesnt-reappea…
thiagocarvalhodev Jan 19, 2024
a55382e
Merge branch 'dev' into PE-4994
karlprieb Jan 22, 2024
290e008
Merge branch 'dev' into PE-4994
thiagocarvalhodev Jan 23, 2024
e643868
Update main.dart
thiagocarvalhodev Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions lib/app_shell.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_bloc.dart';
import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_event.dart';
import 'package:ardrive/components/profile_card.dart';
import 'package:ardrive/components/side_bar.dart';
import 'package:ardrive/gift/reedem_button.dart';
import 'package:ardrive/models/daos/drive_dao/drive_dao.dart';
import 'package:ardrive/pages/drive_detail/components/hover_widget.dart';
import 'package:ardrive/utils/logger.dart';
import 'package:ardrive/utils/size_constants.dart';
Expand Down Expand Up @@ -60,9 +63,38 @@ class AppShellState extends State<AppShell> {

@override
Widget build(BuildContext context) => BlocBuilder<DrivesCubit, DrivesState>(
builder: (context, _) {
builder: (context, drivesState) {
Widget buildPage(scaffold) => Material(
child: BlocBuilder<SyncCubit, SyncState>(
child: BlocConsumer<SyncCubit, SyncState>(
listener: (context, syncState) async {
if (drivesState is DrivesLoadSuccess) {
if (syncState is! SyncInProgress) {
final profileState = context.read<ProfileCubit>().state;

final promptToSnapshotBloc =
context.read<PromptToSnapshotBloc>();
final driveDao = context.read<DriveDao>();
final selectedDriveId = drivesState.selectedDriveId;

final selectedDrive = selectedDriveId == null
? null
: await driveDao
.driveById(driveId: selectedDriveId)
.getSingleOrNull();

final hasWritePermissions =
profileState is ProfileLoggedIn &&
selectedDrive?.ownerAddress ==
profileState.walletAddress;

if (hasWritePermissions) {
promptToSnapshotBloc.add(SelectedDrive(
driveId: drivesState.selectedDriveId,
));
}
}
}
},
builder: (context, syncState) => syncState is SyncInProgress
? Stack(
children: [
Expand Down
98 changes: 83 additions & 15 deletions lib/blocs/drives/drives_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import 'dart:async';

import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_bloc.dart';
import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_event.dart';
import 'package:ardrive/core/activity_tracker.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/utils/user_utils.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:collection/collection.dart';
import 'package:drift/drift.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -17,6 +20,7 @@ part 'drives_state.dart';
/// It works even if the user profile is unavailable.
class DrivesCubit extends Cubit<DrivesState> {
final ProfileCubit _profileCubit;
final PromptToSnapshotBloc _promptToSnapshotBloc;
final DriveDao _driveDao;
final ArDriveAuth _auth;

Expand All @@ -26,9 +30,11 @@ class DrivesCubit extends Cubit<DrivesState> {
required ArDriveAuth auth,
this.initialSelectedDriveId,
required ProfileCubit profileCubit,
required PromptToSnapshotBloc promptToSnapshotBloc,
required DriveDao driveDao,
required ActivityTracker activityTracker,
}) : _profileCubit = profileCubit,
_promptToSnapshotBloc = promptToSnapshotBloc,
_driveDao = driveDao,
_auth = auth,
super(DrivesLoadInProgress()) {
Expand All @@ -52,7 +58,7 @@ class DrivesCubit extends Cubit<DrivesState> {
).listen((drives) async {
final state = this.state;

final profile = _profileCubit.state;
final profileState = _profileCubit.state;

String? selectedDriveId;

Expand All @@ -64,22 +70,34 @@ class DrivesCubit extends Cubit<DrivesState> {
}

final walletAddress =
profile is ProfileLoggedIn ? profile.walletAddress : null;
profileState is ProfileLoggedIn ? profileState.walletAddress : null;

final ghostFolders = await _driveDao.ghostFolders().get();

final sharedDrives =
drives.where((d) => !isDriveOwner(auth, d.ownerAddress)).toList();

final userDrives = drives
.where((d) => profileState is ProfileLoggedIn
? d.ownerAddress == walletAddress
: false)
.toList();

final selectedDrive =
drives.firstWhereOrNull((d) => d.id == selectedDriveId);

final hasWritePermission = profileState is ProfileLoggedIn &&
selectedDrive?.ownerAddress == profileState.walletAddress;

if (hasWritePermission) {
_promptToSnapshotBloc.add(SelectedDrive(driveId: selectedDriveId));
}
karlprieb marked this conversation as resolved.
Show resolved Hide resolved

emit(
DrivesLoadSuccess(
selectedDriveId: selectedDriveId,
// If the user is not logged in, all drives are considered shared ones.
userDrives: drives
.where((d) => profile is ProfileLoggedIn
? d.ownerAddress == walletAddress
: false)
.toList(),
userDrives: userDrives,
sharedDrives: sharedDrives,
drivesWithAlerts: ghostFolders.map((e) => e.driveId).toList(),
canCreateNewDrive: _profileCubit.state is ProfileLoggedIn,
Expand All @@ -89,16 +107,43 @@ class DrivesCubit extends Cubit<DrivesState> {
}

void selectDrive(String driveId) {
final canCreateNewDrive = _profileCubit.state is ProfileLoggedIn;
final state = this.state is DrivesLoadSuccess
? (this.state as DrivesLoadSuccess).copyWith(selectedDriveId: driveId)
: DrivesLoadedWithNoDrivesFound(canCreateNewDrive: canCreateNewDrive);
final profileIsLoggedIn = _profileCubit.state is ProfileLoggedIn;
final canCreateNewDrive = profileIsLoggedIn;
final DrivesState state;
if (this.state is DrivesLoadSuccess) {
state = (this.state as DrivesLoadSuccess).copyWith(
selectedDriveId: driveId,
);

matibat marked this conversation as resolved.
Show resolved Hide resolved
if (profileIsLoggedIn) {
final profileStateAsLoggedIn = _profileCubit.state as ProfileLoggedIn;

_driveDao
.driveById(driveId: driveId)
.getSingleOrNull()
.then((maybeDrive) {
final hasWritePermission =
maybeDrive?.ownerAddress == profileStateAsLoggedIn.walletAddress;

if (hasWritePermission) {
_promptToSnapshotBloc.add(SelectedDrive(driveId: driveId));
}
});
}
} else {
state = DrivesLoadedWithNoDrivesFound(
canCreateNewDrive: canCreateNewDrive,
);
_promptToSnapshotBloc.add(const SelectedDrive(driveId: null));
}
emit(state);
}

void cleanDrives() {
initialSelectedDriveId = null;

_promptToSnapshotBloc.add(const SelectedDrive(driveId: null));

final state = DrivesLoadSuccess(
selectedDriveId: null,
userDrives: const [],
Expand All @@ -110,21 +155,44 @@ class DrivesCubit extends Cubit<DrivesState> {
}

void _resetDriveSelection(DriveID detachedDriveId) {
final canCreateNewDrive = _profileCubit.state is ProfileLoggedIn;
final profileIsLoggedIn = _profileCubit.state is ProfileLoggedIn;
final canCreateNewDrive = profileIsLoggedIn;
if (state is DrivesLoadSuccess) {
final state = this.state as DrivesLoadSuccess;
state.userDrives.removeWhere((drive) => drive.id == detachedDriveId);
state.sharedDrives.removeWhere((drive) => drive.id == detachedDriveId);
final firstOrNullDrive = state.userDrives.isNotEmpty
final firstOrNullDriveId = state.userDrives.isNotEmpty
? state.userDrives.first.id
: state.sharedDrives.isNotEmpty
? state.sharedDrives.first.id
: null;
if (firstOrNullDrive != null) {
emit(state.copyWith(selectedDriveId: firstOrNullDrive));
if (firstOrNullDriveId != null) {
if (profileIsLoggedIn && state.selectedDriveId != null) {
final profileStateAsLoggedIn = _profileCubit.state as ProfileLoggedIn;

_driveDao
.driveById(driveId: firstOrNullDriveId)
.getSingleOrNull()
.then((maybeDrive) {
final hasWritePermission = maybeDrive?.ownerAddress ==
profileStateAsLoggedIn.walletAddress;

if (hasWritePermission) {
_promptToSnapshotBloc.add(SelectedDrive(
driveId: firstOrNullDriveId,
));
} else {
_promptToSnapshotBloc.add(const SelectedDrive(driveId: null));
}
});
}

emit(state.copyWith(selectedDriveId: firstOrNullDriveId));
return;
}
}

_promptToSnapshotBloc.add(const SelectedDrive(driveId: null));
emit(DrivesLoadedWithNoDrivesFound(canCreateNewDrive: canCreateNewDrive));
}

Expand Down
1 change: 0 additions & 1 deletion lib/blocs/feedback_survey/feedback_survey_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FeedbackSurveyCubit extends Cubit<FeedbackSurveyState> {

FeedbackSurveyCubit(
FeedbackSurveyState initialState, {

/// takes a KeyValueStore for testing purposes
KeyValueStore? store,
}) : super(initialState) {
Expand Down
Loading
Loading