Skip to content

Commit

Permalink
fix: merge dev fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jun 16, 2024
1 parent 1299c23 commit 437c0d9
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 104 deletions.
3 changes: 1 addition & 2 deletions designer_v2/lib/features/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:studyu_designer_v2/constants.dart';
import 'package:studyu_designer_v2/localization/app_translation.dart';
import 'package:studyu_designer_v2/localization/locale_providers.dart';
import 'package:studyu_designer_v2/localization/string_hardcoded.dart';
import 'package:studyu_designer_v2/routing/router.dart';
import 'package:studyu_designer_v2/services/notification_dispatcher.dart';
import 'package:studyu_designer_v2/theme.dart';

import '../localization/locale_providers.dart';

final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey();

/// Entry widget of the app.
Expand Down
16 changes: 9 additions & 7 deletions designer_v2/lib/features/app_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:studyu_designer_v2/constants.dart';
import 'package:studyu_designer_v2/features/app_controller_state.dart';
import 'package:studyu_designer_v2/repositories/auth_repository.dart';

Expand All @@ -12,8 +13,6 @@ abstract class IAppDelegate {
Future<bool> onAppStart();
}

typedef _DelegateCallback = Future<bool> Function(IAppDelegate delegate);

/// Main controller that's bound to the top-level application widget's state
@riverpod
class AppController extends _$AppController {
Expand All @@ -26,10 +25,12 @@ class AppController extends _$AppController {
ref.listenSelf((previous, next) {
print("APP CONTROLLER STATE CHANGED: $next");
});
//ref.read(routerProvider).refresh();
// Forward onAppStart to all registered delegates so that they can
// e.g. read some data from local storage for initialization
//await _callDelegates((delegate) => delegate.onAppStart(), withMinDelay: true);
await _callDelegates(
(delegate) => delegate.onAppStart(),
withMinDelay: true,
);
return const AppControllerState(status: AppStatus.initialized);
}

Expand All @@ -38,12 +39,13 @@ class AppController extends _$AppController {

/// A dummy [Future] used for setting a lower bound on app initialization
/// (so that the splash screen is shown during this time)
// TODO MERGE
late final _delayedFuture = Future.delayed(
const Duration(milliseconds: Config.minSplashTime), () => true);
// ignore: avoid_redundant_argument_values, use_named_constants
const Duration(milliseconds: Config.minSplashTime),
() => true,
);

/// Executes the given callback for all registered delegates concurrently
// TODO merge where to call this?
Future<bool> _callDelegates(
Future<bool> Function(IAppDelegate) function, {
bool withMinDelay = false,
Expand Down
2 changes: 1 addition & 1 deletion designer_v2/lib/features/app_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion designer_v2/lib/features/app_controller_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AppControllerState extends Equatable {

final AppStatus status;

get isInitialized => status == AppStatus.initialized;
bool get isInitialized => status == AppStatus.initialized;

@override
List<Object?> get props => [status];
Expand Down
11 changes: 4 additions & 7 deletions designer_v2/lib/features/auth/auth_form_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:reactive_forms/reactive_forms.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand Down Expand Up @@ -57,25 +56,23 @@ enum AuthFormKey {
class AuthFormController extends _$AuthFormController
implements IFormGroupController {
@override
AsyncValue<void> build(AuthFormKey formKey) {
AsyncValue<void> build(AuthFormKey formKeyArg) {
authRepository = ref.watch(authRepositoryProvider);
notificationService = ref.watch(notificationServiceProvider);
router = ref.watch(routerProvider);

formKey = formKey;
formKey = formKeyArg;
resetControlsFor(formKey);

ref.listenSelf((previous, next) {
print("authFormController.state updated");
if (state.hasError) {
final AuthException error = state.error as AuthException;
final AuthException error = state.error! as AuthException;
switch (error.message) {
case "Invalid login credentials":
notificationService.show(Notifications.credentialsInvalid);
break;
case "User already registered":
notificationService.show(Notifications.userAlreadyRegistered);
break;
default:
notificationService.showMessage(error.message);
}
Expand All @@ -88,7 +85,7 @@ class AuthFormController extends _$AuthFormController
_readDebugUser();
_onChangeFormKey(formKey);

return AsyncValue.data(null);
return const AsyncValue.data(null);
}

late final IAuthRepository authRepository;
Expand Down
40 changes: 21 additions & 19 deletions designer_v2/lib/features/auth/auth_form_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions designer_v2/lib/features/dashboard/dashboard_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:studyu_core/core.dart';
Expand All @@ -18,8 +17,6 @@ import 'package:studyu_designer_v2/routing/router.dart';
import 'package:studyu_designer_v2/routing/router_intent.dart';
import 'package:studyu_designer_v2/utils/model_action.dart';

import 'dashboard_state.dart';

part 'dashboard_controller.g.dart';

@riverpod
Expand Down Expand Up @@ -58,19 +55,19 @@ class DashboardController extends _$DashboardController

final SearchController searchController = SearchController();

_subscribeStudies() {
void _subscribeStudies() {
_studiesSubscription = studyRepository.watchAll().listen((wrappedModels) {
print("studyRepository.update");
// Update the controller's state when new studies are available in the repository
final studies = wrappedModels.map((study) => study.model).toList();
state = state.copyWith(
studies: () => AsyncValue.data(studies),
);
}, onError: (error) {
}, onError: (Object error) {
state = state.copyWith(
studies: () => AsyncValue.error(error, StackTrace.current),
);
});
},);
}

void setSearchText(String? text) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion designer_v2/lib/features/design/study_form_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class StudyFormViewModel extends FormViewModel<Study>
/// before the [StudyController]'s [Study] is available (see also: [AsyncValue])
@riverpod
StudyFormViewModel studyFormViewModel(
StudyFormViewModelRef ref, StudyID studyId) {
StudyFormViewModelRef ref, StudyID studyId,) {
print("studyFormViewModel");
final state = ref.watch(studyControllerProvider(studyId));
return StudyFormViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class InviteCodeFormViewModel extends FormViewModel<StudyInvite> {
/// before the [StudyController]'s [Study] is available (see also: [AsyncValue])
@riverpod
InviteCodeFormViewModel inviteCodeFormViewModel(
InviteCodeFormViewModelRef ref, StudyID studyId) {
InviteCodeFormViewModelRef ref, StudyID studyId,) {
print("inviteCodeFormViewModelProvider($studyId");
// Reactively bind to and obtain [StudyController]'s current study
final study = ref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class StudyRecruitController extends _$StudyRecruitController
router: ref.watch(routerProvider),
currentUser: ref.watch(authRepositoryProvider).currentUser,
inviteCodeRepository: ref.watch(inviteCodeRepositoryProvider(studyId)),
invites: const AsyncValue.loading(),
);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions designer_v2/lib/features/study/study_base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:studyu_designer_v2/repositories/model_repository.dart';
import 'package:studyu_designer_v2/repositories/study_repository.dart';
import 'package:studyu_designer_v2/routing/router.dart';
import 'package:studyu_designer_v2/routing/router_intent.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

part 'study_base_controller.g.dart';

Expand All @@ -28,12 +27,6 @@ class StudyBaseController<T extends StudyControllerBaseState>
);
}

// TODO MERGE
/*final StudyID studyId;
final IStudyRepository studyRepository;
final User? currentUser;
final GoRouter router;*/

StreamSubscription<WrappedModel<Study>>? studySubscription;

void subscribeStudy(StudyID studyId) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 437c0d9

Please sign in to comment.