RoyAalekh commited on
Commit
fa7e64a
·
1 Parent(s): 7d76d05

Fix tree edit functionality and improve popup close button positioning

Browse files

- Fix edit tree flow from map tooltips to main form
- Add checkForEditTree() to automatically load trees for editing from localStorage
- Simplify map.js editTree method to just store ID and redirect
- Fix Leaflet popup close button positioning with proper CSS
- Update service worker cache version to force asset refresh
- Update cache timestamps for map.js to ensure latest version delivery

Fixes the 'error fetching tree data' issue when editing trees from map view.
Users can now seamlessly edit trees directly from map marker popups.

Files changed (4) hide show
  1. static/js/tree-track-app.js +19 -0
  2. static/map.html +40 -1
  3. static/map.js +10 -11
  4. static/sw.js +1 -1
static/js/tree-track-app.js CHANGED
@@ -112,11 +112,30 @@ export class TreeTrackApp {
112
 
113
  async loadInitialData() {
114
  try {
 
 
 
 
115
  await this.loadTrees();
116
  } catch (error) {
117
  console.error('Error loading initial data:', error);
118
  }
119
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  async handleFormSubmit(e) {
122
  e.preventDefault();
 
112
 
113
  async loadInitialData() {
114
  try {
115
+ // Check if we need to load a tree for editing
116
+ await this.checkForEditTree();
117
+
118
+ // Load trees list
119
  await this.loadTrees();
120
  } catch (error) {
121
  console.error('Error loading initial data:', error);
122
  }
123
  }
124
+
125
+ async checkForEditTree() {
126
+ const editTreeId = localStorage.getItem('editTreeId');
127
+ if (editTreeId) {
128
+ // Clear the localStorage item to prevent repeated loads
129
+ localStorage.removeItem('editTreeId');
130
+
131
+ try {
132
+ await this.handleEditTree(parseInt(editTreeId));
133
+ } catch (error) {
134
+ console.error('Error loading tree for edit from localStorage:', error);
135
+ this.uiManager.showMessage('Error loading tree for editing: ' + error.message, 'error');
136
+ }
137
+ }
138
+ }
139
 
140
  async handleFormSubmit(e) {
141
  e.preventDefault();
static/map.html CHANGED
@@ -451,6 +451,7 @@
451
  border-radius: var(--radius-lg);
452
  box-shadow: var(--shadow-xl);
453
  border: 1px solid var(--gray-200);
 
454
  }
455
 
456
  .leaflet-popup-tip {
@@ -461,6 +462,44 @@
461
  .leaflet-popup-content {
462
  margin: 0;
463
  line-height: 1.5;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  }
465
 
466
  /* Tree Popup Content */
@@ -907,7 +946,7 @@
907
 
908
  <!-- Leaflet JS -->
909
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
910
- <script src="/static/map.js?v=4.0.0&t=1754657582"></script>
911
 
912
  <script>
913
  // Initialize Granim background animation on page load
 
451
  border-radius: var(--radius-lg);
452
  box-shadow: var(--shadow-xl);
453
  border: 1px solid var(--gray-200);
454
+ position: relative;
455
  }
456
 
457
  .leaflet-popup-tip {
 
462
  .leaflet-popup-content {
463
  margin: 0;
464
  line-height: 1.5;
465
+ overflow: hidden;
466
+ }
467
+
468
+ /* Fix popup close button positioning */
469
+ .leaflet-popup-close-button {
470
+ position: absolute;
471
+ top: 8px;
472
+ right: 8px;
473
+ z-index: 10;
474
+ background: rgba(255, 255, 255, 0.9);
475
+ color: var(--gray-600);
476
+ border: 1px solid var(--gray-300);
477
+ border-radius: 50%;
478
+ width: 24px;
479
+ height: 24px;
480
+ display: flex;
481
+ align-items: center;
482
+ justify-content: center;
483
+ font-size: 14px;
484
+ line-height: 1;
485
+ cursor: pointer;
486
+ transition: all 0.15s ease;
487
+ text-decoration: none;
488
+ font-weight: 400;
489
+ box-shadow: var(--shadow-sm);
490
+ }
491
+
492
+ .leaflet-popup-close-button:hover {
493
+ background: white;
494
+ color: var(--gray-800);
495
+ border-color: var(--gray-400);
496
+ box-shadow: var(--shadow-md);
497
+ transform: scale(1.05);
498
+ }
499
+
500
+ .leaflet-popup-close-button:focus {
501
+ outline: 2px solid var(--primary-500);
502
+ outline-offset: 2px;
503
  }
504
 
505
  /* Tree Popup Content */
 
946
 
947
  <!-- Leaflet JS -->
948
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
949
+ <script src="/static/map.js?v=4.0.1&t=1754657800"></script>
950
 
951
  <script>
952
  // Initialize Granim background animation on page load
static/map.js CHANGED
@@ -689,26 +689,25 @@ class TreeTrackMap {
689
  // Tree management methods
690
  async editTree(treeId) {
691
  try {
692
- const response = await this.authenticatedFetch(`/api/trees/${treeId}`);
693
- if (!response) return;
694
-
695
- if (!response.ok) {
696
- throw new Error('Failed to fetch tree data');
697
  }
698
 
699
  // Store tree ID in localStorage for the form
700
- localStorage.setItem('editTreeId', treeId);
701
 
702
- this.showMessage('Loading tree for editing...', 'success');
703
 
704
- // Redirect to form page
705
  setTimeout(() => {
706
  window.location.href = '/';
707
- }, 1000);
708
 
709
  } catch (error) {
710
- console.error('Error loading tree for edit:', error);
711
- this.showMessage('Error loading tree data: ' + error.message, 'error');
712
  }
713
  }
714
 
 
689
  // Tree management methods
690
  async editTree(treeId) {
691
  try {
692
+ // Check if user has permission to edit (basic check)
693
+ if (!this.currentUser) {
694
+ this.showMessage('Authentication required', 'error');
695
+ return;
 
696
  }
697
 
698
  // Store tree ID in localStorage for the form
699
+ localStorage.setItem('editTreeId', treeId.toString());
700
 
701
+ this.showMessage('Redirecting to form for editing...', 'success');
702
 
703
+ // Redirect to form page immediately
704
  setTimeout(() => {
705
  window.location.href = '/';
706
+ }, 500);
707
 
708
  } catch (error) {
709
+ console.error('Error setting up tree for edit:', error);
710
+ this.showMessage('Error preparing tree for editing: ' + error.message, 'error');
711
  }
712
  }
713
 
static/sw.js CHANGED
@@ -1,5 +1,5 @@
1
  // TreeTrack Service Worker - PWA and Offline Support
2
- const VERSION = 1734826222; // Cache busting - updated for location panel button fix & Granim improvements
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 = 1754657700; // Cache busting - updated for popup close button fix, Granim improvements, and full viewport coverage
3
  const CACHE_NAME = `treetrack-v${VERSION}`;
4
  const STATIC_CACHE = `static-v${VERSION}`;
5
  const API_CACHE = `api-v${VERSION}`;