Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface TSMLReactConfig {
view: 'table' | 'map';
weekday: TSMLReactConfig['weekdays'];
};
distance_options: number[];
distance_unit: 'mi' | 'km';
/** Email addresses for update meeting info button */
feedback_emails: string[];
Expand Down
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/components/Controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ export default function Controls({ state, setState, mapbox }) {
},
input: {
...state.input,
search: '',
mode: mode,
distance: [],
latitude: null,
longitude: null,
mode: mode,
search: '',
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export default function Map({

//manage classes
useEffect(() => {
if (!state.input.meeting) {
if (!state.input?.meeting) {
document.body.classList.add('tsml-ui-map');
}
return () => {
document.body.classList.remove('tsml-ui-map');
};
}, [state.input.meeting]);
}, [state.input?.meeting]);

//reset bounds and locations when filteredSlugs changes
useEffect(() => {
Expand Down
22 changes: 11 additions & 11 deletions src/components/Title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import { getIndexByKey, strings } from '../helpers';

export default function Title({ state }) {
export default function Title({ state: { indexes, input } }) {
//loading
if (!state.indexes || !state.input) return null;
if (!indexes || !input) return null;

//build title from strings.title
const parts = [];
Expand All @@ -14,23 +14,23 @@ export default function Title({ state }) {
parts.push(strings.meetings);
} else if (
key === 'search_with' &&
state.input.mode === 'search' &&
state.input.search
input.mode === 'search' &&
input.search
) {
parts.push(
strings.title.search_with.replace('%search%', `‘${state.input.search}’`)
strings.title.search_with.replace('%search%', `‘${input.search}’`)
);
} else if (
key === 'search_near' &&
state.input.mode === 'location' &&
state.input.search
input.mode === 'location' &&
input.search
) {
parts.push(
strings.title.search_near.replace('%search%', `‘${state.input.search}’`)
strings.title.search_near.replace('%search%', `‘${input.search}’`)
);
} else if (state.indexes[key] && state.input[key]?.length) {
const value = state.input[key]
.map(value => getIndexByKey(state.indexes[key], value)?.name)
} else if (indexes[key] && input[key]?.length) {
const value = input[key]
.map(value => getIndexByKey(indexes[key], value)?.name)
.join(' + ');
parts.push(strings.title[key].replace(`%${key}%`, value));
}
Expand Down
33 changes: 15 additions & 18 deletions src/components/TsmlUI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
filterMeetingData,
getQueryString,
loadMeetingData,
setMinutesNow,
translateNoCodeAPI,
setQueryString,
settings,
} from '../helpers';
Expand Down Expand Up @@ -40,6 +38,7 @@ export default function TsmlUI({ json, mapbox, timezone }) {
},
loading: true,
meetings: [],
ready: false,
});

//enable forward & back buttons
Expand Down Expand Up @@ -78,15 +77,12 @@ export default function TsmlUI({ json, mapbox, timezone }) {
fetch(json)
.then(result => result.json())
.then(result => {
if (json?.includes('nocodeapi.com')) {
result = translateNoCodeAPI(result);
}

if (!Array.isArray(result) || !result.length) {
return setState({
...state,
error: 'bad_data',
loading: false,
ready: true,
});
}

Expand All @@ -96,13 +92,18 @@ export default function TsmlUI({ json, mapbox, timezone }) {
timezone
);

const waitingForGeo =
(!input.latitude || !input.longitude) &&
((input.mode === 'location' && input.search) || input.mode === 'me');

setState({
...state,
capabilities: capabilities,
indexes: indexes,
meetings: meetings,
loading: false,
input: input,
loading: false,
meetings: meetings,
ready: !waitingForGeo,
});
})
.catch(error => {
Expand All @@ -113,22 +114,14 @@ export default function TsmlUI({ json, mapbox, timezone }) {
...state,
error: json ? 'bad_data' : 'no_data_src',
loading: false,
ready: true,
});
});

return (
<div className="tsml-ui">
<Loading />
</div>
);
}

//apply input changes to query string
setQueryString(state.input);

//update time for sorting
state.meetings = setMinutesNow(state.meetings);

//filter data
const [filteredSlugs, inProgress] = filterMeetingData(
state,
Expand All @@ -144,7 +137,11 @@ export default function TsmlUI({ json, mapbox, timezone }) {
state.error = 'not_found';
}

return (
return !state.ready ? (
<div className="tsml-ui">
<Loading />
</div>
) : (
<div className="tsml-ui">
<div className="container-fluid d-flex flex-column py-3">
{state.input.meeting && state.input.meeting in state.meetings ? (
Expand Down
17 changes: 9 additions & 8 deletions src/helpers/data/calculate-distances.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export function calculateDistances(
) {
//build new index and meetings array
const distances = {};
settings.distance_options.forEach(distance => {
distances[distance] = {
key: distance.toString(),
name: `${distance} ${settings.distance_unit}`,
slugs: [],
};
});

//loop through and update or clear distances, and rebuild index
filteredSlugs.forEach(slug => {
Expand All @@ -23,15 +30,8 @@ export function calculateDistances(
),
};

[1, 2, 5, 10, 15, 25].forEach(distance => {
settings.distance_options.forEach(distance => {
if (state.meetings[slug].distance <= distance) {
if (!distances.hasOwnProperty(distance)) {
distances[distance] = {
key: distance.toString(),
name: `${distance} ${settings.distance_unit}`,
slugs: [],
};
}
distances[distance].slugs.push(slug);
}
});
Expand All @@ -57,5 +57,6 @@ export function calculateDistances(
latitude: parseFloat(latitude.toFixed(5)),
longitude: parseFloat(longitude.toFixed(5)),
},
ready: true,
});
}
Loading