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

Add dummy final score page #36

Merged
merged 15 commits into from
Nov 7, 2023
Merged
Binary file removed app/assets/images/logo.jpg
Binary file not shown.
Binary file added app/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions app/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions app/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
2 changes: 2 additions & 0 deletions app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'features/authentication/register/bloc/user_register_bloc.dart';
import 'features/onboarding/presentation/bloc/user_initialization_bloc.dart';
import 'features/quiz_exercise/presentation/bloc/quiz_exercise_cubit.dart';
import 'features/quiz_registration/presentation/bloc/quiz_registration_cubit.dart';
import 'features/quiz_result/presentation/bloc/quiz_result_cubit.dart';
import 'services/di.dart';
import 'services/router_service.dart';

Expand All @@ -28,6 +29,7 @@ class App extends StatelessWidget {
),
),
BlocProvider(create: (context) => QuizExerciseCubit()),
BlocProvider(create: (context) => QuizResultCubit()),
BlocProvider(create: (context) => QuizRegistrationCubit()),
BlocProvider(create: (context) => get<UserRegisterBloc>()),
],
Expand Down
5 changes: 2 additions & 3 deletions app/lib/features/main/presentation/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class _MainPageState extends State<MainPage> {

@override
Widget build(BuildContext context) {

return BebrasScaffold(
body: SingleChildScrollView(
child: Stack(
Expand All @@ -48,8 +47,8 @@ class _MainPageState extends State<MainPage> {
style: FontTheme.blackTitle(),
children: <TextSpan>[
TextSpan(
text:
toBeginningOfSentenceCase('${useData['name']}!'),
text: toBeginningOfSentenceCase(
'${useData?['name']}!'),
style: FontTheme.blackTitleBold(),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SplashScreen extends StatelessWidget {
},
child: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import '../model/quiz_exercise_answer.dart';
import '../model/quiz_exercise_attempt.dart';
import '../repositories/quiz_exercise.dart';

part 'quiz_exercise_event.dart';
part 'quiz_exercise_state.dart';

class QuizExerciseCubit extends Cubit<QuizExerciseState> {
Expand All @@ -23,20 +22,20 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
int currentProblemIndex = 0;
late List<String> problemIdList;
late QuizExerciseAttempt attempt;
late String quizParticipantId;
late String challengeGroup;
String? quizParticipantId;

String selectedAnswer = '';
late int remainingDuration;
Timer? timer;

late QuizService quizService;
late QuizExerciseRepository quizExerciseRepository;

FutureOr<void> fetchQuizExercise({
String? quizId,
String? quizParticipantId,
String? challengeGroup,
}) async {
FutureOr<void> initialize(
{String? quizId,
String? quizParticipantId,
String? challengeGroup}) async {
try {
quizService = QuizService();
quizExerciseRepository = QuizExerciseRepository();
Expand Down Expand Up @@ -87,7 +86,7 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
throw Exception('Duration for selected Challenge Group not found');
}
remainingDuration = duration * 60;
Timer.periodic(const Duration(seconds: 1), (timer) {
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (state is! QuizExerciseShow) {
timer.cancel();
} else if (remainingDuration > 0) {
Expand Down Expand Up @@ -190,13 +189,17 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
attempt.endAt = DateTime.now();
attempt.uploadedAt = DateTime.now();
await quizExerciseRepository.insertQuizExerciseAttempt(
quizParticipantId,
attempt,
);
emit(QuizExerciseFinished(attempt));
quizParticipantId!, attempt);
emit(QuizExerciseFinished(quizParticipantId!));
}
} catch (e) {
emit(QuizExerciseFailed(e.toString()));
}
}

@override
Future<void> close() {
timer?.cancel();
return super.close();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class QuizExerciseShow extends QuizExerciseState {
}

class QuizExerciseFinished extends QuizExerciseState {
final QuizExerciseAttempt quizExerciseAttempt;
const QuizExerciseFinished(this.quizExerciseAttempt);
final String quizParticipantId;
const QuizExerciseFinished(this.quizParticipantId);

@override
List<Object> get props => [quizExerciseAttempt];
List<Object> get props => [quizParticipantId];
}

class QuizExerciseFailed extends QuizExerciseState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class QuizExercisePage extends StatefulWidget {
final String? quizId;
final String? challengeGroup;
final String? quizParticipantId;
const QuizExercisePage(
QuizExercisePage(
{super.key, this.quizId, this.challengeGroup, this.quizParticipantId});

@override
Expand All @@ -16,11 +16,14 @@ class QuizExercisePage extends StatefulWidget {
class _QuizExercisePageState extends State<QuizExercisePage> {
@override
void initState() {
final cubit = context.read<QuizExerciseCubit>();
if (cubit.quizParticipantId != widget.quizParticipantId) {
cubit.initialize(
quizId: widget.quizId,
quizParticipantId: widget.quizParticipantId,
challengeGroup: widget.challengeGroup);
}
super.initState();
context.read<QuizExerciseCubit>().fetchQuizExercise(
quizId: widget.quizId,
quizParticipantId: widget.quizParticipantId,
challengeGroup: widget.challengeGroup);
}

@override
Expand All @@ -47,7 +50,9 @@ class _QuizExercisePageState extends State<QuizExercisePage> {
context.replace(
Uri(
path: '/quiz_result',
queryParameters: {},
queryParameters: {
'quiz_participant_id': state.quizParticipantId,
},
).toString(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class QuizExerciseRepository {
try {
final result = await FirebaseFirestore.instance
.collection('task_set')
.doc(taskId)
.where('id', isEqualTo: taskId)
.get();
return QuizExercise.fromJson(result.data()!);
if (result.docs.isEmpty) {
throw Exception('Task ID not found');
}
final data = result.docs.first;
return QuizExercise.fromJson(data.data());
} catch (e) {
throw Exception(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ class QuizRegistrationCubit extends Cubit<QuizRegistrationState> {
final participantWeeklyQuizzes = await QuizService()
.getRunningWeeklyQuizByParticipantUid(participantUid);

if (participantWeeklyQuizzes.isNotEmpty) {
emit(GetParticipantWeeklyQuizSuccess(participantWeeklyQuizzes));
} else {
emit(const GetParticipantWeeklyQuizFailed('error'));
}
emit(GetParticipantWeeklyQuizSuccess(participantWeeklyQuizzes));
} catch (e) {
emit(GetParticipantWeeklyQuizFailed(e.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,25 @@ class _QuizRegistrationPageState extends State<QuizRegistrationPage> {
String score, String level, BuildContext context) {
return InkWell(
onTap: () {
final endDate = DateFormat('yyyy-MM-dd HH:mm:ss')
.parse(weeklyQuizParticipant.quiz_end_at);
if (endDate.isBefore(DateTime.now())) {
if (weeklyQuizParticipant.attempts.length >=
weeklyQuizParticipant.quiz_max_attempts) {
context.push(
Uri(
path: '/quiz_result',
queryParameters: {
'quiz_participant_id': weeklyQuizParticipant.id,
},
).toString(),
);
} else if (weeklyQuizParticipant.attempts.isNotEmpty) {
context.push(
Uri(
path: '/quiz_result',
queryParameters: {
'quiz_participant_id': weeklyQuizParticipant.id,
},
).toString(),
);
} else {
context.push(
Uri(
Expand Down Expand Up @@ -348,6 +364,22 @@ class _QuizRegistrationPageState extends State<QuizRegistrationPage> {
},
builder: (context, state) {
if (state is GetParticipantWeeklyQuizSuccess) {
if (state.weeklyQuizzes.isEmpty) {
return Container(
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.only(
bottom: 12, top: 12),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Text(
'Silahkan klik Tombol `Daftar Latihan Bebras` dibawah untuk memulai',
),
),
);
}
return ListView(children: [
const SizedBox(
height: 10,
Expand All @@ -374,20 +406,7 @@ class _QuizRegistrationPageState extends State<QuizRegistrationPage> {
}

if (state is GetParticipantWeeklyQuizFailed) {
return Container(
padding: const EdgeInsets.all(10),
margin:
const EdgeInsets.only(bottom: 12, top: 12),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Text(
'Silahkan klik Tombol `Daftar Latihan Bebras` dibawah untuk memulai',
),
),
);
return Text(state.error);
}
return const Center(
child: CircularProgressIndicator(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

import '../../../../services/quiz_service.dart';
import '../../../quiz_exercise/presentation/model/quiz_exercise_attempt.dart';

part 'quiz_result_state.dart';

class QuizResultCubit extends Cubit<QuizResultState> {
QuizResultCubit() : super(QuizResultInitial());

FutureOr<void> initialize(String? quizParticipantId) async {
try {
final quizService = QuizService();

if (quizParticipantId == null) {
throw Exception('QuizParticipantId is null');
}

final quizParticipation = await quizService.getWeeklyQuizParticipant(
quizParticipantId: quizParticipantId);

if (quizParticipation.attempts.isEmpty) {
emit(QuizResultNotAvailable());
} else {
emit(QuizResultAvailable(quizParticipation.attempts.last));
}
} catch (e) {
emit(QuizResultFailed(e.toString()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
part of 'quiz_result_cubit.dart';

@immutable
abstract class QuizResultState extends Equatable {
const QuizResultState();

@override
List<Object> get props => [];
}

class QuizResultInitial extends QuizResultState {}

class QuizResultNotAvailable extends QuizResultState {}

class QuizResultAvailable extends QuizResultState {
final QuizExerciseAttempt attempt;

const QuizResultAvailable(this.attempt);
@override
List<Object> get props => [attempt];
}

class QuizResultFailed extends QuizResultState {
final String error;

const QuizResultFailed(this.error);
@override
List<Object> get props => [error];
}
Loading