Skip to content

Commit ee0f104

Browse files
authored
UX: Refactor position dialog #465 photoprism#5082
* Places: Use $nextTick for state updates * Places: Refactor duplicate code
1 parent a30c04b commit ee0f104

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

frontend/src/component/position/dialog.vue

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
item-value="id"
5757
return-object
5858
auto-select-first
59-
clear-on-select
6059
clearable
6160
autocomplete="off"
6261
no-filter
@@ -267,16 +266,7 @@ export default {
267266
this.cleanupMap();
268267
this.locationInfo = null;
269268
this.locationInfoLoading = false;
270-
271-
// Clear search state
272-
this.searchQuery = "";
273-
this.searchResults = [];
274-
this.searchLoading = false;
275-
this.selectedPlace = null;
276-
if (this.searchTimeout) {
277-
clearTimeout(this.searchTimeout);
278-
this.searchTimeout = null;
279-
}
269+
this.resetSearchState();
280270
},
281271
initMap() {
282272
if (this.map || !this.$refs.map) {
@@ -334,10 +324,7 @@ export default {
334324
});
335325
336326
this.map.on("click", (e) => {
337-
this.currentLat = e.lngLat.lat;
338-
this.currentLng = e.lngLat.lng;
339-
this.updatePosition(e.lngLat.lat, e.lngLat.lng);
340-
this.fetchLocationInfo(e.lngLat.lat, e.lngLat.lng);
327+
this.setPositionAndFetchInfo(e.lngLat.lat, e.lngLat.lng);
341328
});
342329
} catch (error) {
343330
console.error("map: initialization failed", error);
@@ -381,9 +368,7 @@ export default {
381368
// Update coordinates when marker is dragged
382369
this.marker.on("dragend", () => {
383370
const lngLat = this.marker.getLngLat();
384-
this.currentLat = lngLat.lat;
385-
this.currentLng = lngLat.lng;
386-
this.fetchLocationInfo(lngLat.lat, lngLat.lng);
371+
this.setPositionAndFetchInfo(lngLat.lat, lngLat.lng);
387372
});
388373
}
389374
}
@@ -417,6 +402,28 @@ export default {
417402
}
418403
},
419404
405+
clearSearchTimeout() {
406+
if (this.searchTimeout) {
407+
clearTimeout(this.searchTimeout);
408+
this.searchTimeout = null;
409+
}
410+
},
411+
412+
resetSearchState() {
413+
this.searchQuery = "";
414+
this.searchResults = [];
415+
this.selectedPlace = null;
416+
this.searchLoading = false;
417+
this.clearSearchTimeout();
418+
},
419+
420+
setPositionAndFetchInfo(lat, lng) {
421+
this.currentLat = lat;
422+
this.currentLng = lng;
423+
this.updatePosition(lat, lng);
424+
this.fetchLocationInfo(lat, lng);
425+
},
426+
420427
fetchLocationInfo(lat, lng) {
421428
this.locationInfoLoading = true;
422429
this.$api
@@ -439,11 +446,7 @@ export default {
439446
440447
onSearchQueryChange(query) {
441448
this.searchQuery = query;
442-
443-
if (this.searchTimeout) {
444-
clearTimeout(this.searchTimeout);
445-
this.searchTimeout = null;
446-
}
449+
this.clearSearchTimeout();
447450
448451
if (!query || query.length < 2) {
449452
this.searchResults = [];
@@ -491,22 +494,15 @@ export default {
491494
},
492495
onPlaceSelected(place) {
493496
if (place && place.lat && place.lng) {
494-
this.currentLat = place.lat;
495-
this.currentLng = place.lng;
496-
this.updatePosition(place.lat, place.lng);
497-
this.fetchLocationInfo(place.lat, place.lng);
498-
this.clearSearch();
499-
this.searchLoading = false;
500-
if (this.searchTimeout) {
501-
clearTimeout(this.searchTimeout);
502-
this.searchTimeout = null;
503-
}
497+
this.setPositionAndFetchInfo(place.lat, place.lng);
498+
499+
this.$nextTick(() => {
500+
this.resetSearchState();
501+
});
504502
}
505503
},
506504
clearSearch() {
507-
this.searchQuery = "";
508-
this.searchResults = [];
509-
this.selectedPlace = null;
505+
this.resetSearchState();
510506
},
511507
},
512508
};

0 commit comments

Comments
 (0)