Skip to content

Commit

Permalink
fix hide icon and attach drives
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Oct 22, 2024
1 parent 630ca0c commit 7dae599
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 15 additions & 17 deletions lib/blocs/drives/drives_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ 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/logger.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 Down Expand Up @@ -72,27 +70,27 @@ class DrivesCubit extends Cubit<DrivesState> {

String? selectedDriveId;

if (state is DrivesLoadSuccess && state.selectedDriveId != null) {
if (state is DrivesLoadSuccess) {
selectedDriveId = state.selectedDriveId;
} else {
final userPreferences = await _userPreferencesRepository.load();
}

final userHasHiddenDrive = drives.any((d) => d.isHidden);
logger.d('User has hidden drive: $userHasHiddenDrive');
if (selectedDriveId == null) {
if (initialSelectedDriveId != null &&
initialSelectedDriveId!.isNotEmpty) {
selectedDriveId = initialSelectedDriveId;
} else {
final userPreferences = await _userPreferencesRepository.load();

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

if (userPreferences.lastSelectedDriveId != null) {
final lastSelectedDriveId = userPreferences.lastSelectedDriveId;
selectedDriveId = userPreferences.lastSelectedDriveId;

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

Expand Down
2 changes: 2 additions & 0 deletions lib/blocs/hide/global_hide_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class GlobalHideBloc extends Bloc<GlobalHideEvent, GlobalHideState> {
}
});

_userPreferencesRepository.load();

on<GlobalHideEvent>((event, emit) async {
if (event is ShowItems) {
emit(ShowingHiddenItems(userHasHiddenDrive: event.userHasHiddenItems));
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
shell = const LoginPage(gettingStarted: true);
} else if (state is ProfileLoggedIn ||
anonymouslyShowDriveDetail) {
driveId = driveId ?? rootPath;
driveId = driveId ?? rootPath;

shell = BlocListener<DrivesCubit, DrivesState>(
listener: (context, state) {
Expand Down

0 comments on commit 7dae599

Please sign in to comment.