Skip to content

Commit

Permalink
fix: mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
Arenukvern committed Dec 1, 2023
1 parent 7734bb6 commit 4285109
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/idea/create_idea_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class _CreateIdeaProjectScreenState extends State<CreateIdeaProjectScreen> {
onFieldSubmitted: (final _) => onCreate(),
controller: _textController,
maxLength: 90,
maxLines: null,
style: context.textTheme.displaySmall?.copyWith(
color: textColor,
),
Expand Down
5 changes: 3 additions & 2 deletions packages/core/lib/src/data_sources/mutations/mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ enum LocalDbVersion {
static const newestVersion = v3_17;
}

Future<void> runMutations(final GlobalStatesInitializerDto dto) async {
Future<bool> runMutations(final GlobalStatesInitializerDto dto) async {
final userNotifier = dto.userNotifier;
if (userNotifier.isLoading) {
throw ArgumentError.value('user is not loaded yet');
}

final currentLocalDbVersion = userNotifier.value.value.localDbVersion;
if (currentLocalDbVersion == LocalDbVersion.newestVersion) return;
if (currentLocalDbVersion == LocalDbVersion.newestVersion) return false;
try {
await ComplexLocalDbHiveImpl().open();
for (final v in LocalDbVersion.values) {
Expand All @@ -37,6 +37,7 @@ Future<void> runMutations(final GlobalStatesInitializerDto dto) async {
}

userNotifier.updateLocalDbVersion(LocalDbVersion.newestVersion);
return true;
}

Future<void> _mutate_3_16_up_3_17(final GlobalStatesInitializerDto dto) async {
Expand Down
13 changes: 9 additions & 4 deletions packages/core/lib/src/state/user_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ class UserInitializer {
UserInitializer({required this.dto});
final GlobalStatesInitializerDto dto;
Future<void> onUserLoad() async {
await runMutations(dto);

/// not wait for this since it has its own loader
unawaited(_onDelayedLoad());
final isAnyMigrationsExecuted = await runMutations(dto);
if (isAnyMigrationsExecuted) {
/// not wait for this since it has its own loader
unawaited(_onDelayedLoad());
} else {
unawaited(dto.projectsNotifier.onLoad());
}
}

Future<void> _onDelayedLoad() async {
/// refreshing data, just to make sure all is loaded
await Future.delayed(const Duration(seconds: 1));
dto.projectsNotifier.onReset();
await dto.projectsNotifier.onLoad();
}

Expand Down

0 comments on commit 4285109

Please sign in to comment.