1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
Zhiyuan Zheng
2022-06-14 23:43:11 +02:00
parent 04813cbc78
commit 7c0bcbeb06
5 changed files with 12 additions and 15 deletions

View File

@ -3,11 +3,10 @@ import { FormattedRelativeTime } from 'react-intl'
import { AppState } from 'react-native' import { AppState } from 'react-native'
export interface Props { export interface Props {
type: 'past' | 'future'
time: string | number time: string | number
} }
const RelativeTime: React.FC<Props> = ({ type, time }) => { const RelativeTime: React.FC<Props> = ({ time }) => {
const [now, setNow] = useState(new Date().getTime()) const [now, setNow] = useState(new Date().getTime())
useEffect(() => { useEffect(() => {
const appStateListener = AppState.addEventListener('change', state => { const appStateListener = AppState.addEventListener('change', state => {
@ -21,9 +20,7 @@ const RelativeTime: React.FC<Props> = ({ type, time }) => {
return ( return (
<FormattedRelativeTime <FormattedRelativeTime
value={ value={(new Date(time).getTime() - now) / 1000}
((type === 'past' ? -1 : 1) * (now - new Date(time).getTime())) / 1000
}
updateIntervalInSeconds={1} updateIntervalInSeconds={1}
/> />
) )

View File

@ -32,7 +32,7 @@ const HeaderSharedCreated = React.memo(
/> />
</> </>
) : ( ) : (
<RelativeTime type='past' time={actualTime} /> <RelativeTime time={actualTime} />
)} )}
</CustomText> </CustomText>
{edited_at ? ( {edited_at ? (

View File

@ -269,7 +269,7 @@ const TimelinePoll: React.FC<Props> = ({
)) ))
}, [theme, allOptions]) }, [theme, allOptions])
const pollVoteCounts = useMemo(() => { const pollVoteCounts = () => {
if (poll.voters_count !== null) { if (poll.voters_count !== null) {
return ( return (
t('shared.poll.meta.count.voters', { count: poll.voters_count }) + ' • ' t('shared.poll.meta.count.voters', { count: poll.voters_count }) + ' • '
@ -279,9 +279,9 @@ const TimelinePoll: React.FC<Props> = ({
t('shared.poll.meta.count.votes', { count: poll.votes_count }) + ' • ' t('shared.poll.meta.count.votes', { count: poll.votes_count }) + ' • '
) )
} }
}, [poll.voters_count, poll.votes_count]) }
const pollExpiration = useMemo(() => { const pollExpiration = () => {
if (poll.expired) { if (poll.expired) {
return t('shared.poll.meta.expiration.expired') return t('shared.poll.meta.expiration.expired')
} else { } else {
@ -289,12 +289,12 @@ const TimelinePoll: React.FC<Props> = ({
return ( return (
<Trans <Trans
i18nKey='componentTimeline:shared.poll.meta.expiration.until' i18nKey='componentTimeline:shared.poll.meta.expiration.until'
components={[<RelativeTime type='future' time={poll.expires_at} />]} components={[<RelativeTime time={poll.expires_at} />]}
/> />
) )
} }
} }
}, [theme, i18n.language, poll.expired, poll.expires_at]) }
return ( return (
<View style={{ marginTop: StyleConstants.Spacing.M }}> <View style={{ marginTop: StyleConstants.Spacing.M }}>
@ -312,8 +312,8 @@ const TimelinePoll: React.FC<Props> = ({
fontStyle='S' fontStyle='S'
style={{ flexShrink: 1, color: colors.secondary }} style={{ flexShrink: 1, color: colors.secondary }}
> >
{pollVoteCounts} {pollVoteCounts()}
{pollExpiration} {pollExpiration()}
</CustomText> </CustomText>
</View> </View>
</View> </View>

View File

@ -139,7 +139,7 @@
}, },
"expiration": { "expiration": {
"expired": "Vote expired", "expired": "Vote expired",
"until": "Expires in <0 />" "until": "Expires <0 />"
} }
} }
} }

View File

@ -93,7 +93,7 @@ const ScreenAnnouncements: React.FC<
<Trans <Trans
i18nKey='screenAnnouncements:content.published' i18nKey='screenAnnouncements:content.published'
components={[ components={[
<RelativeTime type='past' time={item.published_at} /> <RelativeTime time={item.published_at} />
]} ]}
/> />
</CustomText> </CustomText>