Skip to content

Commit

Permalink
fix deleted elements in activity feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Jan 22, 2024
1 parent 93023e2 commit 3152c0f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
11 changes: 11 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ export const updateChartThemes = (
});
}
};

export const formatElementID = (id: string) => {
const elementIdSplit = id.split(':');
const elementIdFormatted =
elementIdSplit[0].charAt(0).toUpperCase() +
elementIdSplit[0].slice(1, elementIdSplit[0].length) +
' ' +
elementIdSplit[1];

return elementIdFormatted;
};
30 changes: 14 additions & 16 deletions src/routes/activity/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
users
} from '$lib/store';
import type { ActivityEvent, Element, Event, User } from '$lib/types';
import { detectTheme, errToast } from '$lib/utils';
import { detectTheme, errToast, formatElementID } from '$lib/utils';
// alert for user errors
$: $userError && errToast($userError);
Expand Down Expand Up @@ -56,21 +56,19 @@
recentEvents.forEach((event) => {
let elementMatch = elements.find((element) => element.id === event['element_id']);
if (elementMatch) {
let location =
elementMatch['osm_json'].tags && elementMatch['osm_json'].tags.name
? elementMatch['osm_json'].tags.name
: undefined;
let tagger = findUser(event);
supertaggers.push({
...event,
location: location || 'Unnamed element',
merchantId: elementMatch.id,
tagger
});
}
let location =
elementMatch?.['osm_json'].tags && elementMatch['osm_json'].tags.name
? elementMatch['osm_json'].tags.name
: undefined;
let tagger = findUser(event);
supertaggers.push({
...event,
location: location || formatElementID(event['element_id']),
merchantId: event['element_id'],
tagger
});
});
supertaggers = supertaggers;
Expand Down
20 changes: 9 additions & 11 deletions src/routes/community/[area]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
type Leaflet,
type User
} from '$lib/types.js';
import { detectTheme, errToast, updateChartThemes } from '$lib/utils';
import { detectTheme, errToast, formatElementID, updateChartThemes } from '$lib/utils';
// @ts-expect-error
import rewind from '@mapbox/geojson-rewind';
import Chart from 'chart.js/auto';
Expand Down Expand Up @@ -181,18 +181,16 @@
communityEvents.forEach((event) => {
let elementMatch = filteredElements.find((element) => element.id === event['element_id']);
if (elementMatch) {
let location = elementMatch['osm_json'].tags?.name || undefined;
let location = elementMatch?.['osm_json'].tags?.name || undefined;
let tagger = findUser(event);
let tagger = findUser(event);
eventElements.push({
...event,
location: location || 'Unnamed element',
merchantId: elementMatch.id,
tagger
});
}
eventElements.push({
...event,
location: location || formatElementID(event['element_id']),
merchantId: event['element_id'],
tagger
});
});
eventElements = eventElements;
Expand Down
22 changes: 10 additions & 12 deletions src/routes/tagger/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
type Leaflet,
type ProfileLeaderboard
} from '$lib/types.js';
import { detectTheme, errToast } from '$lib/utils';
import { detectTheme, errToast, formatElementID } from '$lib/utils';
import Chart from 'chart.js/auto';
import { format } from 'date-fns';
import DOMPurify from 'dompurify';
Expand Down Expand Up @@ -278,18 +278,16 @@
userEvents.forEach((event) => {
let elementMatch = $elements.find((element) => element.id === event['element_id']);
if (elementMatch) {
let location =
elementMatch['osm_json'].tags && elementMatch['osm_json'].tags.name
? elementMatch['osm_json'].tags.name
: undefined;
let location =
elementMatch?.['osm_json'].tags && elementMatch['osm_json'].tags.name
? elementMatch['osm_json'].tags.name
: undefined;
eventElements.push({
...event,
location: location || 'Unnamed element',
merchantId: elementMatch.id
});
}
eventElements.push({
...event,
location: location || formatElementID(event['element_id']),
merchantId: event['element_id']
});
});
eventElements = eventElements;
Expand Down

0 comments on commit 3152c0f

Please sign in to comment.