...
This commit is contained in:
@@ -36,8 +36,10 @@ class GamificationProvider extends ChangeNotifier {
|
||||
// Load everything at once (called when ContributeScreen or ProfileScreen mounts)
|
||||
// ---------------------------------------------------------------------------
|
||||
Future<void> loadAll({bool force = false}) async {
|
||||
// Skip if recently loaded (within 2 minutes) unless forced
|
||||
if (!force && _lastLoadTime != null && DateTime.now().difference(_lastLoadTime!) < _loadTtl) {
|
||||
debugPrint('GamificationProvider.loadAll(force: $force) called');
|
||||
// Skip if recently loaded (within 2 minutes) unless forced or profile is null
|
||||
if (!force && profile != null && _lastLoadTime != null && DateTime.now().difference(_lastLoadTime!) < _loadTtl) {
|
||||
debugPrint('GamificationProvider.loadAll skipped due to TTL');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,10 +48,20 @@ class GamificationProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
debugPrint('GamificationProvider: Requesting dashboard, leaderboard, etc...');
|
||||
final results = await Future.wait([
|
||||
_service.getDashboard().catchError((e) {
|
||||
debugPrint('Dashboard error: $e');
|
||||
return const DashboardResponse(profile: UserGamificationProfile(userId: '', lifetimeEp: 0, currentEp: 0, currentRp: 0, tier: ContributorTier.BRONZE));
|
||||
return const DashboardResponse(
|
||||
profile: UserGamificationProfile(
|
||||
userId: '',
|
||||
username: '',
|
||||
lifetimeEp: 0,
|
||||
currentEp: 0,
|
||||
currentRp: 0,
|
||||
tier: ContributorTier.BRONZE,
|
||||
),
|
||||
);
|
||||
}),
|
||||
_service.getLeaderboard(district: leaderboardDistrict, timePeriod: leaderboardTimePeriod).catchError((e) {
|
||||
debugPrint('Leaderboard error: $e');
|
||||
@@ -179,6 +191,10 @@ class GamificationProvider extends ChangeNotifier {
|
||||
if (profile != null) {
|
||||
profile = UserGamificationProfile(
|
||||
userId: profile!.userId,
|
||||
username: profile!.username,
|
||||
avatarUrl: profile!.avatarUrl,
|
||||
district: profile!.district,
|
||||
eventifyId: profile!.eventifyId,
|
||||
lifetimeEp: profile!.lifetimeEp,
|
||||
currentEp: profile!.currentEp,
|
||||
currentRp: profile!.currentRp - item.rpCost,
|
||||
@@ -195,6 +211,10 @@ class GamificationProvider extends ChangeNotifier {
|
||||
if (profile != null) {
|
||||
profile = UserGamificationProfile(
|
||||
userId: profile!.userId,
|
||||
username: profile!.username,
|
||||
avatarUrl: profile!.avatarUrl,
|
||||
district: profile!.district,
|
||||
eventifyId: profile!.eventifyId,
|
||||
lifetimeEp: profile!.lifetimeEp,
|
||||
currentEp: profile!.currentEp,
|
||||
currentRp: profile!.currentRp + item.rpCost,
|
||||
|
||||
Reference in New Issue
Block a user