Skip to content

Commit

Permalink
feat: added cefr level to user setting, language settings page / sign…
Browse files Browse the repository at this point in the history
…up page (#1604)
  • Loading branch information
ggurdin authored Jan 27, 2025
1 parent 0ab7705 commit ae7c754
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/pangea/common/constants/model_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ModelKey {
static const String toolSettings = 'tool_settings';
static const String userSettings = 'user_settings';
static const String instructionsSettings = 'instructions_settings';
static const String cefrLevel = 'cefr_level';

// matrix profile keys
// making this a random string so that it's harder to guess
Expand Down
9 changes: 9 additions & 0 deletions lib/pangea/common/network/requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:sentry_flutter/sentry_flutter.dart';

import 'package:fluffychat/pangea/common/constants/model_keys.dart';
import 'package:fluffychat/widgets/matrix.dart';

class Requests {
late String? baseUrl;
// Matrix access token
Expand All @@ -21,6 +24,9 @@ class Requests {
required String url,
required Map<dynamic, dynamic> body,
}) async {
body[ModelKey.cefrLevel] = MatrixState
.pangeaController.userController.profile.userSettings.cefrLevel;

dynamic encoded;
encoded = jsonEncode(body);

Expand All @@ -40,6 +46,9 @@ class Requests {
required String url,
required Map<dynamic, dynamic> body,
}) async {
body[ModelKey.cefrLevel] = MatrixState
.pangeaController.userController.profile.userSettings.cefrLevel;

dynamic encoded;
encoded = jsonEncode(body);

Expand Down
15 changes: 14 additions & 1 deletion lib/pangea/learning_settings/pages/settings_learning.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SettingsLearningController extends State<SettingsLearning> {
super.dispose();
}

setPublicProfile(bool isPublic) {
void setPublicProfile(bool isPublic) {
pangeaController.userController.updateProfile(
(profile) {
// set user DOB to younger that 18 if private and older than 18 if public
Expand All @@ -44,6 +44,16 @@ class SettingsLearningController extends State<SettingsLearning> {
setState(() {});
}

void setCefrLevel(int? cefrLevel) {
pangeaController.userController.updateProfile(
(profile) {
profile.userSettings.cefrLevel = cefrLevel;
return profile;
},
);
setState(() {});
}

void changeLanguage() {
pLanguageDialog(context, () {}).then((_) => setState(() {}));
}
Expand Down Expand Up @@ -96,6 +106,9 @@ class SettingsLearningController extends State<SettingsLearning> {
bool get publicProfile =>
pangeaController.userController.profile.userSettings.publicProfile;

int? get cefrLevel =>
pangeaController.userController.profile.userSettings.cefrLevel;

@override
Widget build(BuildContext context) {
return SettingsLearningView(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:url_launcher/url_launcher_string.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/chat_settings/widgets/language_level_dropdown.dart';
import 'package:fluffychat/pangea/common/constants/model_keys.dart';
import 'package:fluffychat/pangea/common/widgets/full_width_dialog.dart';
import 'package:fluffychat/pangea/learning_settings/pages/settings_learning.dart';
Expand Down Expand Up @@ -49,6 +50,13 @@ class SettingsLearningView extends StatelessWidget {
children: [
LanguageTile(controller),
CountryPickerTile(controller),
Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 24.0),
child: LanguageLevelDropdown(
initialLevel: controller.cefrLevel,
onChanged: controller.setCefrLevel,
),
),
const Divider(height: 1),
ListTile(
title: Text(L10n.of(context).toggleToolSettingsDescription),
Expand Down
8 changes: 8 additions & 0 deletions lib/pangea/login/pages/user_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UserSettingsState extends State<UserSettingsPage> {
PangeaController get _pangeaController => MatrixState.pangeaController;

LanguageModel? selectedTargetLanguage;
int selectedCefrLevel = 0;

String? selectedLanguageError;
String? profileCreationError;
Expand Down Expand Up @@ -97,6 +98,12 @@ class UserSettingsState extends State<UserSettingsPage> {
});
}

void setSelectedCefrLevel(int? cefrLevel) {
setState(() {
selectedCefrLevel = cefrLevel ?? 0;
});
}

void setSelectedAvatarPath(int index) {
if (index < 0 || index >= avatarPaths.length) return;
setState(() {
Expand Down Expand Up @@ -201,6 +208,7 @@ class UserSettingsState extends State<UserSettingsPage> {
}
profile.userSettings.targetLanguage =
selectedTargetLanguage!.langCode;
profile.userSettings.cefrLevel = selectedCefrLevel;
profile.userSettings.createdAt = DateTime.now();
return profile;
},
Expand Down
8 changes: 8 additions & 0 deletions lib/pangea/login/pages/user_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/chat_settings/widgets/language_level_dropdown.dart';
import 'package:fluffychat/pangea/learning_settings/widgets/p_language_dropdown.dart';
import 'package:fluffychat/pangea/login/pages/pangea_login_scaffold.dart';
import 'package:fluffychat/pangea/login/pages/user_settings.dart';
Expand Down Expand Up @@ -97,6 +98,13 @@ class UserSettingsView extends StatelessWidget {
decorationText: L10n.of(context).iWantToLearn,
),
),
Padding(
padding: const EdgeInsets.all(8),
child: LanguageLevelDropdown(
onChanged: controller.setSelectedCefrLevel,
initialLevel: controller.selectedCefrLevel ?? 0,
),
),
if (controller.isSSOSignup)
FullWidthTextField(
hintText: L10n.of(context).username,
Expand Down
4 changes: 4 additions & 0 deletions lib/pangea/user/models/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UserSettings {
String? sourceLanguage;
String? country;
bool? hasJoinedHelpSpace;
int? cefrLevel;

UserSettings({
this.dateOfBirth,
Expand All @@ -31,6 +32,7 @@ class UserSettings {
this.sourceLanguage,
this.country,
this.hasJoinedHelpSpace,
this.cefrLevel,
});

factory UserSettings.fromJson(Map<String, dynamic> json) => UserSettings(
Expand All @@ -48,6 +50,7 @@ class UserSettings {
sourceLanguage: json[ModelKey.l1LanguageKey],
country: json[ModelKey.userCountry],
hasJoinedHelpSpace: json[ModelKey.hasJoinedHelpSpace],
cefrLevel: json[ModelKey.cefrLevel],
);

Map<String, dynamic> toJson() {
Expand All @@ -62,6 +65,7 @@ class UserSettings {
data[ModelKey.l1LanguageKey] = sourceLanguage;
data[ModelKey.userCountry] = country;
data[ModelKey.hasJoinedHelpSpace] = hasJoinedHelpSpace;
data[ModelKey.cefrLevel] = cefrLevel;
return data;
}

Expand Down

0 comments on commit ae7c754

Please sign in to comment.