Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(designer): reset feature on test mode now resets all subject data #699

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 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 @@ -66,17 +67,33 @@ class Preview {
// delete study subscription and progress
if (containsQueryPair('cmd', 'reset')) {
if (selectedStudyObjectId != null) {
final StudySubject subject = await SupabaseQuery.getById<StudySubject>(
selectedStudyObjectId!,
selectedColumns: [
'*',
'study!study_subject_studyId_fkey(*)',
'subject_progress(*)',
],
);
subject.delete();
final List<StudySubject> subjects =
await SupabaseQuery.getAll<StudySubject>();

final List<StudySubject> subjectsToDelete = subjects
.where(
(subject) =>
subject.userId ==
Supabase.instance.client.auth.currentUser!.id,
)
.toList();

print("Subjects to delete: ${subjectsToDelete.length}");

for (final subject in subjectsToDelete) {
// 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 @@ -171,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
Loading