From a303f5c30cf34015d80d2abf2eed833cf4447174 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 24 Mar 2024 20:51:12 +0800 Subject: [PATCH] :bug: Fix and optimize something --- ios/Runner.xcodeproj/project.pbxproj | 6 +++--- lib/auth.dart | 9 ++++++++- lib/widgets/posts/reactions.dart | 30 +++++++++++++++++----------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ed0cfc6..a2375d8 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -477,7 +477,7 @@ DEVELOPMENT_TEAM = W7HPZ53V6B; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = SolarAgent; + INFOPLIST_KEY_CFBundleDisplayName = Solian; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -666,7 +666,7 @@ DEVELOPMENT_TEAM = W7HPZ53V6B; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = SolarAgent; + INFOPLIST_KEY_CFBundleDisplayName = Solian; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -693,7 +693,7 @@ DEVELOPMENT_TEAM = W7HPZ53V6B; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = SolarAgent; + INFOPLIST_KEY_CFBundleDisplayName = Solian; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/lib/auth.dart b/lib/auth.dart index b31f971..0917f59 100644 --- a/lib/auth.dart +++ b/lib/auth.dart @@ -27,6 +27,7 @@ class AuthGuard { static const profileKey = "profiles"; oauth2.Client? client; + DateTime? lastRefreshedAt; Future pickClient() async { if (await storage.containsKey(key: storageKey)) { @@ -110,7 +111,13 @@ class AuthGuard { const storage = FlutterSecureStorage(); if (await storage.containsKey(key: storageKey)) { if (client != null) { - await refreshToken(); + if (lastRefreshedAt == null || + lastRefreshedAt! + .add(const Duration(minutes: 3)) + .isAfter(DateTime.now())) { + await refreshToken(); + lastRefreshedAt = DateTime.now(); + } } return true; } else { diff --git a/lib/widgets/posts/reactions.dart b/lib/widgets/posts/reactions.dart index 46b5040..9b06297 100644 --- a/lib/widgets/posts/reactions.dart +++ b/lib/widgets/posts/reactions.dart @@ -74,8 +74,18 @@ class _ReactionListState extends State { ); if (res.statusCode == 201) { widget.onReact(symbol, 1); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text("Your reaction has been added onto this post."), + ), + ); } else if (res.statusCode == 204) { widget.onReact(symbol, -1); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text("Your reaction has been removed from this post."), + ), + ); } else { var message = utf8.decode(res.bodyBytes); ScaffoldMessenger.of(context).showSnackBar( @@ -105,10 +115,7 @@ class _ReactionListState extends State { ), child: Text( 'Reactions', - style: Theme - .of(context) - .textTheme - .headlineSmall, + style: Theme.of(context).textTheme.headlineSmall, ), ), FutureBuilder( @@ -119,7 +126,7 @@ class _ReactionListState extends State { icon: const Icon(Icons.add_reaction), label: const Text("REACT"), onPressed: - isSubmitting ? null : () => viewReactMenu(context), + isSubmitting ? null : () => viewReactMenu(context), ); } else { return Container(); @@ -141,17 +148,16 @@ class _ReactionListState extends State { onTap: isSubmitting ? null : () { - doReact( - element.key, - ReactionList.emojis[element.key]!['attitude'], - ); - }, + doReact( + element.key, + ReactionList.emojis[element.key]!['attitude'], + ); + }, child: Container( padding: const EdgeInsets.symmetric(horizontal: 6.0), child: ListTile( title: Text( - "${ReactionList.emojis[element.key]!['icon']} x${element - .value.toString()}", + "${ReactionList.emojis[element.key]!['icon']} x${element.value.toString()}", ), subtitle: Text( ":${element.key}:",