feat: added cefr level to user setting, language settings page / signup page (#1604)

pull/1593/head
ggurdin 9 months ago committed by GitHub
parent 0ab77054d5
commit ae7c754dbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

@ -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
@ -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);
@ -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);

@ -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
@ -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(() {}));
}
@ -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);

@ -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';
@ -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),

@ -28,6 +28,7 @@ class UserSettingsState extends State<UserSettingsPage> {
PangeaController get _pangeaController => MatrixState.pangeaController;
LanguageModel? selectedTargetLanguage;
int selectedCefrLevel = 0;
String? selectedLanguageError;
String? profileCreationError;
@ -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(() {
@ -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;
},

@ -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';
@ -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,

@ -19,6 +19,7 @@ class UserSettings {
String? sourceLanguage;
String? country;
bool? hasJoinedHelpSpace;
int? cefrLevel;
UserSettings({
this.dateOfBirth,
@ -31,6 +32,7 @@ class UserSettings {
this.sourceLanguage,
this.country,
this.hasJoinedHelpSpace,
this.cefrLevel,
});
factory UserSettings.fromJson(Map<String, dynamic> json) => UserSettings(
@ -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() {
@ -62,6 +65,7 @@ class UserSettings {
data[ModelKey.l1LanguageKey] = sourceLanguage;
data[ModelKey.userCountry] = country;
data[ModelKey.hasJoinedHelpSpace] = hasJoinedHelpSpace;
data[ModelKey.cefrLevel] = cefrLevel;
return data;
}

Loading…
Cancel
Save