mirror of
https://github.com/getredash/redash.git
synced 2026-03-21 16:00:09 -04:00
* Prettier all the JS files * Add GitHub Action to autoformat code pushed to master * Fix eslint violation due to formatting. * Remove GitHub actions for styling * Add restyled.io config
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
import React, { useMemo, useEffect } from "react";
|
|
import moment from "moment";
|
|
import PropTypes from "prop-types";
|
|
import { react2angular } from "react2angular";
|
|
import { Moment } from "@/components/proptypes";
|
|
import useForceUpdate from "@/lib/hooks/useForceUpdate";
|
|
|
|
export function Timer({ from }) {
|
|
const startTime = useMemo(() => moment(from).valueOf(), [from]);
|
|
const forceUpdate = useForceUpdate();
|
|
|
|
useEffect(() => {
|
|
const timer = setInterval(forceUpdate, 1000);
|
|
return () => clearInterval(timer);
|
|
}, [forceUpdate]);
|
|
|
|
const diff = moment.now() - startTime;
|
|
const format = diff > 1000 * 60 * 60 ? "HH:mm:ss" : "mm:ss"; // no HH under an hour
|
|
|
|
return <span className="rd-timer">{moment.utc(diff).format(format)}</span>;
|
|
}
|
|
|
|
Timer.propTypes = {
|
|
from: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date), Moment]),
|
|
};
|
|
|
|
Timer.defaultProps = {
|
|
from: null,
|
|
};
|
|
|
|
export default function init(ngModule) {
|
|
ngModule.component("rdTimer", react2angular(Timer));
|
|
}
|
|
|
|
init.init = true;
|