-
Notifications
You must be signed in to change notification settings - Fork 2
Issues 41, 42, 43 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cde3151
cb9ad9c
4d03338
866bc91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,15 @@ export async function getFilteredXicons(filter: XiconFilter): Promise<XiconItem[ | |
| }); | ||
| } | ||
|
|
||
| // Filter by country (for regions) | ||
| if (filter.country) { | ||
| const countryLower = filter.country.toLowerCase(); | ||
| items = items.filter(item => { | ||
| if (item.type !== 'region') return true; | ||
| return item.country?.toLowerCase().includes(countryLower); | ||
| }); | ||
| } | ||
|
|
||
| return items; | ||
| } | ||
|
|
||
|
|
@@ -273,3 +282,36 @@ export async function getNextPrevXicons( | |
|
|
||
| return { next, prev }; | ||
| } | ||
|
|
||
| export async function getCountryStateCityMap(): Promise<Record<string, Record<string, string[]>>> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function will map countries -> states -> cities |
||
| const map: Record<string, Record<string, Set<string>>> = {}; | ||
|
|
||
| const regions = (await getAllXicons()).filter(item => item.type === 'region'); | ||
|
|
||
| regions.forEach(region => { | ||
| const country = region.country?.trim() || 'Unknown'; | ||
| const state = region.state?.trim() || 'Unknown'; | ||
| const city = region.city?.trim() || 'Unknown'; | ||
|
|
||
| if (!map[country]) { | ||
| map[country] = {}; | ||
| } | ||
|
|
||
| if (!map[country][state]) { | ||
| map[country][state] = new Set(); | ||
| } | ||
|
|
||
| map[country][state].add(city); | ||
| }); | ||
|
|
||
| // Convert Set → Array | ||
| const result: Record<string, Record<string, string[]>> = {}; | ||
| for (const country in map) { | ||
| result[country] = {}; | ||
| for (const state in map[country]) { | ||
| result[country][state] = Array.from(map[country][state]).sort(); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ async function fetchRegions(): Promise<Region[]> { | |
|
|
||
| for (let i = 0; i < regionNames.length; i++) { | ||
| const name = regionNames[i]; | ||
| const { city, state } = getLocation(name, locationsByRegion); | ||
| const { city, state, country } = getLocation(name, locationsByRegion); | ||
| const mapUrl = getMapUrl(name, latLngByRegion); | ||
| const slug = kebabCase(name); | ||
| const websiteUrl = `https://freemensworkout.org/regions/${slug}`; | ||
|
|
@@ -40,7 +40,7 @@ async function fetchRegions(): Promise<Region[]> { | |
| name, | ||
| city, | ||
| state, | ||
| country: 'United States', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By default United states is placed as country in the db seeding script. I changed it to parse the country from the location row from api. |
||
| country, | ||
| regionPageUrl: websiteUrl, | ||
| mapUrl, | ||
| tags: [], | ||
|
|
@@ -161,12 +161,13 @@ const getLatLngByRegion = (rows: string[][], colNums: ColNums) => { | |
| */ | ||
| const getLocation = (regionName: string, locationsByRegion: Record<string, string[]>) => { | ||
| const locations = [ | ||
| ...new Set(locationsByRegion[regionName].map(location => extractCityState(location))), | ||
| ...new Set(locationsByRegion[regionName].map(location => extractCityStateCountry(location))), | ||
| ]; | ||
| const location = locations[0].split(','); | ||
| return { | ||
| city: location[0].trim(), | ||
| state: location[1].trim(), | ||
| country: location[2]?.trim(), | ||
| }; | ||
| }; | ||
|
|
||
|
|
@@ -180,7 +181,7 @@ const getLocation = (regionName: string, locationsByRegion: Record<string, strin | |
| * @param location - a comma-separated address string | ||
| * @returns "City, State" or an empty string if it can't parse | ||
| */ | ||
| const extractCityState = (location: string) => { | ||
| const extractCityStateCountry = (location: string) => { | ||
| // Split on commas, trim whitespace, drop any empty segments | ||
| const parts = location | ||
| .split(',') | ||
|
|
@@ -195,6 +196,7 @@ const extractCityState = (location: string) => { | |
| // City is the 4th-to-last segment, state is the 3rd-to-last | ||
| const city = parts[parts.length - 4]; | ||
| const state = parts[parts.length - 3]; | ||
| const country = parts[parts.length - 1]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This here extracts country from the location, logic is similar to the extracting logic for state & city |
||
|
|
||
| return `${city}, ${state}`; | ||
| return `${city}, ${state}, ${country}`; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is added to organize country, state and city