mirror of https://github.com/tooot-app/app
Fixed #301
This commit is contained in:
parent
be4fb53d03
commit
72eee3600f
|
@ -0,0 +1,32 @@
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { FormattedRelativeTime } from 'react-intl'
|
||||||
|
import { AppState } from 'react-native'
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
type: 'past' | 'future'
|
||||||
|
time: string | number
|
||||||
|
}
|
||||||
|
|
||||||
|
const RelativeTime: React.FC<Props> = ({ type, time }) => {
|
||||||
|
const [now, setNow] = useState(new Date().getTime())
|
||||||
|
useEffect(() => {
|
||||||
|
const appStateListener = AppState.addEventListener('change', state => {
|
||||||
|
setNow(new Date().getTime())
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
appStateListener.remove()
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormattedRelativeTime
|
||||||
|
value={
|
||||||
|
((type === 'past' ? -1 : 1) * (now - new Date(time).getTime())) / 1000
|
||||||
|
}
|
||||||
|
updateIntervalInSeconds={1}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RelativeTime
|
|
@ -1,10 +1,11 @@
|
||||||
import Icon from '@components/Icon'
|
import Icon from '@components/Icon'
|
||||||
|
import RelativeTime from '@components/RelativeTime'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { FormattedDate, FormattedRelativeTime } from 'react-intl'
|
import { FormattedDate } from 'react-intl'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
created_at: Mastodon.Status['created_at'] | number
|
created_at: Mastodon.Status['created_at'] | number
|
||||||
|
@ -31,12 +32,7 @@ const HeaderSharedCreated = React.memo(
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<FormattedRelativeTime
|
<RelativeTime type='past' time={actualTime} />
|
||||||
value={
|
|
||||||
-(new Date().getTime() - new Date(actualTime).getTime()) / 1000
|
|
||||||
}
|
|
||||||
updateIntervalInSeconds={1}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</CustomText>
|
</CustomText>
|
||||||
{edited_at ? (
|
{edited_at ? (
|
||||||
|
|
|
@ -4,6 +4,7 @@ import haptics from '@components/haptics'
|
||||||
import Icon from '@components/Icon'
|
import Icon from '@components/Icon'
|
||||||
import { displayMessage } from '@components/Message'
|
import { displayMessage } from '@components/Message'
|
||||||
import { ParseEmojis } from '@components/Parse'
|
import { ParseEmojis } from '@components/Parse'
|
||||||
|
import RelativeTime from '@components/RelativeTime'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
import {
|
import {
|
||||||
MutationVarsTimelineUpdateStatusProperty,
|
MutationVarsTimelineUpdateStatusProperty,
|
||||||
|
@ -16,8 +17,7 @@ import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { maxBy } from 'lodash'
|
import { maxBy } from 'lodash'
|
||||||
import React, { useCallback, useMemo, useState } from 'react'
|
import React, { useCallback, useMemo, useState } from 'react'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { FormattedRelativeTime } from 'react-intl'
|
import { Pressable, View } from 'react-native'
|
||||||
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
|
||||||
import { useQueryClient } from 'react-query'
|
import { useQueryClient } from 'react-query'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
|
@ -289,15 +289,7 @@ const TimelinePoll: React.FC<Props> = ({
|
||||||
return (
|
return (
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey='componentTimeline:shared.poll.meta.expiration.until'
|
i18nKey='componentTimeline:shared.poll.meta.expiration.until'
|
||||||
components={[
|
components={[<RelativeTime type='future' time={poll.expires_at} />]}
|
||||||
<FormattedRelativeTime
|
|
||||||
value={
|
|
||||||
(new Date(poll.expires_at).getTime() - new Date().getTime()) /
|
|
||||||
1000
|
|
||||||
}
|
|
||||||
updateIntervalInSeconds={1}
|
|
||||||
/>
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import analytics from '@components/analytics'
|
||||||
import Button from '@components/Button'
|
import Button from '@components/Button'
|
||||||
import haptics from '@components/haptics'
|
import haptics from '@components/haptics'
|
||||||
import { ParseHTML } from '@components/Parse'
|
import { ParseHTML } from '@components/Parse'
|
||||||
|
import RelativeTime from '@components/RelativeTime'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
import { BlurView } from '@react-native-community/blur'
|
import { BlurView } from '@react-native-community/blur'
|
||||||
import { useAccessibility } from '@utils/accessibility/AccessibilityManager'
|
import { useAccessibility } from '@utils/accessibility/AccessibilityManager'
|
||||||
|
@ -92,15 +93,7 @@ const ScreenAnnouncements: React.FC<
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey='screenAnnouncements:content.published'
|
i18nKey='screenAnnouncements:content.published'
|
||||||
components={[
|
components={[
|
||||||
<FormattedRelativeTime
|
<RelativeTime type='past' time={item.published_at} />
|
||||||
value={
|
|
||||||
-(
|
|
||||||
new Date().getTime() -
|
|
||||||
new Date(item.published_at).getTime()
|
|
||||||
) / 1000
|
|
||||||
}
|
|
||||||
updateIntervalInSeconds={1}
|
|
||||||
/>
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</CustomText>
|
</CustomText>
|
||||||
|
|
Loading…
Reference in New Issue