Skip to content

Commit

Permalink
fix address names not loading
Browse files Browse the repository at this point in the history
'timelineMap' is a Map object, not just a plain { } object. So instead of Object.values() we should use Map.values() - which returns an iterator - but we want to reverse it.
So we have to convert to array, then reverse, and then call forEach to fillLocationNamesOfTrip.

Also, we should ensure that only trips, not places, get passed to fillLocationNamesOfTrip
(since places always have the same locations as the trips surrounding them, the place cards will automatically get their location names filled in)
  • Loading branch information
JGreenlee committed May 21, 2024
1 parent a16bbc0 commit 3aa2ce5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions www/js/diary/LabelTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { fillLocationNamesOfTrip } from './addressNamesHelper';
import { logDebug } from '../plugin/logger';
import { configuredFilters as multilabelConfiguredFilters } from '../survey/multilabel/infinite_scroll_filters';
import { configuredFilters as enketoConfiguredFilters } from '../survey/enketo/infinite_scroll_filters';
import { TimelineEntry } from '../types/diaryTypes';
import { TimelineEntry, isTrip } from '../types/diaryTypes';
import TimelineContext, { LabelTabFilter, TimelineLabelMap } from '../TimelineContext';
import { AppContext } from '../App';
import { subscribe } from '../customEventHandler';
Expand Down Expand Up @@ -58,11 +58,11 @@ const LabelTab = () => {

useEffect(() => {
if (!timelineMap) return;
const tripsRead = Object.values(timelineMap || {});
tripsRead
.slice()
.reverse()
.forEach((trip) => fillLocationNamesOfTrip(trip));
const timelineEntries = Array.from(timelineMap.values());
if (!timelineEntries?.length) return;
timelineEntries.reverse().forEach((entry) => {
if (isTrip(entry)) fillLocationNamesOfTrip(entry);
});
}, [timelineMap]);

function applyFilters(timelineMap, labelMap: TimelineLabelMap) {
Expand Down
3 changes: 2 additions & 1 deletion www/js/diary/addressNamesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function useLocalStorage<T>(key: string, initialValue: T) {

import Bottleneck from 'bottleneck';
import { displayError, logDebug } from '../plugin/logger';
import { CompositeTrip } from '../types/diaryTypes';

let nominatimLimiter = new Bottleneck({ maxConcurrent: 2, minTime: 500 });
export const resetNominatimLimiter = () => {
Expand Down Expand Up @@ -137,7 +138,7 @@ async function fetchNominatimLocName(loc_geojson) {
}

// Schedules nominatim fetches for the start and end locations of a trip
export function fillLocationNamesOfTrip(trip) {
export function fillLocationNamesOfTrip(trip: CompositeTrip) {
nominatimLimiter.schedule(() => fetchNominatimLocName(trip.end_loc));
nominatimLimiter.schedule(() => fetchNominatimLocName(trip.start_loc));
}
Expand Down

0 comments on commit 3aa2ce5

Please sign in to comment.