Skip to content

Commit

Permalink
Enhancing UX by introducing User Profile Modification Feature (Palisa…
Browse files Browse the repository at this point in the history
…doesFoundation#2268)

* Feature request: Implement User Profile Modification Feature

* changes

* changes

* proper dynamic call

* fixing tests

* fixing coverage

* writing test for missing lines

* writing test for missing lines

* writing test for missing lines

* writing test for missing lines

* writing test for missing lines

* adding requested changes

* adding requested changes

* adding requested changes

* adding requested changes

* adding requested changes

* adding requested changes

* adding requested changes

* test for missing lines

* adding requested changes

* adding requested changes

* test for missing lines
  • Loading branch information
Dante291 authored and Abhisheksainii committed Jan 3, 2024
1 parent 2f0482e commit ece173d
Show file tree
Hide file tree
Showing 22 changed files with 898 additions and 292 deletions.
4 changes: 3 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@
"Notification Feature is not installed": "Meddelelsesfunktionen er ikke installeret",
"For complete access, please": "Für vollständigen Zugriff bitte",
" join an organization.": " einer Organisation beitreten.",
"JOIN":"BEITRETEN"
"JOIN":"BEITRETEN",
"Camera": "Kamera",
"Gallery": "Galerie"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,7 @@
"No organizations found Please contact your admin": "No organizations found ! Please contact your admin",
"For complete access, please": "For complete access, please",
" join an organization.": " join an organization.",
"JOIN":"JOIN"
"JOIN":"JOIN",
"Camera": "Camera",
"Gallery": "Gallery"
}
4 changes: 3 additions & 1 deletion lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,7 @@
"No organizations found Please contact your admin": "Neniuj organizoj trovitaj! Bonvolu kontakti vian administranton",
"For complete access, please": "Para acceso completo, por favor",
" join an organization.": " unirse a una organización.",
"JOIN":"UNIRSE"
"JOIN":"UNIRSE",
"Camera": "Cámara",
"Gallery": "Galería"
}
4 changes: 3 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@
"No organizations found Please contact your admin": "Aucune organisation trouvée ! Veuillez contacter votre administrateur",
"For complete access, please": "Pour un accès complet, veuillez",
" join an organization.": " rejoindre une organisation.",
"JOIN":"REJOINDRE"
"JOIN":"REJOINDRE",
"Camera": "Caméra",
"Gallery": "Galerie"
}
4 changes: 3 additions & 1 deletion lang/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,7 @@
"No organizations found Please contact your admin": "कोई संगठन नहीं मिला! कृपया अपने व्यवस्थापक से संपर्क करें",
"For complete access, please": "पूर्ण पहुंच के लिए, कृपया",
" join an organization.": " किसी संगठन से जुड़ें.",
"JOIN":"जोड़ना"
"JOIN":"जोड़ना",
"Camera": "कैमरा",
"Gallery": "गैलरी"
}
4 changes: 3 additions & 1 deletion lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,7 @@
"No organizations found Please contact your admin": "組織が見つかりません!管理者に連絡してください",
"For complete access, please": "完全にアクセスするには、",
" join an organization.": " 組織に参加します。",
"JOIN": "参加する"
"JOIN": "参加する",
"Camera": "カメラ",
"Gallery": "ギャラリー"
}
4 changes: 3 additions & 1 deletion lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,7 @@
"No organizations found Please contact your admin": "Neniuj organizoj trovitaj! Bonvolu kontakti vian administranton",
"For complete access, please": "Para acesso completo, por favor",
" join an organization.": " ingressar em uma organização.",
"JOIN":"ENTRAR"
"JOIN":"ENTRAR",
"Camera": "Câmera",
"Gallery": "Galeria"
}
4 changes: 3 additions & 1 deletion lang/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@
"No organizations found Please contact your admin": "Neniuj organizoj trovitaj! Bonvolu kontakti vian administranton",
"For complete access, please": "如需完整访问,请",
" join an organization.": " 加入一个组织。",
"JOIN":"加入"
"JOIN":"加入",
"Camera": "相机",
"Gallery": "画廊"
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class AddPostViewModel extends BaseModel {
String get userName =>
userConfig.currentUser.firstName! + userConfig.currentUser.lastName!;

/// User profile picture.
String? get userPic => userConfig.currentUser.image;

/// The organisation name.
///
/// params:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/third_party_service/multi_media_pick_service.dart';
import 'package:talawa/view_model/base_view_model.dart';

Expand All @@ -16,6 +20,9 @@ class EditProfilePageViewModel extends BaseModel {
/// profile image.
late File? imageFile;

/// profile image in base64.
String? base64Image;

/// first name controller.
TextEditingController firstNameTextController = TextEditingController();

Expand Down Expand Up @@ -52,7 +59,7 @@ class EditProfilePageViewModel extends BaseModel {
///
/// **returns**:
/// * `Future<void>`: None
Future<void> getImageFromGallery({bool camera = false}) async {
Future<void> getImage({bool camera = false}) async {
final image =
await _multiMediaPickerService.getPhotoFromGallery(camera: camera);
if (image != null) {
Expand All @@ -61,6 +68,108 @@ class EditProfilePageViewModel extends BaseModel {
}
}

/// Method to select image from gallery or camera.
///
/// **params**:
/// * `camera`: for true it will select from camera otherwise gallery
///
/// **returns**:
/// * `Future<void>`: none
Future<void> selectImage({bool camera = false}) async {
if (camera) {
getImage(camera: true);
} else {
getImage();
}
}

/// This function is used to convert the image into Base64 format.
///
/// **params**:
/// * `file`: Takes the image in format of file.
///
/// **returns**:
/// * `Future<String>`: image in string format
Future<String> convertToBase64(File file) async {
try {
final List<int> bytes = await file.readAsBytes();
base64Image = base64Encode(bytes);
return base64Image!;
} catch (error) {
return '';
}
}

/// Method to update user profile.
///
/// **params**:
/// * `firstName`: updated first name.
/// * `lastName`: updated last name.
/// * `newImage`: New profile picture that is to be updated.
///
/// **returns**:
/// * `Future<void>`: none
Future<void> updateUserProfile({
String? firstName,
String? lastName,
File? newImage,
}) async {
if (firstName == user.firstName &&
newImage == null &&
lastName == user.lastName) {
return;
}
try {
final Map<String, dynamic> variables = {};
if (firstName != null) {
variables["firstName"] = firstName;
}
if (lastName != null) {
variables["lastName"] = lastName;
}
if (newImage != null) {
final String imageAsString = await convertToBase64(newImage);
variables["file"] = 'data:image/png;base64,$imageAsString';
}
if (variables.isNotEmpty) {
await databaseService.gqlAuthMutation(
queries.updateUserProfile(),
variables: variables,
);
// Fetch updated user info from the database and save it in hivebox.
final QueryResult result1 = await databaseFunctions.gqlAuthQuery(
queries.fetchUserInfo,
variables: {'id': user.id},
) as QueryResult;
final User userInfo = User.fromJson(
((result1.data!['users'] as List<dynamic>)[0])
as Map<String, dynamic>,
fromOrg: true,
);
userInfo.authToken = userConfig.currentUser.authToken;
userInfo.refreshToken = userConfig.currentUser.refreshToken;
userConfig.updateUser(userInfo);
notifyListeners();

user.firstName = firstName ?? user.firstName;
user.lastName = lastName ?? user.lastName;
firstNameTextController.text = user.firstName!;
lastNameTextController.text = user.lastName!;

navigationService.showTalawaErrorSnackBar(
"Profile updated successfully",
MessageType.info,
);
notifyListeners();
}
} on Exception catch (_) {
navigationService.showTalawaErrorSnackBar(
"Something went wrong",
MessageType.error,
);
}
}

/// This function remove the selected image.
///
/// **params**:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class ProfilePageViewModel extends BaseModel {
void Function(void Function()) setter,
) {
return InkWell(
key: const Key('dombtn1'),
key: Key('domBtn_$amount'),
onTap: () {
setter(() {
donationAmount.text = amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class SelectOrganizationViewModel extends BaseModel {
return {
'organizationsConnection':
(existingOrganizations!["organizationsConnection"]
as List<Map<String, dynamic>>) +
as List<Object?>) +
(newOrganizations!['organizationsConnection']
as List<Map<String, dynamic>>),
as List<dynamic>),
};
},
),
Expand Down
9 changes: 8 additions & 1 deletion lib/views/after_auth_screens/add_post_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/utils/app_localization.dart';
import 'package:talawa/view_model/after_auth_view_models/add_post_view_models/add_post_view_model.dart';
import 'package:talawa/views/base_view.dart';
import 'package:talawa/widgets/custom_avatar.dart';

/// Add Post View Model.
late AddPostViewModel model;
Expand Down Expand Up @@ -81,7 +83,12 @@ class _AddPostState extends State<AddPost> {
child: Column(
children: <Widget>[
ListTile(
leading: const CircleAvatar(radius: 25),
leading: CustomAvatar(
isImageNull: model.userPic == null,
firstAlphabet: model.userName.substring(0, 1).toUpperCase(),
imageUrl: model.userPic,
fontSize: SizeConfig.screenHeight! * 0.018,
),
title: Text(model.userName),
subtitle: Text(
AppLocalizations.of(context)!
Expand Down
Loading

0 comments on commit ece173d

Please sign in to comment.