RoyAalekh commited on
Commit
a6bca2b
Β·
1 Parent(s): f4d4875

EMERGENCY FIX: Restore working map by removing broken ES6 module imports

Browse files

🚨 Critical Issues Fixed:
- Removed broken ES6 import statements that caused map to freeze
- Restored traditional script loading in map.html
- Fixed map tree loading with working batch mechanism
- Temporarily disabled background data service to prevent module errors

πŸ› Root Problems Identified:
- Mixed ES6 modules + traditional scripts don't work without proper setup
- Import statements were breaking JavaScript execution
- Background loading was working but map couldn't render trees
- Module loading paradigm was inconsistent across the app

βœ… Map Now Works:
- Trees load and display properly with clustering
- Spiderfy spiral view restored and functional
- Proper zoom levels maintained (15 initial, 17 max)
- All clustering behavior preserved

⚠️ Technical Debt:
- Background data service code still exists but disabled
- Need proper module architecture for future optimization
- Authentication works, tree loading works, map functional

static/index.html CHANGED
@@ -947,7 +947,7 @@
947
  // Force refresh if we detect cached version
948
  (function() {
949
  const currentVersion = '5.1.1';
950
- const timestamp = '1761507628'; // Cache-busting bump
951
  const lastVersion = sessionStorage.getItem('treetrack_version');
952
  const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
953
 
@@ -1193,7 +1193,7 @@
1193
  </div>
1194
  </div>
1195
 
1196
- <script type="module" src="/static/js/tree-track-app.js?v=5.1.1&t=1761507628"></script>
1197
 
1198
  <script>
1199
  // Idle-time prefetch of map assets to speed up first navigation
 
947
  // Force refresh if we detect cached version
948
  (function() {
949
  const currentVersion = '5.1.1';
950
+ const timestamp = '1761507910'; // Cache-busting bump
951
  const lastVersion = sessionStorage.getItem('treetrack_version');
952
  const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
953
 
 
1193
  </div>
1194
  </div>
1195
 
1196
+ <script type="module" src="/static/js/tree-track-app.js?v=5.1.1&t=1761507910"></script>
1197
 
1198
  <script>
1199
  // Idle-time prefetch of map assets to speed up first navigation
static/js/modules/auth-manager.js CHANGED
@@ -2,7 +2,7 @@
2
  * Authentication Manager Module
3
  * Handles user authentication, session management, and permissions
4
  */
5
- import { backgroundDataService } from './background-data.js';
6
 
7
  export class AuthManager {
8
  constructor() {
@@ -28,15 +28,8 @@ export class AuthManager {
28
  this.currentUser = data.user;
29
  this.authToken = token;
30
 
31
- // Start background data loading immediately after successful auth
32
- try {
33
- backgroundDataService.setAuthToken(token);
34
- backgroundDataService.startPreemptiveLoading().catch(error => {
35
- console.warn('Background data preloading failed:', error);
36
- });
37
- } catch (error) {
38
- console.warn('Failed to start background data loading:', error);
39
- }
40
 
41
  return true;
42
  } else {
@@ -71,12 +64,8 @@ export class AuthManager {
71
  this.currentUser = null;
72
  this.authToken = null;
73
 
74
- // Clear background data cache when user logs out
75
- try {
76
- backgroundDataService.clearCache();
77
- } catch (error) {
78
- console.warn('Failed to clear background data cache:', error);
79
- }
80
  }
81
 
82
  canEditTree(createdBy) {
 
2
  * Authentication Manager Module
3
  * Handles user authentication, session management, and permissions
4
  */
5
+ // import { backgroundDataService } from './background-data.js'; // Temporarily disabled
6
 
7
  export class AuthManager {
8
  constructor() {
 
28
  this.currentUser = data.user;
29
  this.authToken = token;
30
 
31
+ // Background data loading temporarily disabled
32
+ console.log('βœ… Authentication successful - background loading disabled for now');
 
 
 
 
 
 
 
33
 
34
  return true;
35
  } else {
 
64
  this.currentUser = null;
65
  this.authToken = null;
66
 
67
+ // Background data cache clearing temporarily disabled
68
+ console.log('πŸ—‘οΈ Auth data cleared');
 
 
 
 
69
  }
70
 
71
  canEditTree(createdBy) {
static/map.html CHANGED
@@ -928,7 +928,7 @@
928
  // Force refresh if we detect cached version
929
  (function() {
930
  const currentVersion = '5.1.1';
931
- const timestamp = '1761507628'; // Current timestamp for cache busting
932
  const lastVersion = sessionStorage.getItem('treetrack_version');
933
  const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
934
 
@@ -1081,14 +1081,9 @@ const timestamp = '1761507628'; // Current timestamp for cache busting
1081
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
1082
  <!-- Leaflet MarkerCluster JS for performance and grouping -->
1083
  <script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
1084
- <script type="module">
1085
- // Import and initialize the map with background data service
1086
- import('./map.js?v=5.1.1&t=1761507058').then(module => {
1087
- // Map initialization is handled in the module
1088
- console.log('πŸ—ΊοΈ Map module loaded with background data service');
1089
- }).catch(error => {
1090
- console.error('❌ Failed to load map module:', error);
1091
- });
1092
  </script>
1093
  </body>
1094
  </html>
 
928
  // Force refresh if we detect cached version
929
  (function() {
930
  const currentVersion = '5.1.1';
931
+ const timestamp = '1761507910'; // Current timestamp for cache busting
932
  const lastVersion = sessionStorage.getItem('treetrack_version');
933
  const lastTimestamp = sessionStorage.getItem('treetrack_timestamp');
934
 
 
1081
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
1082
  <!-- Leaflet MarkerCluster JS for performance and grouping -->
1083
  <script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
1084
+ <script src="/static/map.js?v=5.1.1&t=1761507910"></script>
1085
+ <script>
1086
+ console.log('πŸ—ΊοΈ Map script loaded successfully');
 
 
 
 
 
1087
  </script>
1088
  </body>
1089
  </html>
static/map.js CHANGED
@@ -1,7 +1,5 @@
1
- // Import background data service
2
- import { backgroundDataService } from './js/modules/background-data.js';
3
-
4
  // TreeTrack Enhanced Map with Authentication and Tree Management
 
5
  class TreeTrackMap {
6
  constructor() {
7
  this.map = null;
@@ -65,11 +63,8 @@ class TreeTrackMap {
65
  this.currentUser = data.user;
66
  this.authToken = token;
67
 
68
- // Start preemptive data loading in background
69
- backgroundDataService.setAuthToken(token);
70
- backgroundDataService.startPreemptiveLoading().catch(error => {
71
- console.warn('Background data loading failed:', error);
72
- });
73
 
74
  return true;
75
  } else {
@@ -623,72 +618,94 @@ class TreeTrackMap {
623
  // Clear existing tree markers
624
  this.clearTreeMarkers();
625
 
626
- // Try to use cached data first
627
- let filteredTrees;
628
- const cachedTrees = backgroundDataService.getCachedTreeData();
 
 
629
 
630
- if (cachedTrees) {
631
- console.log('⚑ Using preloaded tree data from cache');
632
- filteredTrees = cachedTrees;
633
- } else {
634
- // Show loading message
635
- document.getElementById('treeCount').textContent = 'Loading trees...';
636
 
637
- // Wait for background loading or load now
638
- console.log('⏳ Getting tree data (background loading)...');
639
- const allTrees = await backgroundDataService.getTreeData();
640
- filteredTrees = allTrees;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  }
642
 
643
- console.log(`πŸ“Š Processing ${filteredTrees.length} trees for map display`);
 
 
 
 
 
 
 
 
 
644
 
645
  // Add tree markers with optimized batch processing
646
  let loadedCount = 0;
647
- const uiBatchSize = 100; // Increased batch size for faster processing
648
 
649
- // Process all batches immediately for faster loading
650
- const batches = [];
651
  for (let i = 0; i < filteredTrees.length; i += uiBatchSize) {
652
- batches.push(filteredTrees.slice(i, i + uiBatchSize));
653
- }
654
-
655
- // Process batches with minimal delays
656
- for (let batchIndex = 0; batchIndex < batches.length; batchIndex++) {
657
- const batch = batches[batchIndex];
658
 
659
- // Use requestAnimationFrame for smoother UI updates
660
- await new Promise(resolve => {
661
- setTimeout(() => {
662
- batch.forEach((tree) => {
663
- try {
664
- this.addTreeMarker(tree);
665
- loadedCount++;
666
- } catch (error) {
667
- console.warn(`Failed to add marker for tree ${tree.id}:`, error);
668
- }
669
- });
 
 
 
 
 
 
 
670
 
671
- // Update progress
672
- document.getElementById('treeCount').textContent = `${loadedCount} trees`;
673
- resolve();
674
- }, batchIndex * 10); // Minimal 10ms delays
675
- });
 
 
 
 
 
 
676
  }
677
 
678
- console.log(`πŸŽ‰ Map loading complete: ${loadedCount} tree markers added`);
679
- this.showMessage(`Loaded ${loadedCount} trees successfully`, 'success');
680
-
681
- // Auto-center on trees with exact same view as center button
682
- setTimeout(() => {
683
- if (loadedCount > 0) {
684
- const group = new L.featureGroup(this.treeMarkers);
685
- const bounds = group.getBounds();
686
- // Use same settings as centerMapToTrees for consistency
687
- this.map.fitBounds(bounds.pad(0.1), { maxZoom: 15 });
688
- console.log('🎯 Map auto-centered to match center view exactly');
689
- }
690
- }, 100); // Reduced delay since loading is faster
691
-
692
  } catch (error) {
693
  console.error('❌ Error loading trees:', error);
694
  this.showMessage('Failed to load trees. Please refresh the page.', 'error');
 
 
 
 
1
  // TreeTrack Enhanced Map with Authentication and Tree Management
2
+ // Note: Background data service integration temporarily disabled due to module loading issues
3
  class TreeTrackMap {
4
  constructor() {
5
  this.map = null;
 
63
  this.currentUser = data.user;
64
  this.authToken = token;
65
 
66
+ // Background data loading temporarily disabled
67
+ console.log('βœ… Authentication successful, map ready to load trees');
 
 
 
68
 
69
  return true;
70
  } else {
 
618
  // Clear existing tree markers
619
  this.clearTreeMarkers();
620
 
621
+ // Load trees in batches (restored simple approach)
622
+ let allTrees = [];
623
+ let offset = 0;
624
+ const batchSize = 1000; // API batch size (Supabase limit)
625
+ let hasMoreTrees = true;
626
 
627
+ console.log('πŸ“Š Loading trees in batches...');
628
+ document.getElementById('treeCount').textContent = 'Loading trees...';
629
+
630
+ while (hasMoreTrees && allTrees.length < 3000) { // Safety limit
631
+ console.log(`πŸ“₯ Loading batch: offset=${offset}, limit=${batchSize}`);
 
632
 
633
+ const response = await this.authenticatedFetch(`/api/trees?limit=${batchSize}&offset=${offset}`);
634
+ if (!response) {
635
+ console.error('❌ Failed to fetch batch');
636
+ break;
637
+ }
638
+
639
+ const batchTrees = await response.json();
640
+ console.log(`βœ… Loaded batch: ${batchTrees.length} trees`);
641
+
642
+ if (batchTrees.length === 0) {
643
+ hasMoreTrees = false;
644
+ break;
645
+ }
646
+
647
+ allTrees = allTrees.concat(batchTrees);
648
+ offset += batchSize;
649
+
650
+ // If we got less than the batch size, we've reached the end
651
+ if (batchTrees.length < batchSize) {
652
+ hasMoreTrees = false;
653
+ }
654
+
655
+ // Update progress
656
+ document.getElementById('treeCount').textContent = `${allTrees.length} trees loaded...`;
657
  }
658
 
659
+ // Filter out specific trees (e.g., ID 18 as requested)
660
+ const filteredTrees = allTrees.filter(tree => {
661
+ if (tree.id === 18) {
662
+ console.log('πŸ”„ Excluding tree ID 18 from display');
663
+ return false;
664
+ }
665
+ return true;
666
+ });
667
+
668
+ console.log(`πŸ“Š Total trees to display: ${filteredTrees.length}`);
669
 
670
  // Add tree markers with optimized batch processing
671
  let loadedCount = 0;
672
+ const uiBatchSize = 100; // UI batch size for smooth rendering
673
 
 
 
674
  for (let i = 0; i < filteredTrees.length; i += uiBatchSize) {
675
+ const batch = filteredTrees.slice(i, i + uiBatchSize);
 
 
 
 
 
676
 
677
+ // Process batch with small delay to prevent UI blocking
678
+ setTimeout(() => {
679
+ batch.forEach((tree) => {
680
+ try {
681
+ this.addTreeMarker(tree);
682
+ loadedCount++;
683
+ } catch (error) {
684
+ console.warn(`Failed to add marker for tree ${tree.id}:`, error);
685
+ }
686
+ });
687
+
688
+ // Update progress
689
+ document.getElementById('treeCount').textContent = `${loadedCount} trees`;
690
+
691
+ // If this is the last batch, finalize
692
+ if (i + uiBatchSize >= filteredTrees.length) {
693
+ console.log(`πŸŽ‰ Map loading complete: ${loadedCount} tree markers added`);
694
+ this.showMessage(`Loaded ${loadedCount} trees successfully`, 'success');
695
 
696
+ // Auto-center on trees with clustering view
697
+ setTimeout(() => {
698
+ if (loadedCount > 0) {
699
+ const group = new L.featureGroup(this.treeMarkers);
700
+ const bounds = group.getBounds();
701
+ this.map.fitBounds(bounds.pad(0.1), { maxZoom: 15 });
702
+ console.log('🎯 Map auto-centered with clustering view');
703
+ }
704
+ }, 100);
705
+ }
706
+ }, (i / uiBatchSize) * 50); // Stagger UI batches by 50ms
707
  }
708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
  } catch (error) {
710
  console.error('❌ Error loading trees:', error);
711
  this.showMessage('Failed to load trees. Please refresh the page.', 'error');
static/sw.js CHANGED
@@ -1,5 +1,5 @@
1
  // TreeTrack Service Worker - PWA and Offline Support
2
- const VERSION = 1761507628; // Cache busting bump - force clients to fetch new static assets and header image change
3
  const CACHE_NAME = `treetrack-v${VERSION}`;
4
  const STATIC_CACHE = `static-v${VERSION}`;
5
  const API_CACHE = `api-v${VERSION}`;
 
1
  // TreeTrack Service Worker - PWA and Offline Support
2
+ const VERSION = 1761507910; // Cache busting bump - force clients to fetch new static assets and header image change
3
  const CACHE_NAME = `treetrack-v${VERSION}`;
4
  const STATIC_CACHE = `static-v${VERSION}`;
5
  const API_CACHE = `api-v${VERSION}`;
version.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
  "version": "5.1.1",
3
- "timestamp": 1761507628
4
  }
 
1
  {
2
  "version": "5.1.1",
3
+ "timestamp": 1761507910
4
  }