Skip to content

Commit

Permalink
Merge pull request #1543 from ardriveapp/PE-5309
Browse files Browse the repository at this point in the history
PE-5309: Add hide icon to Details panel
  • Loading branch information
matibat authored Jan 5, 2024
2 parents 076b424 + 0e4f36c commit 570879e
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 130 deletions.
1 change: 1 addition & 0 deletions lib/blocs/drive_create/drive_create_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
id: drive.rootFolderId,
driveId: drive.id,
name: driveName,
isHidden: false,
);

final rootFolderDataItem = await _arweave.prepareEntityDataItem(
Expand Down
28 changes: 10 additions & 18 deletions lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {

bool _forceDisableMultiselect = false;

bool _refreshSelectedItem = false;
final bool _refreshSelectedItem = true;

bool _showHiddenFiles = false;

Expand Down Expand Up @@ -159,8 +159,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 @@ -170,8 +172,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 @@ -184,8 +188,6 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
_selectedItem!.isOwner,
);
}

_refreshSelectedItem = false;
}

final currentFolderContents = parseEntitiesToDatatableItem(
Expand Down Expand Up @@ -408,22 +410,12 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
);
}

void refreshDriveDataTable({
bool reComputeFolderContents = false,
}) {
_refreshSelectedItem = true;
void refreshDriveDataTable() {
// _refreshSelectedItem = true;

if (state is DriveDetailLoadSuccess) {
final state = this.state as DriveDetailLoadSuccess;
if (reComputeFolderContents) {
openFolder(
path: state.folderInView.folder.path,
contentOrderBy: state.contentOrderBy,
contentOrderingMode: state.contentOrderingMode,
);
} else {
emit(state.copyWith());
}
emit(state.copyWith());
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/blocs/drive_detail/drive_detail_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DriveDetailLoadSuccess extends DriveDetailState {
this.hasFoldersSelected = false,
this.selectedFilePreviewUrl,
required this.driveIsEmpty,
this.selectedItem,
required this.selectedItem,
required this.currentFolderContents,
required this.isShowingHiddenFiles,
});
Expand Down Expand Up @@ -113,6 +113,7 @@ class DriveDetailLoadSuccess extends DriveDetailState {
_equatableBust,
driveIsEmpty,
multiselect,
selectedItem,
];
SelectedItem? maybeSelectedItem() =>
selectedItems.isNotEmpty ? selectedItems.first : null;
Expand Down
1 change: 1 addition & 0 deletions lib/blocs/folder_create/folder_create_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class FolderCreateCubit extends Cubit<FolderCreateState> {
driveId: targetFolder.driveId,
parentFolderId: targetFolder.id,
name: folderName,
isHidden: false,
);
if (_turboUploadService.useTurboUpload) {
final folderDataItem = await _arweave.prepareEntityDataItem(
Expand Down
20 changes: 20 additions & 0 deletions lib/blocs/hide/hide_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class HideBloc extends Bloc<HideEvent, HideState> {
on<ConfirmUploadEvent>(_onConfirmUploadEvent);
on<SelectUploadMethodEvent>(_onSelectUploadMethodEvent);
on<RefreshTurboBalanceEvent>(_refreshTurboBalance);
on<ErrorEvent>(_onErrorEvent);
}

bool get _useTurboUpload =>
Expand Down Expand Up @@ -318,6 +319,8 @@ class HideBloc extends Bloc<HideEvent, HideState> {
);
final folderEntity = newFolder.asEntity();

logger.d('Unhiding folder with JSON: ${folderEntity.toJson()}');

final driveKey = await _driveDao.getDriveKey(
event.driveId,
profile.cipherKey,
Expand Down Expand Up @@ -418,6 +421,13 @@ class HideBloc extends Bloc<HideEvent, HideState> {
);
}

void _onErrorEvent(
ErrorEvent event,
Emitter<HideState> emit,
) {
emit(FailureHideState(hideAction: event.hideAction));
}

void _computeIsFreeThanksToTurbo() {
final allowedDataItemSizeForTurbo = _appConfig.allowedDataItemSizeForTurbo;
final forceNoFreeThanksToTurbo = _appConfig.forceNoFreeThanksToTurbo;
Expand Down Expand Up @@ -553,4 +563,14 @@ class HideBloc extends Bloc<HideEvent, HideState> {
totalSize: _totalSize,
);
}

@override
void onError(Object error, StackTrace stackTrace) {
add(ErrorEvent(
error: error,
stackTrace: stackTrace,
hideAction: state.hideAction,
));
super.onError(error, stackTrace);
}
}
19 changes: 19 additions & 0 deletions lib/blocs/hide/hide_event.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:ardrive/blocs/hide/hide_state.dart';
import 'package:ardrive/blocs/upload/upload_cubit.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:equatable/equatable.dart';
Expand Down Expand Up @@ -82,3 +83,21 @@ class RefreshTurboBalanceEvent extends HideEvent {
@override
List<Object> get props => [];
}

class ErrorEvent extends HideEvent {
final Object error;
final StackTrace stackTrace;
final HideAction hideAction;

const ErrorEvent({
required this.error,
required this.stackTrace,
required this.hideAction,
});

@override
List<Object> get props => [
error,
stackTrace,
];
}
11 changes: 4 additions & 7 deletions lib/blocs/hide/hide_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UploadingHideState extends HideState {
});

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

class PreparingAndSigningHideState extends HideState {
Expand All @@ -33,7 +33,7 @@ class PreparingAndSigningHideState extends HideState {
});

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

class ConfirmingHideState extends HideState {
Expand Down Expand Up @@ -127,19 +127,16 @@ class SuccessHideState extends HideState {
});

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

class FailureHideState extends HideState {
final String message;

const FailureHideState({
required this.message,
required super.hideAction,
});

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

enum HideAction {
Expand Down
1 change: 1 addition & 0 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ class UploadCubit extends Cubit<UploadState> {
id: metadata.id,
name: metadata.name,
parentFolderId: metadata.parentFolderId,
isHidden: false,
);

if (metadata.metadataTxId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FolderDataItemUploadHandle implements UploadHandle, DataItemHandle {
driveId: targetDriveId,
parentFolderId: folder.parentFolderId,
name: folder.name,
isHidden: false,
).toJson(),
).codeUnits.length;

Expand Down Expand Up @@ -58,6 +59,7 @@ class FolderDataItemUploadHandle implements UploadHandle, DataItemHandle {
driveId: targetDriveId,
parentFolderId: folder.parentFolderId,
name: folder.name,
isHidden: false,
);

folderEntityTx = await arweave.prepareEntityDataItem(
Expand Down
Loading

0 comments on commit 570879e

Please sign in to comment.