fedisearch/application/src/components/Geo.tsx

36 wiersze
973 B
TypeScript
Czysty Zwykły widok Historia

2022-09-14 19:16:00 +00:00
import React from 'react'
2022-11-03 18:38:01 +00:00
export function getFlagEmoji (countryCode: string): string {
2022-09-14 19:16:00 +00:00
const codePoints = countryCode
.toUpperCase()
.split('')
.map(char => 127397 + char.charCodeAt(0))
return String.fromCodePoint(...codePoints)
}
2022-11-03 18:38:01 +00:00
export interface GeoParams {
countryCode?: string
countryName?: string
city?: string
2022-09-14 19:16:00 +00:00
}
2022-11-03 18:38:01 +00:00
export default function Geo ({ countryCode, countryName, city }: GeoParams): React.ReactElement | null {
const alignedCountryCode = countryCode ?? ''
const alignedCity = city ?? ''
if (alignedCountryCode === '' && alignedCity === '') {
2022-09-14 19:16:00 +00:00
return null
}
return <div className={'geo'}>
2022-11-03 18:38:01 +00:00
{
alignedCity !== ''
? <span className={'city'}>{alignedCity}</span>
: ''
}
{
alignedCountryCode !== ''
? <span className={'country'} title={`${countryName ?? alignedCountryCode}`}>{getFlagEmoji(alignedCountryCode)}</span>
: ''
}
2022-09-14 19:16:00 +00:00
</div>
}