Skip to content

Commit

Permalink
Merge pull request #1530 from ardriveapp/PE-5254
Browse files Browse the repository at this point in the history
PE-5254: Hackathon - Hide feature
  • Loading branch information
thiagocarvalhodev authored Jan 31, 2024
2 parents c9162c0 + ced0778 commit 3d7daa8
Show file tree
Hide file tree
Showing 68 changed files with 3,150 additions and 1,581 deletions.
11 changes: 2 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
},
"bloc.newBlocTemplate": "equatable",
"bloc.newCubitTemplate": "equatable",
"dart.additionalAnalyzerFileExtensions": [
"drift"
],
"cSpell.words": [
"Hkdf",
"hmac",
"sublist",
"Widgetbook"
]
"dart.additionalAnalyzerFileExtensions": ["drift"],
"cSpell.words": ["Hkdf", "hmac", "sublist", "Widgetbook"]
}
22 changes: 13 additions & 9 deletions lib/blocs/create_manifest/create_manifest_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,19 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {
Future<void> loadFolder(String folderId) async {
await _selectedFolderSubscription?.cancel();

_selectedFolderSubscription =
_driveDao.watchFolderContents(drive.id, folderId: folderId).listen(
(f) => emit(
CreateManifestFolderLoadSuccess(
viewingRootFolder: f.folder.parentFolderId == null,
viewingFolder: f,
),
),
);
_selectedFolderSubscription = _driveDao
.watchFolderContents(
drive.id,
folderId: folderId,
)
.listen(
(f) => emit(
CreateManifestFolderLoadSuccess(
viewingRootFolder: f.folder.parentFolderId == null,
viewingFolder: f,
),
),
);
}

/// User selected a new name due to name conflict, confirm that form is valid and check for conflicts again
Expand Down
49 changes: 35 additions & 14 deletions lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {

bool _refreshSelectedItem = false;

bool _showHiddenFiles = false;

DriveDetailCubit({
required this.driveId,
String? initialFolderId,
Expand Down Expand Up @@ -74,6 +76,12 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
}
}

void toggleHiddenFiles() {
_showHiddenFiles = !_showHiddenFiles;

refreshDriveDataTable();
}

void openFolder({
required String path,
DriveOrder contentOrderBy = DriveOrder.name,
Expand Down Expand Up @@ -148,8 +156,10 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
);

if (index >= 0) {
final item = folderContents.files[index];

_selectedItem = DriveDataTableItemMapper.toFileDataTableItem(
folderContents.files[index],
item,
_selectedItem!.index,
_selectedItem!.isOwner,
);
Expand All @@ -159,8 +169,10 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
(element) => element.id == _selectedItem!.id,
);
if (index >= 0) {
final item = folderContents.subfolders[index];

_selectedItem = DriveDataTableItemMapper.fromFolderEntry(
folderContents.subfolders[index],
item,
_selectedItem!.index,
_selectedItem!.isOwner,
);
Expand All @@ -173,8 +185,6 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
_selectedItem!.isOwner,
);
}

_refreshSelectedItem = false;
}

final currentFolderContents = parseEntitiesToDatatableItem(
Expand All @@ -195,6 +205,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
rowsPerPage: availableRowsPerPage.first,
availableRowsPerPage: availableRowsPerPage,
currentFolderContents: currentFolderContents,
isShowingHiddenFiles: _showHiddenFiles,
),
);
} else {
Expand All @@ -212,6 +223,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
driveIsEmpty: rootFolderNode.isEmpty(),
multiselect: false,
currentFolderContents: currentFolderContents,
isShowingHiddenFiles: _showHiddenFiles,
),
);
}
Expand Down Expand Up @@ -400,8 +412,11 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {

if (state is DriveDetailLoadSuccess) {
await Future.delayed(const Duration(milliseconds: 100));
emit((state as DriveDetailLoadSuccess)
.copyWith(forceRebuildKey: UniqueKey()));
final state = this.state as DriveDetailLoadSuccess;
emit(state.copyWith(
forceRebuildKey: UniqueKey(),
isShowingHiddenFiles: _showHiddenFiles,
));
}
}

Expand Down Expand Up @@ -444,14 +459,20 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
}

final state = this.state as DriveDetailLoadSuccess;
final allImagesForFolder = state.currentFolderContents
.whereType<FileDataTableItem>()
.where(
(element) => supportedImageTypesInFilePreview.contains(
element.contentType,
),
)
.toList();

final isShowingHiddenFiles = state.isShowingHiddenFiles;

final List<FileDataTableItem> allImagesForFolder =
state.currentFolderContents.whereType<FileDataTableItem>().where(
(element) {
final supportedImageType = supportedImageTypesInFilePreview.contains(
element.contentType,
);

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

_allImagesOfCurrentFolder = allImagesForFolder;

Expand Down
11 changes: 10 additions & 1 deletion lib/blocs/drive_detail/drive_detail_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DriveDetailLoadSuccess extends DriveDetailState {

final Key? forceRebuildKey;

final bool isShowingHiddenFiles;

DriveDetailLoadSuccess({
required this.currentDrive,
required this.hasWritePermissions,
Expand All @@ -51,9 +53,10 @@ class DriveDetailLoadSuccess extends DriveDetailState {
this.hasFoldersSelected = false,
this.selectedFilePreviewUrl,
required this.driveIsEmpty,
this.selectedItem,
required this.selectedItem,
required this.currentFolderContents,
this.forceRebuildKey,
required this.isShowingHiddenFiles,
});

DriveDetailLoadSuccess copyWith({
Expand All @@ -73,6 +76,7 @@ class DriveDetailLoadSuccess extends DriveDetailState {
ArDriveDataTableItem? selectedItem,
List<ArDriveDataTableItem>? currentFolderContents,
Key? forceRebuildKey,
bool? isShowingHiddenFiles,
}) =>
DriveDetailLoadSuccess(
forceRebuildKey: forceRebuildKey ?? this.forceRebuildKey,
Expand All @@ -94,12 +98,16 @@ class DriveDetailLoadSuccess extends DriveDetailState {
driveIsEmpty: driveIsEmpty ?? this.driveIsEmpty,
currentFolderContents:
currentFolderContents ?? this.currentFolderContents,
isShowingHiddenFiles: isShowingHiddenFiles ?? this.isShowingHiddenFiles,
);

@override
List<Object?> get props => [
currentDrive,
hasWritePermissions,
folderInView,
currentFolderContents,
isShowingHiddenFiles,
contentOrderBy,
contentOrderingMode,
showSelectedItemDetails,
Expand All @@ -111,6 +119,7 @@ class DriveDetailLoadSuccess extends DriveDetailState {
driveIsEmpty,
multiselect,
forceRebuildKey,
selectedItem,
];
SelectedItem? maybeSelectedItem() =>
selectedItems.isNotEmpty ? selectedItems.first : null;
Expand Down
32 changes: 27 additions & 5 deletions lib/blocs/fs_entry_move/fs_entry_move_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FsEntryMoveBloc extends Bloc<FsEntryMoveEvent, FsEntryMoveState> {
final ProfileCubit _profileCubit;
final SyncCubit _syncCubit;
final ArDriveCrypto _crypto;
final DriveDetailCubit _driveDetailCubit;

FsEntryMoveBloc({
required this.driveId,
Expand All @@ -38,11 +39,13 @@ class FsEntryMoveBloc extends Bloc<FsEntryMoveEvent, FsEntryMoveState> {
required ProfileCubit profileCubit,
required SyncCubit syncCubit,
required ArDriveCrypto crypto,
required DriveDetailCubit driveDetailCubit,
Platform platform = const LocalPlatform(),
}) : _arweave = arweave,
_turboUploadService = turboUploadService,
_driveDao = driveDao,
_profileCubit = profileCubit,
_driveDetailCubit = driveDetailCubit,
_syncCubit = syncCubit,
_crypto = crypto,
super(const FsEntryMoveLoadInProgress()) {
Expand Down Expand Up @@ -133,8 +136,10 @@ class FsEntryMoveBloc extends Bloc<FsEntryMoveEvent, FsEntryMoveState> {
required String folderId,
required Emitter<FsEntryMoveState> emit,
}) async {
final folderStream =
_driveDao.watchFolderContents(driveId, folderId: folderId);
final folderStream = _driveDao.watchFolderContents(
driveId,
folderId: folderId,
);
await emit.forEach(
folderStream,
onData: (FolderWithContents folderWithContents) => FsEntryMoveLoadSuccess(
Expand Down Expand Up @@ -176,21 +181,38 @@ class FsEntryMoveBloc extends Bloc<FsEntryMoveEvent, FsEntryMoveState> {
}) async {
final driveKey = await _driveDao.getDriveKey(driveId, profile.cipherKey);
final moveTxDataItems = <DataItem>[];
final isShowingHiddenItems =
(_driveDetailCubit.state as DriveDetailLoadSuccess)
.isShowingHiddenFiles;
final files = selectedItems.whereType<FileDataTableItem>().toList();

if (!isShowingHiddenItems) {
files.removeWhere((element) => element.isHidden);
}

final filesToMove = selectedItems
.whereType<FileDataTableItem>()
final filesToMove = files
.where((file) => conflictingItems
.where((conflictingFile) => conflictingFile.id == file.id)
.isEmpty)
.toList();

final foldersToMove = selectedItems
files.clear();

final folders = selectedItems.whereType<FolderDataTableItem>().toList();

if (!isShowingHiddenItems) {
folders.removeWhere((element) => element.isHidden);
}

final foldersToMove = folders
.whereType<FolderDataTableItem>()
.where((folder) => conflictingItems
.where((conflictingFolder) => conflictingFolder.id == folder.id)
.isEmpty)
.toList();

folders.clear();

final folderMap = <String, FolderEntriesCompanion>{};

await _driveDao.transaction(() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FsEntryRenameCubit extends Cubit<FsEntryRenameState> {
bool updateExtension = false,
}) async {
try {
late bool hasEntityWithSameName;
final bool hasEntityWithSameName;

if (_isRenamingFolder) {
hasEntityWithSameName = await _folderWithSameNameExists(newName);
Expand Down
6 changes: 5 additions & 1 deletion lib/blocs/ghost_fixer/ghost_fixer_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class GhostFixerCubit extends Cubit<GhostFixerState> {
await _selectedFolderSubscription?.cancel();

_selectedFolderSubscription = _driveDao
.watchFolderContents(ghostFolder.driveId, folderId: folderId)
.watchFolderContents(
ghostFolder.driveId,
folderId: folderId,
)
.listen(
(f) => emit(
GhostFixerFolderLoadSuccess(
Expand Down Expand Up @@ -129,6 +132,7 @@ class GhostFixerCubit extends Cubit<GhostFixerState> {
isGhost: false,
lastUpdated: ghostFolder.lastUpdated,
dateCreated: ghostFolder.dateCreated,
isHidden: ghostFolder.isHidden,
);

final folderEntity = folder.asEntity();
Expand Down
Loading

0 comments on commit 3d7daa8

Please sign in to comment.