Skip to content

Commit

Permalink
fix: reset subject temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Dec 17, 2024
1 parent 975d016 commit ef65f85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 13 additions & 17 deletions app/lib/screens/app_onboarding/preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:studyu_app/models/app_state.dart';
import 'package:studyu_app/routes.dart';
import 'package:studyu_core/core.dart';
import 'package:studyu_core/src/env/env.dart' as env;
import 'package:studyu_flutter_common/studyu_flutter_common.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

Expand Down Expand Up @@ -69,9 +70,6 @@ class Preview {
final List<StudySubject> subjects =
await SupabaseQuery.getAll<StudySubject>();

final List<SubjectProgress> progress =
await SupabaseQuery.getAll<SubjectProgress>();

final List<StudySubject> subjectsToDelete = subjects
.where(
(subject) =>
Expand All @@ -80,24 +78,22 @@ class Preview {
)
.toList();

final List<SubjectProgress> progressToDelete = progress
.where(
(prog) =>
prog.subjectId ==
Supabase.instance.client.auth.currentUser!.id,
)
.toList();
print("Subjects to delete: ${subjectsToDelete.length}");

for (final subject in subjectsToDelete) {
await subject.delete();
}

for (final prog in progressToDelete) {
await prog.delete();
// todo refactor
await env.client
.from(SubjectProgress.tableName)
.delete()
.eq('subject_id', subject.id);
await env.client
.from(StudySubject.tableName)
.delete()
.eq('id', subject.id);
}

deleteActiveStudyReference();
selectedStudyObjectId = '';
selectedStudyObjectId = null;
}
}
}
Expand Down Expand Up @@ -192,7 +188,7 @@ class Preview {
return subject;
}
} catch (e) {
print('[PreviewApp]: Failed fetching subject: $e');
print('[PreviewApp]: Failed fetching subject. Maybe subject was reset? Error: $e');
// todo try sign in again if token expired see loading screen
}
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/src/models/tables/study_subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class StudySubject extends SupabaseObjectFunctions<StudySubject> {
.eq('id', id)
.select()
.single();
// todo delete() does not return?!
response['study'] = study.toJson();
return StudySubject.fromJson(response);
} catch (error, stacktrace) {
Expand Down

0 comments on commit ef65f85

Please sign in to comment.