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-6752: hide drives #1892

Merged
merged 25 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
71ac336
hide drives + important fixes
thiagocarvalhodev Oct 10, 2024
3a902ac
fix tests
thiagocarvalhodev Oct 14, 2024
e868e51
Update side_bar.dart
thiagocarvalhodev Oct 15, 2024
a92d7a4
manifest preview and download
thiagocarvalhodev Oct 17, 2024
04ea46d
always show shared drives
thiagocarvalhodev Oct 21, 2024
4d44634
chore: remove commented code and prints
thiagocarvalhodev Oct 21, 2024
307d9c1
test(user prefs/hide)
thiagocarvalhodev Oct 22, 2024
630ca0c
fix(user prefs)
thiagocarvalhodev Oct 22, 2024
7dae599
fix hide icon and attach drives
thiagocarvalhodev Oct 22, 2024
fdcd613
Update hide_dialog.dart
thiagocarvalhodev Oct 22, 2024
d3f0cb6
Update drive_explorer_item_tile.dart
thiagocarvalhodev Oct 22, 2024
e5105a0
Update sync_repository.dart
thiagocarvalhodev Oct 22, 2024
9f8b2f0
remove feedback survey modal
thiagocarvalhodev Oct 22, 2024
87ebc4e
fix sync drives with hidden property
thiagocarvalhodev Oct 22, 2024
3b52208
clear all configs when logging out
thiagocarvalhodev Oct 22, 2024
abb5275
Update global_hide_bloc_test.dart
thiagocarvalhodev Oct 22, 2024
d84d6d9
Update user_preferences_repository_test.dart
thiagocarvalhodev Oct 22, 2024
48b6946
refactors(hide drive)
thiagocarvalhodev Oct 22, 2024
b0c7bf4
refactor(hide)
thiagocarvalhodev Oct 22, 2024
836bc7a
Update hide_bloc.dart
thiagocarvalhodev Oct 22, 2024
77ce82e
Update hide_bloc.dart
thiagocarvalhodev Oct 22, 2024
45a6f84
Update app_router_delegate.dart
thiagocarvalhodev Oct 22, 2024
14373a0
fix: missing hide button
thiagocarvalhodev Oct 28, 2024
8acbf55
fix(attach drives): dont ask for attach a drive logging the user out
thiagocarvalhodev Oct 28, 2024
9f47a53
Merge pull request #1904 from ardriveapp/PE-7037-missing-hide-show-hi…
thiagocarvalhodev Oct 28, 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
17 changes: 10 additions & 7 deletions lib/app_shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class AppShellState extends State<AppShell> {
}
}
},
builder: (context, syncState) => syncState is SyncInProgress
? Stack(
builder: (context, syncState) {
return Stack(children: [
scaffold,
if (syncState is SyncInProgress)
Stack(
children: [
AbsorbPointer(
child: scaffold,
),
SizedBox.expand(
child: Container(
color: Colors.black.withOpacity(0.5),
Expand Down Expand Up @@ -181,8 +181,9 @@ class AppShellState extends State<AppShell> {
),
),
],
)
: scaffold,
),
]);
},
),
);
return ScreenTypeLayout.builder(
Expand Down Expand Up @@ -367,6 +368,8 @@ class MobileAppBar extends StatelessWidget implements PreferredSizeWidget {
),
),
const Spacer(),
const GlobalHideToggleButton(),
const SizedBox(width: 8),
const SyncButton(),
const SizedBox(
width: 24,
Expand Down
4 changes: 2 additions & 2 deletions lib/authentication/ardrive_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ class ArDriveAuthImpl implements ArDriveAuth {
await _secureKeyValueStore.remove('biometricEnabled');
currentUser = null;
await _disconnectFromArConnect();
_userStreamController.add(null);
}

await _userRepository.deleteUser();
await _databaseHelpers.deleteAllTables();
await (await _metadataCache).clear();
(await _metadataCache).clear();
_userStreamController.add(null);
} catch (e, stacktrace) {
logger.e('Failed to logout user', e, stacktrace);
throw AuthenticationFailedException('Failed to logout user');
Expand Down
82 changes: 54 additions & 28 deletions lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'package:rxdart/rxdart.dart';
part 'drive_detail_state.dart';

class DriveDetailCubit extends Cubit<DriveDetailState> {
final String driveId;
String _driveId;
final ProfileCubit _profileCubit;
final DriveDao _driveDao;
final ConfigService _configService;
Expand All @@ -49,10 +49,8 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {

bool _refreshSelectedItem = false;

bool _showHiddenFiles = false;

DriveDetailCubit({
required this.driveId,
required String driveId,
String? initialFolderId,
required ProfileCubit profileCubit,
required DriveDao driveDao,
Expand All @@ -70,6 +68,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
_breadcrumbBuilder = breadcrumbBuilder,
_syncCubit = syncCubit,
_driveRepository = driveRepository,
_driveId = driveId,
super(DriveDetailLoadInProgress()) {
if (driveId.isEmpty) {
return;
Expand All @@ -95,26 +94,38 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
}
}

void toggleHiddenFiles() {
_showHiddenFiles = !_showHiddenFiles;
void showEmptyDriveDetail() async {
await _syncCubit.waitCurrentSync();

emit(DriveDetailLoadEmpty());
}

Future<void> changeDrive(String driveId) async {
final drive = await _driveDao.driveById(driveId: driveId).getSingleOrNull();

if (drive == null) {
return;
}

_driveId = driveId;

refreshDriveDataTable();
openFolder(folderId: drive.rootFolderId);
}

void openFolder({
Future<void> openFolder({
String? folderId,
String? otherDriveId,
String? selectedItemId,
DriveOrder contentOrderBy = DriveOrder.name,
OrderingMode contentOrderingMode = OrderingMode.asc,
}) async {
/// always wait for the current sync to finish before opening a new folder
await _syncCubit.waitCurrentSync();

try {
_selectedItem = null;
_allImagesOfCurrentFolder = null;

String driveId = otherDriveId ?? this.driveId;
String driveId = otherDriveId ?? _driveId;

emit(DriveDetailLoadInProgress());

Expand All @@ -131,6 +142,10 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
),
_profileCubit.stream.startWith(ProfileCheckingAvailability()),
(drive, folderContents, _) async {
if (isClosed) {
return;
}

await _syncCubit.waitCurrentSync();

if (drive == null) {
Expand Down Expand Up @@ -195,6 +210,12 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
isOwner: isDriveOwner(_auth, drive.ownerAddress),
);

if (selectedItemId != null) {
_selectedItem = currentFolderContents.firstWhere(
(element) => element.id == selectedItemId,
);
}

final List<BreadCrumbRowInfo> pathSegments =
await _breadcrumbBuilder.buildForFolder(
folderId: folderContents.folder.id,
Expand All @@ -215,10 +236,10 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
rowsPerPage: availableRowsPerPage.first,
availableRowsPerPage: availableRowsPerPage,
currentFolderContents: currentFolderContents,
isShowingHiddenFiles: _showHiddenFiles,
pathSegments: pathSegments,
driveIsEmpty: folderContents.files.isEmpty &&
folderContents.subfolders.isEmpty,
showSelectedItemDetails: _selectedItem != null,
),
);
} else {
Expand All @@ -241,7 +262,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
multiselect: false,
currentFolderContents: currentFolderContents,
columnVisibility: columnsVisibility,
isShowingHiddenFiles: _showHiddenFiles,
showSelectedItemDetails: _selectedItem != null,
),
);
}
Expand Down Expand Up @@ -447,53 +468,58 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
final state = this.state as DriveDetailLoadSuccess;
emit(state.copyWith(
forceRebuildKey: UniqueKey(),
isShowingHiddenFiles: _showHiddenFiles,
));
}
}

bool canNavigateThroughImages() {
final numberOfImages = getAllImagesOfCurrentFolder().length;
bool canNavigateThroughImages(bool showHiddenImages) {
final numberOfImages = getAllImagesOfCurrentFolder(showHiddenImages).length;
return numberOfImages > 1;
}

Future<void> selectNextImage() => _selectImageRelativeToCurrent(1);
Future<void> selectPreviousImage() => _selectImageRelativeToCurrent(-1);
Future<void> selectNextImage(bool showHiddenImages) =>
_selectImageRelativeToCurrent(1, showHiddenImages);
Future<void> selectPreviousImage(bool showHiddenImages) =>
_selectImageRelativeToCurrent(-1, showHiddenImages);

Future<void> _selectImageRelativeToCurrent(int offset) async {
final currentIndex = getIndexForImage(_selectedItem as FileDataTableItem);
Future<void> _selectImageRelativeToCurrent(
int offset, bool showHiddenImages) async {
final currentIndex = getIndexForImage(
_selectedItem as FileDataTableItem,
showHiddenImages,
);
final nextIndex = currentIndex + offset;
final nextImage = getImageForIndex(nextIndex);
final nextImage = getImageForIndex(nextIndex, showHiddenImages);

await selectDataItem(nextImage);
}

FileDataTableItem getImageForIndex(int index) {
final allImagesOfCurrentFolder = getAllImagesOfCurrentFolder();
FileDataTableItem getImageForIndex(int index, bool showHiddenImages) {
final allImagesOfCurrentFolder =
getAllImagesOfCurrentFolder(showHiddenImages);
final cyclicIndex = index % allImagesOfCurrentFolder.length;
final image = allImagesOfCurrentFolder[cyclicIndex];

return image;
}

int getIndexForImage(FileDataTableItem image) {
final allImagesOfCurrentFolder = getAllImagesOfCurrentFolder();
int getIndexForImage(FileDataTableItem image, bool showHiddenImages) {
final allImagesOfCurrentFolder =
getAllImagesOfCurrentFolder(showHiddenImages);
final index = allImagesOfCurrentFolder.indexWhere(
(element) => element.id == image.id,
);

return index;
}

List<FileDataTableItem> getAllImagesOfCurrentFolder() {
List<FileDataTableItem> getAllImagesOfCurrentFolder(bool showHiddenImages) {
if (_allImagesOfCurrentFolder != null) {
return _allImagesOfCurrentFolder!;
}

final state = this.state as DriveDetailLoadSuccess;

final isShowingHiddenFiles = state.isShowingHiddenFiles;

final List<FileDataTableItem> allImagesForFolder =
state.currentFolderContents.whereType<FileDataTableItem>().where(
(element) {
Expand All @@ -502,7 +528,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
);

return supportedImageType &&
(isShowingHiddenFiles ? true : !element.isHidden);
(showHiddenImages ? true : !element.isHidden);
},
).toList();

Expand Down
8 changes: 2 additions & 6 deletions lib/blocs/drive_detail/drive_detail_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
final Map<int, bool> columnVisibility;
final Key? forceRebuildKey;

final bool isShowingHiddenFiles;

DriveDetailLoadSuccess({
required this.currentDrive,
required this.hasWritePermissions,
Expand All @@ -61,7 +59,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
required this.currentFolderContents,
required this.columnVisibility,
this.forceRebuildKey,
required this.isShowingHiddenFiles,
required this.pathSegments,
this.selectedPage,
});
Expand All @@ -83,7 +80,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
ArDriveDataTableItem? selectedItem,
List<ArDriveDataTableItem>? currentFolderContents,
Key? forceRebuildKey,
bool? isShowingHiddenFiles,
List<BreadCrumbRowInfo>? pathSegments,
int? selectedPage,
}) =>
Expand All @@ -109,7 +105,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
driveIsEmpty: driveIsEmpty ?? this.driveIsEmpty,
currentFolderContents:
currentFolderContents ?? this.currentFolderContents,
isShowingHiddenFiles: isShowingHiddenFiles ?? this.isShowingHiddenFiles,
pathSegments: pathSegments ?? this.pathSegments,
);

Expand All @@ -119,7 +114,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
hasWritePermissions,
folderInView,
currentFolderContents,
isShowingHiddenFiles,
contentOrderBy,
contentOrderingMode,
showSelectedItemDetails,
Expand All @@ -144,4 +138,6 @@ class DriveDetailLoadSuccess extends DriveDetailState {
/// the user's profile.
class DriveDetailLoadNotFound extends DriveDetailState {}

class DriveDetailLoadEmpty extends DriveDetailState {}

class DriveInitialLoading extends DriveDetailState {}
31 changes: 27 additions & 4 deletions lib/blocs/drives/drives_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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/user/repositories/user_preferences_repository.dart';
import 'package:ardrive/utils/user_utils.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:drift/drift.dart';
Expand All @@ -22,6 +23,7 @@ class DrivesCubit extends Cubit<DrivesState> {
final PromptToSnapshotBloc _promptToSnapshotBloc;
final DriveDao _driveDao;
final ArDriveAuth _auth;
final UserPreferencesRepository _userPreferencesRepository;

late StreamSubscription _drivesSubscription;
String? initialSelectedDriveId;
Expand All @@ -32,10 +34,12 @@ class DrivesCubit extends Cubit<DrivesState> {
required PromptToSnapshotBloc promptToSnapshotBloc,
required DriveDao driveDao,
required ActivityTracker activityTracker,
required UserPreferencesRepository userPreferencesRepository,
}) : _profileCubit = profileCubit,
_promptToSnapshotBloc = promptToSnapshotBloc,
_driveDao = driveDao,
_auth = auth,
_userPreferencesRepository = userPreferencesRepository,
super(DrivesLoadInProgress()) {
_auth.onAuthStateChanged().listen((user) {
if (user == null) {
Expand Down Expand Up @@ -66,11 +70,28 @@ class DrivesCubit extends Cubit<DrivesState> {

String? selectedDriveId;

if (state is DrivesLoadSuccess && state.selectedDriveId != null) {
if (state is DrivesLoadSuccess) {
selectedDriveId = state.selectedDriveId;
} else {
selectedDriveId = initialSelectedDriveId ??
(drives.isNotEmpty ? drives.first.id : null);
}

if (selectedDriveId == null) {
if (initialSelectedDriveId != null &&
initialSelectedDriveId!.isNotEmpty) {
selectedDriveId = initialSelectedDriveId;
} else {
final userPreferences = await _userPreferencesRepository.load();

final userHasHiddenDrive = drives.any((d) => d.isHidden);
await _userPreferencesRepository
.saveUserHasHiddenItem(userHasHiddenDrive);

selectedDriveId = userPreferences.lastSelectedDriveId;

if (selectedDriveId == null ||
!drives.any((d) => d.id == selectedDriveId)) {
selectedDriveId = drives.isNotEmpty ? drives.first.id : null;
}
}
}

final walletAddress = profileState is ProfileLoggedIn
Expand Down Expand Up @@ -118,6 +139,8 @@ class DrivesCubit extends Cubit<DrivesState> {
);
_promptToSnapshotBloc.add(const SelectedDrive(driveId: null));
}

_userPreferencesRepository.saveLastSelectedDriveId(driveId);
emit(state);
}

Expand Down
Loading
Loading