forked from Ivasoft/mattermost-mobile
* Add app review * Use overlay instead of modal * Add fixes for ios * i18n-extract * Add to milliseconds function * Address review feedback * Add try to queryGlobalValue * added app review illustration * add feedback illustration * Add animations and feedback bot message * Restrict reviews to build environment variable * Fix bug with "dont ask anymore" * Add check for only supported servers * Add missing change * Use for await Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local> Co-authored-by: Matthew Birtch <mattbirtch@gmail.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import moment from 'moment-timezone';
|
|
import React, {useEffect, useState} from 'react';
|
|
import {Text, TextProps} from 'react-native';
|
|
|
|
import {toMilliseconds} from '@utils/datetime';
|
|
|
|
type FormattedRelativeTimeProps = TextProps & {
|
|
timezone?: UserTimezone | string;
|
|
value: number | string | Date;
|
|
updateIntervalInSeconds?: number;
|
|
}
|
|
|
|
const FormattedRelativeTime = ({timezone, value, updateIntervalInSeconds, ...props}: FormattedRelativeTimeProps) => {
|
|
const getFormattedRelativeTime = () => {
|
|
let zone = timezone;
|
|
if (typeof timezone === 'object') {
|
|
zone = timezone.useAutomaticTimezone ? timezone.automaticTimezone : timezone.manualTimezone;
|
|
}
|
|
|
|
return timezone ? moment.tz(value, zone as string).fromNow() : moment(value).fromNow();
|
|
};
|
|
|
|
const [formattedTime, setFormattedTime] = useState(getFormattedRelativeTime);
|
|
useEffect(() => {
|
|
if (updateIntervalInSeconds) {
|
|
const interval = setInterval(
|
|
() => setFormattedTime(getFormattedRelativeTime()),
|
|
toMilliseconds({seconds: updateIntervalInSeconds}),
|
|
);
|
|
return function cleanup() {
|
|
return clearInterval(interval);
|
|
};
|
|
}
|
|
return function cleanup() {
|
|
return null;
|
|
};
|
|
}, [updateIntervalInSeconds]);
|
|
|
|
return (
|
|
<Text {...props}>
|
|
{formattedTime}
|
|
</Text>
|
|
);
|
|
};
|
|
|
|
export default FormattedRelativeTime;
|