Skip to content

Commit

Permalink
Carlene/mixpanel (#36)
Browse files Browse the repository at this point in the history
* fix: change secrets env target path

* feat(service): initializing mixpanel service

* add env

* feat(service): add mixpanels

* fix: add params

* fix: clean code

---------

Co-authored-by: Veloraine <[email protected]>
Co-authored-by: Yudha Haris Purnama <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2023
1 parent 08614ce commit 16877a8
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 159 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ulaskelas-frontend",
"request": "launch",
"type": "dart"
},
{
"name": "ulaskelas-frontend (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "ulaskelas-frontend (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
6 changes: 5 additions & 1 deletion lib/core/environment/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Config {
await HiveDataBaseService.init();
}
await Pref.init();
await MixpanelService.init();

// TODO(fauzi): Implement notification plugin
// await notificationPlugin.init();
Expand All @@ -55,6 +56,7 @@ class Config {
}

static bool get isDevelopment => appFlavor == Flavor.development;

static BaseConfig get baseConfig => _baseConfig()!;

static BaseConfig? _baseConfig() {
Expand All @@ -74,8 +76,10 @@ class Config {

class BaseConfig {
const BaseConfig({
required this.endpoints, this.assetAbsolutePath = Constants.assetPath,
required this.endpoints,
this.assetAbsolutePath = Constants.assetPath,
});

final String assetAbsolutePath;
final BaseEndpoints endpoints;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/core/environment/secrets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import 'package:envied/envied.dart';

part 'secrets.g.dart';

@Envied(name: 'Secret', path: '.env.example')
@Envied(name: 'Secret', path: '.env')
abstract class Secret {
@EnviedField(varName: 'BASE_URL_DEV')
static const String baseUrlDev = _Secret.baseUrlDev;
@EnviedField(varName: 'BASE_URL_PROD')
static const String baseUrlProd = _Secret.baseUrlProd;
@EnviedField(varName: 'MIXPANEL_TOKEN')
static const String mixpanelToken = _Secret.mixpanelToken;
}
23 changes: 23 additions & 0 deletions lib/core/utils/util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
String getFinalGrade(double score) {
var grade = 'E';
switch (score) {
case >= 85:
grade = 'A';
case >= 80:
grade = 'A-';
case >= 75:
grade = 'B+';
case >= 70:
grade = 'B';
case >= 65:
grade = 'B-';
case >= 60:
grade = 'C+';
case >= 55:
grade = 'C';
case >= 40:
grade = 'D';
}

return grade;
}
2 changes: 2 additions & 0 deletions lib/features/kalkulator/presentation/pages/_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:ulaskelas/core/bases/states/_states.dart';
import 'package:ulaskelas/core/constants/_constants.dart';
import 'package:ulaskelas/core/theme/_theme.dart';
import 'package:ulaskelas/core/utils/util.dart';
import 'package:ulaskelas/features/kalkulator/domain/entities/query_calculator.dart';
import 'package:ulaskelas/services/_services.dart';
import '../../../matkul/main/domain/entities/query_search_course.dart';
import '../../../matkul/search/presentation/states/_states.dart';
import '../../../matkul/search/presentation/widgets/_widgets.dart';
Expand Down
42 changes: 27 additions & 15 deletions lib/features/kalkulator/presentation/pages/kalkulator_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class _CalculatorPageState extends BaseStateful<CalculatorPage> {

@override
Widget buildNarrowLayout(
BuildContext context,
SizingInformation sizeInfo,
) {
BuildContext context,
SizingInformation sizeInfo,
) {
return SafeArea(
child: RefreshIndicator(
key: refreshIndicatorKey,
Expand Down Expand Up @@ -82,8 +82,11 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
width: double.infinity,
text: 'Tambah Mata Kuliah',
backgroundColor: BaseColors.purpleHearth,
onPressed: () =>
nav.goToSearchCourseCalculatorPage(),
onPressed: () {
nav.goToSearchCourseCalculatorPage();
// ignore: lines_longer_than_80_chars
MixpanelService.track('calculator_add_course');
},
),
],
),
Expand All @@ -97,7 +100,7 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
padding: const EdgeInsets.all(20),
itemCount: calculatorRM.state.calculators.length + 1,
itemBuilder: (context, index) {
if (index == calculators.length){
if (index == calculators.length) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 20,
Expand All @@ -116,19 +119,27 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
model: calculator,
onTap: () {
nav.goToComponentCalculatorPage(
calculatorId: calculator.id!,
courseName: calculator.courseName!,
totalScore: calculator.totalScore!,
totalPercentage: calculator.totalPercentage!,
calculatorId: calculator.id!,
courseName: calculator.courseName!,
totalScore: calculator.totalScore!,
totalPercentage: calculator.totalPercentage!,
);
MixpanelService.track(
'calculator_view_course',
params: {
'course_id': calculator.courseName!,
'final_letter_grade': getFinalGrade(
calculator.totalScore!,),
'final_grade': calculator.totalScore.toString(),
},
);
},
);
},
separatorBuilder: (BuildContext context, int index) =>
const SizedBox(height: 16),
const SizedBox(height: 16),
),
),

],
);
},
Expand All @@ -139,9 +150,9 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul

@override
Widget buildWideLayout(
BuildContext context,
SizingInformation sizeInfo,
) {
BuildContext context,
SizingInformation sizeInfo,
) {
return buildNarrowLayout(context, sizeInfo);
}

Expand All @@ -159,4 +170,5 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
bool scrollCondition() {
throw UnimplementedError();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class _ComponentFormPageState extends BaseStateful<ComponentFormPage> {
text: 'Simpan',
onTap: () async {
await onSubmitCallBack(context);
MixpanelService.track('calculator_add_course_component');
},
),
)
),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: lines_longer_than_80_chars

part of '_pages.dart';

class CalculatorComponentPage extends StatefulWidget {
Expand Down Expand Up @@ -75,7 +77,7 @@ class _CalculatorComponentPageState
Text(
_getFinalScoreAndGrade(widget.totalScore),
style: FontTheme.poppins14w600black(),
)
),
],
),
Padding(
Expand Down Expand Up @@ -103,7 +105,7 @@ class _CalculatorComponentPageState
textAlign: TextAlign.center,
style: FontTheme.poppins12w600black(),
),
)
),
],
),
),
Expand Down Expand Up @@ -184,6 +186,14 @@ class _CalculatorComponentPageState
QueryCalculator(id: widget.calculatorId),
),
);
MixpanelService.track(
'calculator_delete_course_component',
params: {
'course_id': widget.courseName,
'final_letter_grade': widget.totalScore.toString(),
'final_grade': getFinalGrade(widget.totalScore),
},
);
},
child: Text(
'Hapus Kalkulator Mata Kuliah',
Expand All @@ -193,7 +203,7 @@ class _CalculatorComponentPageState
),
),
),
)
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ class CalculatorState {
_calculators = result.data;
print(_calculators);
});
}
);
});
calculatorRM.notify();
}

Future<void> deleteCalculator(QueryCalculator query) async {
final resp = await _repo.deleteCalculator(query);
await resp.fold((failure) {
ErrorMessenger('Kalkulator gagal dihapus')
.show(ctx!);
ErrorMessenger('Kalkulator gagal dihapus').show(ctx!);
}, (result) async {
SuccessMessenger('Kalkulator berhasil dipahus').show(ctx!);
final calcResp = await _repo.getAllCalculator();
Expand All @@ -64,8 +62,7 @@ class CalculatorState {
_calculators = result.data;
print(_calculators);
});
}
);
});
calculatorRM.notify();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import 'package:ulaskelas/features/matkul/bookmarks/domain/entities/query_bookma
import 'package:ulaskelas/features/matkul/bookmarks/presentation/states/_states.dart';
import 'package:ulaskelas/features/matkul/bookmarks/presentation/widgets/_widgets.dart';
import 'package:ulaskelas/features/matkul/search/presentation/widgets/_widgets.dart';
import 'package:ulaskelas/services/_services.dart';

part 'bookmarks_page.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ Kamu Belum memiliki Mata kuliah tersimpan. Silakan tambahkan terlebih dahulu.'''
// TODO(paw): set course_id
return CardBookmark(
model: bookmark,
onTap: () => nav.goToDetailMatkulPage(
bookmark.courseId!,
bookmark.courseCode!,
),
onTap: () {
nav.goToDetailMatkulPage(
bookmark.courseId!,
bookmark.courseCode!,
);
MixpanelService.track(
'open_profile_saved_course',
params: {
'course_id': bookmark.courseCode!,
},
);
},
);
},
separatorBuilder: (BuildContext context, int index) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ part of '_pages.dart';
/// ```;
class DetailMatkulPage extends StatefulWidget {
const DetailMatkulPage({
required this.courseId, required this.courseCode, super.key,
required this.courseId,
required this.courseCode,
super.key,
});

final int courseId;
Expand Down Expand Up @@ -114,7 +116,7 @@ class _DetailMatkulPageState extends BaseStateful<DetailMatkulPage> {
TitleAndBookMark(course: course),
const HeightSpace(24),
if (course.tags?.isNotEmpty ?? false)
_buildMatkulTag(course),
_buildMatkulTag(course),
const HeightSpace(16),
_buildMatkulDescription(course),
const HeightSpace(32),
Expand Down Expand Up @@ -170,12 +172,12 @@ class _DetailMatkulPageState extends BaseStateful<DetailMatkulPage> {
children: course.tags!
.map(
(e) => Padding(
padding: const EdgeInsets.only(right: 8, bottom: 8),
child: Tag(
label: e,
),
),
)
padding: const EdgeInsets.only(right: 8, bottom: 8),
child: Tag(
label: e,
),
),
)
.toList(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:ulaskelas/features/leaderboard/presentation/widgets/_widgets.dar
import 'package:ulaskelas/features/matkul/bookmarks/data/models/_models.dart';
import 'package:ulaskelas/features/matkul/form/data/models/_models.dart';
import 'package:ulaskelas/features/matkul/search/data/models/_models.dart';
import 'package:ulaskelas/services/_services.dart';
import 'package:ulaskelas/services/launch_service.dart';

part 'review_card.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ part of '_widgets.dart';

class TitleAndBookMark extends StatelessWidget {
const TitleAndBookMark({
required this.course, super.key,
required this.course,
super.key,
});

final CourseModel course;
Expand Down Expand Up @@ -36,6 +37,7 @@ class TitleAndBookMark extends StatelessWidget {
shortName: course.shortName,
);
bookmarkRM.setState((s) => s.toggleBookmark(bookmark));
MixpanelService.track('bookmark_course');
},
child: Icon(
Icons.bookmark,
Expand Down
Loading

0 comments on commit 16877a8

Please sign in to comment.