Export and use formatCity.

This commit is contained in:
Maxime-J 2024-04-15 16:41:16 +00:00
parent fe9db71ba8
commit 53449d65bb
2 changed files with 4 additions and 11 deletions

View File

@ -53,7 +53,7 @@ export function useFormat() {
}
};
return { formatOS, formatBrowser, formatDevice, formatCountry, formatRegion, formatValue };
return { formatOS, formatBrowser, formatDevice, formatCountry, formatRegion, formatCity, formatValue };
}
export default useFormat;

View File

@ -1,23 +1,16 @@
import MetricsTable, { MetricsTableProps } from './MetricsTable';
import { emptyFilter } from 'lib/filters';
import FilterLink from 'components/common/FilterLink';
import { useLocale } from 'components/hooks';
import { useMessages } from 'components/hooks';
import { useCountryNames } from 'components/hooks';
import { useFormat } from 'components/hooks';
export function CitiesTable(props: MetricsTableProps) {
const { locale } = useLocale();
const { formatMessage, labels } = useMessages();
const countryNames = useCountryNames(locale);
const renderLabel = (city: string, country: string) => {
const countryName = countryNames[country];
return countryName ? `${city}, ${countryName}` : city;
};
const { formatCity } = useFormat();
const renderLink = ({ x: city, country }) => {
return (
<FilterLink id="city" value={city} label={renderLabel(city, country)}>
<FilterLink id="city" value={city} label={formatCity(city, country)}>
{country && (
<img
src={`${process.env.basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}