Skip to content

Commit

Permalink
fix timing, bump spec
Browse files Browse the repository at this point in the history
  • Loading branch information
joshreisner committed Dec 22, 2023
1 parent d468122 commit fc81de4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"typescript": "^5.0.4"
},
"dependencies": {
"@code4recovery/spec": "^1.0.3",
"@code4recovery/spec": "^1.0.5",
"@emotion/react": "^11.11.1",
"deepmerge": "^4.3.1",
"luxon": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions public/app.js

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions src/helpers/calculate-distances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ import { flattenAndSortIndexes } from './flatten-and-sort-indexes';
import { formatString as i18n } from './format-string';

//calculate distances
export function calculateDistances(
filteredSlugs: string[],
latitude: number,
longitude: number,
setState: (state: State) => void,
state: State,
settings: TSMLReactConfig,
strings: Translation
) {
export function calculateDistances({
latitude,
longitude,
setState,
settings,
state,
strings,
}: {
latitude: number;
longitude: number;
setState: (state: State) => void;
settings: TSMLReactConfig;
state: State;
strings: Translation;
}) {
const slugs = Object.keys(state.meetings);
if (!slugs.length) return;

//build new index and meetings array
const distances: {
[index: string]: Index;
Expand All @@ -31,7 +40,7 @@ export function calculateDistances(
});

//loop through and update or clear distances, and rebuild index
filteredSlugs.forEach(slug => {
slugs.forEach(slug => {
const distance = getDistance(
{ latitude, longitude },
state.meetings[slug],
Expand Down
26 changes: 12 additions & 14 deletions src/helpers/filter-meeting-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,29 @@ export function filterMeetingData(
.then(result => {
if (result.features && result.features.length) {
//re-render page with new params
calculateDistances(
filteredSlugs,
result.features[0].center[1],
result.features[0].center[0],
calculateDistances({
latitude: result.features[0].center[1],
longitude: result.features[0].center[0],
setState,
state,
settings,
strings
);
state,
strings,
});
} else {
//show error
}
});
} else if (state.input.mode === 'me') {
navigator.geolocation.getCurrentPosition(
position => {
calculateDistances(
filteredSlugs,
position.coords.latitude,
position.coords.longitude,
calculateDistances({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
setState,
state,
settings,
strings
);
state,
strings,
});
},
error => {
console.warn(`TSML UI geolocation error: ${error.message}`);
Expand Down

0 comments on commit fc81de4

Please sign in to comment.