Skip to content

Commit

Permalink
Mr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik committed Jun 24, 2024
1 parent 7f18066 commit 71e5c78
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 58 deletions.
26 changes: 26 additions & 0 deletions app/lib/domain/extenstions/time_ago_extenstions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extension TimeAgoExtension on int? {
String timeAgo() {
if (this == null) return "";

final DateTime now = DateTime.now();
final DateTime date = DateTime.fromMillisecondsSinceEpoch(this!);

final Duration diff = now.difference(date);

if (diff.inSeconds < 60) {
return "just now";
} else if (diff.inMinutes < 60) {
return "${diff.inMinutes} minutes ago";
} else if (diff.inHours < 24) {
return "${diff.inHours} hours ago";
} else if (diff.inDays < 7) {
return "${diff.inDays} days ago";
} else if (diff.inDays < 30) {
return "${diff.inDays ~/ 7} weeks ago";
} else if (diff.inDays < 365) {
return "${diff.inDays ~/ 30} months ago";
} else {
return "${diff.inDays ~/ 365} years ago";
}
}
}
3 changes: 2 additions & 1 deletion app/lib/ui/flow/home/home_screen_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class HomeViewNotifier extends StateNotifier<HomeViewState> {
}

void getAllSpace() async {
if (state.loading) return;
try {
state = state.copyWith(loading: state.spaceList.isEmpty);
final spaces = await spaceService.getAllSpaceInfo();
Expand All @@ -51,7 +52,7 @@ class HomeViewNotifier extends StateNotifier<HomeViewState> {
updateSelectedSpace(selectedSpace);
}
} catch (error, stack) {
state = state.copyWith(error: error);
state = state.copyWith(error: error, loading: false);
logger.e(
'HomeViewNotifier: error while getting all spaces',
error: error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:style/animation/on_tap_scale.dart';
import 'package:style/extenstions/context_extenstions.dart';
import 'package:style/text/app_text_dart.dart';
import 'package:yourspace_flutter/domain/extenstions/lat_lng_extenstion.dart';
import 'package:yourspace_flutter/domain/extenstions/time_ago_extenstions.dart';

import '../../../../../gen/assets.gen.dart';
import '../../../../components/user_battery_status.dart';
Expand Down Expand Up @@ -159,7 +160,6 @@ class _SelectedMemberDetailViewState extends State<SelectedMemberDetailView> {
}

Widget _userTimeAgo(int? createdAt) {
final time = timeAgo(createdAt);
return Row(
children: [
Icon(
Expand All @@ -169,39 +169,14 @@ class _SelectedMemberDetailViewState extends State<SelectedMemberDetailView> {
),
const SizedBox(width: 4),
Text(
time,
createdAt.timeAgo(),
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textDisabled),
)
],
);
}

String timeAgo(int? timestamp) {
if (timestamp == null) return "";

final DateTime now = DateTime.now();
final DateTime date = DateTime.fromMillisecondsSinceEpoch(timestamp);

final Duration diff = now.difference(date);

if (diff.inSeconds < 60) {
return "just now";
} else if (diff.inMinutes < 60) {
return "${diff.inMinutes} minutes ago";
} else if (diff.inHours < 24) {
return "${diff.inHours} hours ago";
} else if (diff.inDays < 7) {
return "${diff.inDays} days ago";
} else if (diff.inDays < 30) {
return "${diff.inDays ~/ 7} weeks ago";
} else if (diff.inDays < 365) {
return "${diff.inDays ~/ 30} months ago";
} else {
return "${diff.inDays ~/ 365} years ago";
}
}

void getAddress(ApiLocation? location) async {
if (location != null) {
final latLng = LatLng(location.latitude, location.longitude);
Expand Down
5 changes: 1 addition & 4 deletions app/lib/ui/flow/home/map/components/space_user_footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class _SpaceUserFooterState extends State<SpaceUserFooter> {
child: Column(
children: [
_mapControlBtn(context),

AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder: (Widget child, Animation<double> animation) {
Expand All @@ -56,9 +55,7 @@ class _SpaceUserFooterState extends State<SpaceUserFooter> {
begin: const Offset(0.0, 1.0),
end: const Offset(0.0, 0.0),
).animate(animation),
child: ScaleTransition(
scale: animation,
child: child),
child: ScaleTransition(scale: animation, child: child),
);
},
child: widget.selectedUser != null
Expand Down
1 change: 1 addition & 0 deletions app/lib/ui/flow/home/map/map_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MapViewNotifier extends StateNotifier<MapViewState> {
}

void listenMemberLocation(String spaceId) async {
if (state.loading) return;
try {
state = state.copyWith(loading: true, selectedUser: null);
spaceService.getMemberWithLocation(spaceId).listen((userInfo) {
Expand Down
50 changes: 25 additions & 25 deletions data/.flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# This is a generated file; do not edit or check into version control.
cloud_firestore=/Users/ishita/.pub-cache/hosted/pub.dev/cloud_firestore-4.17.5/
cloud_firestore_web=/Users/ishita/.pub-cache/hosted/pub.dev/cloud_firestore_web-3.12.5/
cloud_functions=/Users/ishita/.pub-cache/hosted/pub.dev/cloud_functions-4.7.6/
cloud_functions_web=/Users/ishita/.pub-cache/hosted/pub.dev/cloud_functions_web-4.9.6/
device_info_plus=/Users/ishita/.pub-cache/hosted/pub.dev/device_info_plus-9.1.2/
firebase_auth=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_auth-4.20.0/
firebase_auth_web=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_auth_web-5.12.0/
firebase_core=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_core-2.32.0/
firebase_core_web=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_core_web-2.17.1/
firebase_storage=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_storage-11.7.7/
firebase_storage_web=/Users/ishita/.pub-cache/hosted/pub.dev/firebase_storage_web-3.9.7/
flutter_timezone=/Users/ishita/.pub-cache/hosted/pub.dev/flutter_timezone-1.0.8/
google_sign_in=/Users/ishita/.pub-cache/hosted/pub.dev/google_sign_in-6.2.1/
google_sign_in_android=/Users/ishita/.pub-cache/hosted/pub.dev/google_sign_in_android-6.1.23/
google_sign_in_ios=/Users/ishita/.pub-cache/hosted/pub.dev/google_sign_in_ios-5.7.6/
google_sign_in_web=/Users/ishita/.pub-cache/hosted/pub.dev/google_sign_in_web-0.12.3+3/
package_info_plus=/Users/ishita/.pub-cache/hosted/pub.dev/package_info_plus-8.0.0/
path_provider_linux=/Users/ishita/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/Users/ishita/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
shared_preferences=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences-2.2.3/
shared_preferences_android=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.2/
shared_preferences_foundation=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.4.0/
shared_preferences_linux=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/
shared_preferences_web=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences_web-2.3.0/
shared_preferences_windows=/Users/ishita/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/
cloud_firestore=/home/kaushik/.pub-cache/hosted/pub.dev/cloud_firestore-4.17.5/
cloud_firestore_web=/home/kaushik/.pub-cache/hosted/pub.dev/cloud_firestore_web-3.12.5/
cloud_functions=/home/kaushik/.pub-cache/hosted/pub.dev/cloud_functions-4.7.6/
cloud_functions_web=/home/kaushik/.pub-cache/hosted/pub.dev/cloud_functions_web-4.9.6/
device_info_plus=/home/kaushik/.pub-cache/hosted/pub.dev/device_info_plus-9.1.2/
firebase_auth=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_auth-4.20.0/
firebase_auth_web=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_auth_web-5.12.0/
firebase_core=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_core-2.32.0/
firebase_core_web=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_core_web-2.17.1/
firebase_storage=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_storage-11.7.7/
firebase_storage_web=/home/kaushik/.pub-cache/hosted/pub.dev/firebase_storage_web-3.9.7/
flutter_timezone=/home/kaushik/.pub-cache/hosted/pub.dev/flutter_timezone-1.0.8/
google_sign_in=/home/kaushik/.pub-cache/hosted/pub.dev/google_sign_in-6.2.1/
google_sign_in_android=/home/kaushik/.pub-cache/hosted/pub.dev/google_sign_in_android-6.1.24/
google_sign_in_ios=/home/kaushik/.pub-cache/hosted/pub.dev/google_sign_in_ios-5.7.6/
google_sign_in_web=/home/kaushik/.pub-cache/hosted/pub.dev/google_sign_in_web-0.12.4/
package_info_plus=/home/kaushik/.pub-cache/hosted/pub.dev/package_info_plus-8.0.0/
path_provider_linux=/home/kaushik/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/home/kaushik/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
shared_preferences=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences-2.2.3/
shared_preferences_android=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.3/
shared_preferences_foundation=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.4.0/
shared_preferences_linux=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/
shared_preferences_web=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences_web-2.3.0/
shared_preferences_windows=/home/kaushik/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/
2 changes: 1 addition & 1 deletion data/.flutter-plugins-dependencies

Large diffs are not rendered by default.

0 comments on commit 71e5c78

Please sign in to comment.