1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-17 18:03:22 +02:00
portfolio/src/components/Location/index.tsx

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-29 04:58:06 +01:00
import RelativeTime from '@yaireo/relative-time'
import { LazyMotion, domAnimation, m, useReducedMotion } from 'framer-motion'
import { useLocation } from '../../hooks/useLocation'
2023-01-29 04:58:06 +01:00
import { getAnimationProps, moveInTop } from '../Transitions'
2022-11-18 00:46:24 +01:00
import { Flag } from './Flag'
2023-01-29 04:58:06 +01:00
import styles from './index.module.css'
export default function Location() {
const { now, next } = useLocation()
const shouldReduceMotion = useReducedMotion()
const isDifferentCountry = now?.country !== next?.country
const relativeTime = new RelativeTime({ locale: 'en' })
return now?.city ? (
<LazyMotion features={domAnimation}>
2022-11-18 00:46:24 +01:00
<m.section
aria-label="Location"
variants={moveInTop}
className={styles.location}
{...getAnimationProps(shouldReduceMotion)}
>
2022-11-18 00:46:24 +01:00
<Flag country={{ code: now.country_code, name: now.country }} />
{now?.city} <span>Now</span>
<div className={styles.next}>
{next?.city && (
<>
2022-11-18 00:46:24 +01:00
{isDifferentCountry && (
<Flag
country={{ code: next.country_code, name: next.country }}
/>
)}
{next.city}{' '}
<span>{relativeTime.from(new Date(next.date_start))}</span>
</>
)}
</div>
2022-11-18 00:46:24 +01:00
</m.section>
</LazyMotion>
) : null
}