2018-07-09 21:29:13 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { getIncrement, getTimerBucket } from '../../util/timer';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
interface Props {
|
2019-06-26 19:33:13 +00:00
|
|
|
withImageNoCaption?: boolean;
|
|
|
|
withSticker?: boolean;
|
|
|
|
withTapToViewExpired?: boolean;
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationLength: number;
|
|
|
|
expirationTimestamp: number;
|
2019-05-16 22:32:11 +00:00
|
|
|
direction?: 'incoming' | 'outgoing';
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class ExpireTimer extends React.Component<Props> {
|
|
|
|
private interval: any;
|
|
|
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.interval = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
const { expirationLength } = this.props;
|
|
|
|
const increment = getIncrement(expirationLength);
|
|
|
|
const updateFrequency = Math.max(increment, 500);
|
|
|
|
|
|
|
|
const update = () => {
|
|
|
|
this.setState({
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.interval = setInterval(update, updateFrequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
if (this.interval) {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
direction,
|
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
|
|
|
withImageNoCaption,
|
2019-05-16 22:32:11 +00:00
|
|
|
withSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
withTapToViewExpired,
|
2018-07-09 21:29:13 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const bucket = getTimerBucket(expirationTimestamp, expirationLength);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-expire-timer',
|
|
|
|
`module-expire-timer--${bucket}`,
|
2019-06-26 19:33:13 +00:00
|
|
|
direction ? `module-expire-timer--${direction}` : null,
|
|
|
|
withTapToViewExpired
|
|
|
|
? `module-expire-timer--${direction}-with-tap-to-view-expired`
|
|
|
|
: null,
|
|
|
|
direction && withImageNoCaption
|
2018-07-09 21:29:13 +00:00
|
|
|
? 'module-expire-timer--with-image-no-caption'
|
2019-05-16 22:32:11 +00:00
|
|
|
: null,
|
|
|
|
withSticker ? 'module-expire-timer--with-sticker' : null
|
2018-07-09 21:29:13 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|