Save profile links

This commit is contained in:
Vincent Velociter
2023-12-06 11:55:31 +01:00
parent 007237250d
commit ca74d1a95f
2 changed files with 21 additions and 4 deletions
@@ -125,7 +125,7 @@ class AccountRepository {
);
}
FutureResult<void> saveProfile(Map<String, dynamic> profile) {
FutureResult<void> saveProfile(Map<String, String> profile) {
return _apiClient.post(
Uri.parse('$kLichessHost/account/profile'),
headers: {'Accept': 'application/json'},
+20 -3
View File
@@ -113,6 +113,9 @@ class _EditProfileFormState extends ConsumerState<_EditProfileForm> {
@override
Widget build(BuildContext context) {
final String? initialLinks =
widget.user.profile?.links?.map((e) => e.url).join('\r\n');
return Form(
key: _formKey,
child: Column(
@@ -239,6 +242,16 @@ class _EditProfileFormState extends ConsumerState<_EditProfileForm> {
return null;
},
),
_textField(
label: context.l10n.socialMediaLinks,
initialValue: initialLinks,
formKey: 'links',
controller: TextEditingController(text: initialLinks),
maxLength: 3000,
maxLines: 4,
description:
'Mastodon, Facebook, GitHub, Chess.com, ...\r\n${context.l10n.oneUrlPerLine}',
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: FutureBuilder(
@@ -254,9 +267,13 @@ class _EditProfileFormState extends ConsumerState<_EditProfileForm> {
_formData.removeWhere((key, value) {
return value == null;
});
final future = ref
.read(accountRepositoryProvider)
.saveProfile(_formData);
final future =
ref.read(accountRepositoryProvider).saveProfile(
_formData.map(
(key, value) =>
MapEntry(key, value.toString()),
),
);
setState(() {
_pendingSaveProfile = future;