Skip to content

Commit 23a9008

Browse files
clean unused state properties
1 parent 07317d3 commit 23a9008

12 files changed

Lines changed: 34 additions & 140 deletions

File tree

lib/data/repositories/friend_request_repository_impl.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'package:hooks_riverpod/hooks_riverpod.dart';
2-
import '../../domain/entities/page.dart';
3-
import '../api/friend_request_api.dart';
4-
import '../../domain/entities/enum/friend_request_status.dart';
5-
import '../../domain/repositories/friend_request_repository.dart';
62

3+
import '../../domain/entities/enum/friend_request_status.dart';
74
import '../../domain/entities/friend_request.dart';
5+
import '../../domain/entities/page.dart';
86
import '../../domain/entities/user.dart';
7+
import '../../domain/repositories/friend_request_repository.dart';
8+
import '../api/friend_request_api.dart';
99

1010
/// Provider for the FriendRequestRepository implementation.
1111
final friendRequestRepositoryProvider =

lib/presentation/common/activity/view_model/activity_item_interaction_view_model.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:hooks_riverpod/hooks_riverpod.dart';
2+
23
import 'state/activity_item_interaction_state.dart';
34

45
/// Provider for the activity item interaction view model.

lib/presentation/common/activity/view_model/activity_list_view_model.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:hooks_riverpod/hooks_riverpod.dart';
33

4-
import '../../../../domain/entities/activity.dart';
54
import 'state/activity_list_state.dart';
65

76
/// Provider for the activity list view model.
@@ -20,23 +19,6 @@ class ActivityListWidgetViewModel
2019
ActivityListWidgetViewModel(this.ref, this.listId)
2120
: super(ActivityListWidgetState.initial());
2221

23-
/// Sets the position in the state
24-
void setScrollPosition(double position) {
25-
state = state.copyWith(position: position);
26-
}
27-
28-
void setGroupedActivities(List<List<Activity>> activities, int total) {
29-
state = state.copyWith(groupedActivities: activities, total: total);
30-
}
31-
32-
void setNbOfElements(int nbOfElements) {
33-
state = state.copyWith(nbOfElements: nbOfElements);
34-
}
35-
36-
void isLoading(bool loading) {
37-
state = state.copyWith(isLoading: loading);
38-
}
39-
4022
int calculateTotalElements(List<dynamic> listOfLists) {
4123
int totalElements =
4224
listOfLists.fold(0, (sum, list) => sum + (list.length as int));

lib/presentation/common/activity/view_model/state/activity_list_state.dart

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,17 @@ import '../../../../../domain/entities/activity.dart';
22

33
/// The state class for activity list.
44
class ActivityListWidgetState {
5-
final double scrollPosition;
6-
final int pageNumber;
7-
final int total;
8-
final int nbOfElements;
9-
final bool isLoading;
105
final List<List<Activity>> groupedActivities;
116

12-
const ActivityListWidgetState(
13-
{required this.scrollPosition,
14-
required this.pageNumber,
15-
required this.total,
16-
required this.nbOfElements,
17-
required this.isLoading,
18-
required this.groupedActivities});
7+
const ActivityListWidgetState({required this.groupedActivities});
198

209
/// Factory method to create the initial state.
2110
factory ActivityListWidgetState.initial() {
22-
return const ActivityListWidgetState(
23-
scrollPosition: 0,
24-
pageNumber: 0,
25-
total: 0,
26-
nbOfElements: 0,
27-
isLoading: false,
28-
groupedActivities: []);
11+
return const ActivityListWidgetState(groupedActivities: []);
2912
}
3013

31-
ActivityListWidgetState copyWith(
32-
{double? position,
33-
int? pageNumber,
34-
int? total,
35-
int? nbOfElements,
36-
bool? isLoading,
37-
List<List<Activity>>? groupedActivities}) {
14+
ActivityListWidgetState copyWith({List<List<Activity>>? groupedActivities}) {
3815
return ActivityListWidgetState(
39-
scrollPosition: position ?? scrollPosition,
40-
isLoading: isLoading ?? this.isLoading,
41-
pageNumber: pageNumber ?? this.pageNumber,
42-
total: total ?? this.total,
43-
nbOfElements: nbOfElements ?? this.nbOfElements,
4416
groupedActivities: groupedActivities ?? this.groupedActivities);
4517
}
4618
}

lib/presentation/common/activity/widgets/activity_item_details.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
33
import 'package:intl/intl.dart';
4+
45
import '../../../../domain/entities/activity.dart';
56
import '../../core/utils/activity_utils.dart';
67
import '../../core/utils/color_utils.dart';

lib/presentation/common/user/view_model/profile_view_model.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class ProfileViewModel extends StateNotifier<ProfileState> {
2424
/// Retrieves the friendship status.
2525
Future<void> getFriendshipStatus(String userId) async {
2626
final friendRequestRepository = ref.read(friendRequestRepositoryProvider);
27-
//final activityRepository = ref.read(activityRepositoryProvider);
28-
2927
final currentUser = await StorageUtils.getUser();
3028

3129
if (userId != currentUser?.id) {
@@ -34,16 +32,6 @@ class ProfileViewModel extends StateNotifier<ProfileState> {
3432
} else {
3533
state = state.copyWith(status: FriendRequestStatus.noDisplay);
3634
}
37-
/*
38-
if (state.friendshipStatus != null &&
39-
state.friendshipStatus == FriendRequestStatus.accepted) {
40-
final activities = await activityRepository.getUserActivities(userId);
41-
state =
42-
state.copyWith(activities: activities.list, total: activities.total);
43-
} else if (userId == currentUser?.id) {
44-
final activities = await activityRepository.getActivities();
45-
state = state.copyWith(activities: activities.list);
46-
}*/
4735
}
4836

4937
Future<EntityPage<Activity>> fetchActivities({int pageNumber = 0}) async {

lib/presentation/common/user/view_model/state/profile_state.dart

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,29 @@ import 'dart:typed_data';
22

33
import '../../../../../domain/entities/enum/friend_request_status.dart';
44

5-
import '../../../../../domain/entities/activity.dart';
6-
75
/// The state class for profile.
86
class ProfileState {
9-
final List<Activity> activities; // List of activities
10-
final int total; // total of activities to display
117
final bool isLoading; // Indicates if the list is currently loading
128
final FriendRequestStatus? friendshipStatus; //the friend request status
139
final Uint8List? profilePicture; // the profile picture
1410

1511
const ProfileState(
16-
{required this.activities,
17-
required this.total,
18-
required this.isLoading,
12+
{required this.isLoading,
1913
required this.friendshipStatus,
2014
required this.profilePicture});
2115

2216
/// Factory method to create the initial state.
2317
factory ProfileState.initial() {
2418
return const ProfileState(
25-
activities: [],
26-
total: 0,
27-
isLoading: false,
28-
friendshipStatus: null,
29-
profilePicture: null);
19+
isLoading: false, friendshipStatus: null, profilePicture: null);
3020
}
3121

3222
/// Method to create a copy of the state with updated values.
3323
ProfileState copyWith(
34-
{List<Activity>? activities, // Updated list of activities
35-
int? total, // updated total
36-
bool? isLoading, // Updated loading state
24+
{bool? isLoading, // Updated loading state
3725
FriendRequestStatus? status, // Updated friend request status
3826
Uint8List? profilePicture}) {
3927
return ProfileState(
40-
activities: activities ?? this.activities,
41-
total: total ?? this.total,
4228
isLoading: isLoading ?? this.isLoading,
4329
friendshipStatus: status ?? friendshipStatus,
4430
profilePicture: profilePicture ?? this.profilePicture);

lib/presentation/community/view_model/community_view_model.dart

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:hooks_riverpod/hooks_riverpod.dart';
2+
import '../../common/core/enums/infinite_scroll_list.enum.dart';
3+
import '../../common/core/widgets/view_model/infinite_scroll_list_view_model.dart';
24

35
import '../../../data/repositories/activity_repository_impl.dart';
46
import '../../../data/repositories/user_repository_impl.dart';
@@ -22,25 +24,19 @@ class CommunityViewModel extends StateNotifier<CommunityState> {
2224
return ref.read(userRepositoryProvider).search(text);
2325
}
2426

25-
void getMyAndMyFriendsActivities() async {
26-
if (!state.isLoading) {
27-
state = state.copyWith(isLoading: true);
28-
29-
EntityPage<Activity> newActivities = await ref
30-
.read(activityRepositoryProvider)
31-
.getMyAndMyFriendsActivities(pageNumber: state.pageNumber);
32-
state = state.copyWith(
33-
activities: [...state.activities, ...newActivities.list],
34-
isLoading: false,
35-
pageNumber: state.pageNumber + 1);
36-
}
37-
}
38-
3927
Future<EntityPage<Activity>> getInitialMyAndMyFriendsActivities(
4028
{int pageNumber = 0}) async {
4129
EntityPage<Activity> newActivities = await ref
4230
.read(activityRepositoryProvider)
4331
.getMyAndMyFriendsActivities(pageNumber: pageNumber);
4432
return newActivities;
4533
}
34+
35+
void refreshList() {
36+
ref
37+
.read(infiniteScrollListViewModelProvider(
38+
InfiniteScrollListEnum.community.toString())
39+
.notifier)
40+
.reset();
41+
}
4642
}
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
import '../../../../domain/entities/activity.dart';
2-
31
/// The state class for community screen.
42
class CommunityState {
5-
final List<Activity> activities; // List of activities
6-
final bool isLoading; // Indicates if the list is currently loading
7-
final int pageNumber;
8-
9-
const CommunityState(
10-
{required this.activities,
11-
required this.isLoading,
12-
required this.pageNumber});
3+
const CommunityState();
134

145
/// Factory method to create the initial state.
156
factory CommunityState.initial() {
16-
return const CommunityState(
17-
activities: [], isLoading: false, pageNumber: 0);
7+
return const CommunityState();
188
}
199

2010
/// Method to create a copy of the state with updated values.
21-
CommunityState copyWith(
22-
{List<Activity>? activities, // Updated list of activities
23-
bool? isLoading, // Updated loading state
24-
int? pageNumber}) {
25-
return CommunityState(
26-
activities: activities ?? this.activities,
27-
isLoading: isLoading ?? this.isLoading,
28-
pageNumber: pageNumber ?? this.pageNumber);
11+
CommunityState copyWith() {
12+
return const CommunityState();
2913
}
3014
}

lib/presentation/my_activities/view_model/activity_list_view_model.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,4 @@ class ActivityListViewModel extends StateNotifier<ActivityListState> {
6969
),
7070
);
7171
}
72-
73-
/// Reload the state with new list of activities
74-
void reloadActivities(List<Activity> activities) {
75-
state = state.copyWith(activities: activities);
76-
}
7772
}

0 commit comments

Comments
 (0)