Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #206 : Removed "subscribed to mail" data from others profile #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ linter:
non_constant_identifier_names: false

constant_identifier_names: false

no_leading_underscores_for_local_identifiers: false
aman-singh7 marked this conversation as resolved.
Show resolved Hide resolved

library_private_types_in_public_api: false

depend_on_referenced_packages: false

use_build_context_synchronously: false
2 changes: 1 addition & 1 deletion lib/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class UserAttributes {
this.educationalInstitute,
});
String? name;
String email;
String? email;
bool subscribed;
DateTime? createdAt;
DateTime? updatedAt;
Expand Down
31 changes: 17 additions & 14 deletions lib/ui/views/ib/builders/ib_webview_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ class IbWebViewBuilder extends MarkdownElementBuilder {

return Html(
data: textContent,
customRender: {
'iframe': (RenderContext context, Widget child) {
final width = MediaQuery.of(context.buildContext).size.width;
final height = (width * 9) / 16;
customRenders: {
tagMatcher('iframe'): CustomRender.widget(
widget: (context, child) {
final width = MediaQuery.of(context.buildContext).size.width;
final height = (width * 9) / 16;

return SizedBox(
width: width,
height: height,
child: WebView(
initialUrl: context.tree.element?.attributes['src'],
javascriptMode: JavascriptMode.unrestricted,
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
),
);
},
return SizedBox(
width: width,
height: height,
child: WebView(
initialUrl: context.tree.element?.attributes['src'],
javascriptMode: JavascriptMode.unrestricted,
initialMediaPlaybackPolicy:
AutoMediaPlaybackPolicy.always_allow,
),
);
},
),
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/views/ib/ib_landing_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ class _IbLandingViewState extends State<IbLandingView> {
? Showcase(
key: _model.toc,
description: 'Show Table of Contents',
child: IconButton(
icon: const Icon(Icons.menu_book_rounded),
onPressed: value as VoidCallback,
),
onTargetClick: () {
_model.onShowCased('toc');
if (_key.currentState!.isDrawerOpen) Get.back();
Future.delayed(
const Duration(milliseconds: 200),
value,
value as VoidCallback,
);
},
disposeOnTap: true,
child: IconButton(
icon: const Icon(Icons.menu_book_rounded),
onPressed: value as VoidCallback,
),
)
: Container();
},
Expand Down
32 changes: 11 additions & 21 deletions lib/ui/views/profile/profile_view.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mobile_app/cv_theme.dart';
import 'package:mobile_app/locator.dart';
import 'package:mobile_app/models/user.dart';
import 'package:mobile_app/services/local_storage_service.dart';
import 'package:mobile_app/ui/components/cv_tab_bar.dart';
import 'package:mobile_app/ui/views/base_view.dart';
import 'package:mobile_app/ui/views/profile/user_favourites_view.dart';
Expand All @@ -26,14 +24,6 @@ class ProfileView extends StatefulWidget {

class _ProfileViewState extends State<ProfileView> {
late ProfileViewModel _model;
String? userId;

@override
void initState() {
super.initState();
userId =
widget.userId ?? locator<LocalStorageService>().currentUser?.data.id;
}

Widget _buildProfileImage() {
return Padding(
Expand Down Expand Up @@ -84,9 +74,7 @@ class _ProfileViewState extends State<ProfileView> {
}

Widget _buildEditProfileButton() {
var _localStorageService = locator<LocalStorageService>();
if (_localStorageService.isLoggedIn &&
userId == _localStorageService.currentUser!.data.id) {
if (_model.isLoggedIn && _model.isPersonalProfile) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
primary: CVTheme.primaryColor,
Expand Down Expand Up @@ -153,10 +141,11 @@ class _ProfileViewState extends State<ProfileView> {
'Educational Institute',
_attrs?.educationalInstitute,
),
_buildProfileComponent(
'Subscribed to mails',
_attrs?.subscribed.toString(),
),
if (_model.isLoggedIn && _model.isPersonalProfile)
_buildProfileComponent(
'Subscribed to mails',
_attrs?.subscribed.toString(),
),
_buildEditProfileButton()
],
),
Expand All @@ -168,7 +157,7 @@ class _ProfileViewState extends State<ProfileView> {
}

Widget _buildProjectsTabBar() {
if (userId == null) return Container();
if (_model.userId == null) return Container();
return Expanded(
child: Card(
shape: RoundedRectangleBorder(
Expand Down Expand Up @@ -196,8 +185,8 @@ class _ProfileViewState extends State<ProfileView> {
),
body: TabBarView(
children: [
UserProjectsView(userId: userId!),
UserFavouritesView(userId: userId!),
UserProjectsView(userId: _model.userId!),
UserFavouritesView(userId: _model.userId!),
],
),
),
Expand All @@ -211,7 +200,8 @@ class _ProfileViewState extends State<ProfileView> {
return BaseView<ProfileViewModel>(
onModelReady: (model) {
_model = model;
_model.fetchUserProfile(userId);
_model.userId = widget.userId;
_model.fetchUserProfile();
},
builder: (context, model, child) => Scaffold(
appBar: widget.userId != null
Expand Down
2 changes: 1 addition & 1 deletion lib/viewmodels/ib/ib_page_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class IbPageViewModel extends BaseModel {
if (!state.tocButton) _list.add(keysMap['toc']);

if (_list.isNotEmpty) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Future.delayed(const Duration(milliseconds: 800), () {
showCaseWidgetState.startShowCase(_list);
});
Expand Down
22 changes: 19 additions & 3 deletions lib/viewmodels/profile/profile_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ import 'package:mobile_app/models/failure_model.dart';
import 'package:mobile_app/models/projects.dart';
import 'package:mobile_app/models/user.dart';
import 'package:mobile_app/services/API/users_api.dart';
import 'package:mobile_app/services/local_storage_service.dart';
import 'package:mobile_app/viewmodels/base_viewmodel.dart';

class ProfileViewModel extends BaseModel {
// ViewState Keys
String FETCH_USER_PROFILE = 'fetch_user_profile';

final UsersApi _usersApi = locator<UsersApi>();
final LocalStorageService _localStorageService =
locator<LocalStorageService>();

String? _userId;

String? get userId => _userId;

set userId(String? id) {
_userId = id ?? _localStorageService.currentUser?.data.id;
}

User? _user;

Expand All @@ -21,6 +32,11 @@ class ProfileViewModel extends BaseModel {
notifyListeners();
}

bool get isLoggedIn => _localStorageService.isLoggedIn;

bool get isPersonalProfile =>
_localStorageService.currentUser?.data.id == _userId;

Project? _updatedProject;

Project? get updatedProject => _updatedProject;
Expand All @@ -30,11 +46,11 @@ class ProfileViewModel extends BaseModel {
notifyListeners();
}

Future? fetchUserProfile(String? userId) async {
if (userId == null) return;
Future? fetchUserProfile() async {
if (_userId == null) return;
setStateFor(FETCH_USER_PROFILE, ViewState.Busy);
try {
user = await _usersApi.fetchUser(userId);
user = await _usersApi.fetchUser(_userId!);

setStateFor(FETCH_USER_PROFILE, ViewState.Success);
} on Failure catch (f) {
Expand Down
Loading