mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-02-12 16:52:51 +00:00
Fix fetching and loading indicator in sandbox
This commit is contained in:
@@ -115,6 +115,7 @@ cp lib/keys.dart.example lib/keys.dart
|
||||
- Add ability to downvote suspected locations which are old enough
|
||||
- Turn by turn navigation or at least swipe nav sheet up to see a list
|
||||
- Import/Export map providers
|
||||
- Import default profiles from the website to capture changes without pushing an update?
|
||||
|
||||
### Future Features & Wishlist
|
||||
- Tap pending queue item to edit again before submitting
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"2.6.3": {
|
||||
"content": [
|
||||
"• Prevent edit submissions where nothing (location, tags, direction) has been changed"
|
||||
"• Prevent edit submissions where nothing (location, tags, direction) has been changed",
|
||||
"• FIXED: Node data not loading in sandbox mode - improved cache integration and status reporting for development testing"
|
||||
]
|
||||
},
|
||||
"2.6.2": {
|
||||
|
||||
@@ -78,15 +78,79 @@ class NodeDataManager extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle sandbox mode (always fetch from OSM API, no caching)
|
||||
// Handle sandbox mode (always fetch from OSM API, but integrate with cache system for UI)
|
||||
if (uploadMode == UploadMode.sandbox) {
|
||||
debugPrint('[NodeDataManager] Sandbox mode: fetching from OSM API');
|
||||
return fetchOsmApiNodes(
|
||||
bounds: bounds,
|
||||
profiles: profiles,
|
||||
uploadMode: uploadMode,
|
||||
maxResults: 0,
|
||||
);
|
||||
|
||||
// Track user-initiated requests for status reporting
|
||||
final requestKey = '${bounds.hashCode}_${profiles.map((p) => p.id).join('_')}_$uploadMode';
|
||||
|
||||
if (isUserInitiated && _userInitiatedRequests.contains(requestKey)) {
|
||||
debugPrint('[NodeDataManager] Sandbox request already in progress for this area');
|
||||
return _cache.getNodesFor(bounds);
|
||||
}
|
||||
|
||||
// Start status tracking for user-initiated requests
|
||||
if (isUserInitiated) {
|
||||
_userInitiatedRequests.add(requestKey);
|
||||
NetworkStatus.instance.setLoading();
|
||||
debugPrint('[NodeDataManager] Starting user-initiated sandbox request');
|
||||
} else {
|
||||
debugPrint('[NodeDataManager] Starting background sandbox request (no status reporting)');
|
||||
}
|
||||
|
||||
try {
|
||||
final nodes = await fetchOsmApiNodes(
|
||||
bounds: bounds,
|
||||
profiles: profiles,
|
||||
uploadMode: uploadMode,
|
||||
maxResults: 0,
|
||||
);
|
||||
|
||||
// Add nodes to cache for UI integration (even though we don't rely on cache for subsequent fetches)
|
||||
if (nodes.isNotEmpty) {
|
||||
_cache.addOrUpdateNodes(nodes);
|
||||
_cache.markAreaAsFetched(bounds, nodes);
|
||||
} else {
|
||||
// Mark area as fetched even with no nodes so UI knows we've checked this area
|
||||
_cache.markAreaAsFetched(bounds, []);
|
||||
}
|
||||
|
||||
// Update UI
|
||||
notifyListeners();
|
||||
|
||||
// Set success after the next frame renders, but only for user-initiated requests
|
||||
if (isUserInitiated) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
NetworkStatus.instance.setSuccess();
|
||||
});
|
||||
debugPrint('[NodeDataManager] User-initiated sandbox request completed successfully: ${nodes.length} nodes');
|
||||
}
|
||||
|
||||
return nodes;
|
||||
|
||||
} catch (e) {
|
||||
debugPrint('[NodeDataManager] Sandbox fetch failed: $e');
|
||||
|
||||
// Only report errors for user-initiated requests
|
||||
if (isUserInitiated) {
|
||||
if (e is RateLimitError) {
|
||||
NetworkStatus.instance.setRateLimited();
|
||||
} else if (e.toString().contains('timeout')) {
|
||||
NetworkStatus.instance.setTimeout();
|
||||
} else {
|
||||
NetworkStatus.instance.setError();
|
||||
}
|
||||
debugPrint('[NodeDataManager] User-initiated sandbox request failed: $e');
|
||||
}
|
||||
|
||||
// Return whatever we have in cache for this area (likely empty for sandbox)
|
||||
return _cache.getNodesFor(bounds);
|
||||
} finally {
|
||||
if (isUserInitiated) {
|
||||
_userInitiatedRequests.remove(requestKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Production mode: check cache first
|
||||
|
||||
@@ -70,12 +70,18 @@ class NodeRefreshController {
|
||||
}
|
||||
|
||||
final zoom = controller.mapController.camera.zoom;
|
||||
if (zoom < kNodeMinZoomLevel) {
|
||||
// Show a snackbar-style bubble warning
|
||||
// Use the correct minimum zoom level based on upload mode
|
||||
final minZoom = uploadMode == UploadMode.sandbox ? kOsmApiMinZoomLevel : kNodeMinZoomLevel;
|
||||
|
||||
if (zoom < minZoom) {
|
||||
// Show a snackbar-style bubble warning with mode-specific message
|
||||
if (context.mounted) {
|
||||
final message = uploadMode == UploadMode.sandbox
|
||||
? 'Nodes not drawn below zoom level $minZoom in sandbox mode (OSM API limits)'
|
||||
: 'Nodes not drawn below zoom level $minZoom';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Nodes not drawn below zoom level $kNodeMinZoomLevel'),
|
||||
content: Text(message),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user