mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-02 19:49:23 +00:00
Use proper duration formatter
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
"@babel/preset-env": "^7.22.20",
|
"@babel/preset-env": "^7.22.20",
|
||||||
"@babel/preset-react": "^7.22.15",
|
"@babel/preset-react": "^7.22.15",
|
||||||
"@babel/preset-typescript": "^7.23.0",
|
"@babel/preset-typescript": "^7.23.0",
|
||||||
|
"@formatjs/intl-durationformat": "^0.6.1",
|
||||||
"@livekit/components-core": "^0.11.0",
|
"@livekit/components-core": "^0.11.0",
|
||||||
"@livekit/components-react": "^2.0.0",
|
"@livekit/components-react": "^2.0.0",
|
||||||
"@opentelemetry/api": "^1.4.0",
|
"@opentelemetry/api": "^1.4.0",
|
||||||
|
|||||||
@@ -7,9 +7,18 @@ Please see LICENSE in the repository root for full details.
|
|||||||
|
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import "@formatjs/intl-durationformat/polyfill";
|
||||||
|
import { DurationFormat } from "@formatjs/intl-durationformat";
|
||||||
|
|
||||||
import styles from "./RaisedHandIndicator.module.css";
|
import styles from "./RaisedHandIndicator.module.css";
|
||||||
|
|
||||||
|
const durationFormatter = new DurationFormat(undefined, {
|
||||||
|
minutesDisplay: "always",
|
||||||
|
secondsDisplay: "always",
|
||||||
|
hoursDisplay: "auto",
|
||||||
|
style: "digital",
|
||||||
|
});
|
||||||
|
|
||||||
export function RaisedHandIndicator({
|
export function RaisedHandIndicator({
|
||||||
raisedHandTime,
|
raisedHandTime,
|
||||||
minature,
|
minature,
|
||||||
@@ -26,14 +35,16 @@ export function RaisedHandIndicator({
|
|||||||
if (!raisedHandTime || !showTimer) {
|
if (!raisedHandTime || !showTimer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculateTime = (): void => {
|
const calculateTime = (): void => {
|
||||||
const totalSeconds = Math.ceil(
|
const totalSeconds = Math.ceil(
|
||||||
(new Date().getTime() - raisedHandTime.getTime()) / 1000,
|
(new Date().getTime() - raisedHandTime.getTime()) / 1000,
|
||||||
);
|
);
|
||||||
const seconds = totalSeconds % 60;
|
|
||||||
const minutes = Math.floor(totalSeconds / 60);
|
|
||||||
setRaisedHandDuration(
|
setRaisedHandDuration(
|
||||||
`${minutes < 10 ? "0" : ""}${minutes}:${seconds < 10 ? "0" : ""}${seconds}`,
|
durationFormatter.format({
|
||||||
|
seconds: totalSeconds % 60,
|
||||||
|
minutes: Math.floor(totalSeconds / 60),
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
calculateTime();
|
calculateTime();
|
||||||
|
|||||||
37
yarn.lock
37
yarn.lock
@@ -1781,6 +1781,38 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.8.tgz#21a907684723bbbaa5f0974cf7730bd797eb8e62"
|
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.8.tgz#21a907684723bbbaa5f0974cf7730bd797eb8e62"
|
||||||
integrity sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==
|
integrity sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==
|
||||||
|
|
||||||
|
"@formatjs/ecma402-abstract@2.2.1":
|
||||||
|
version "2.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.2.1.tgz#2e62bc5c22b0e6a5e13bfec6aac15d3d403e1065"
|
||||||
|
integrity sha512-O4ywpkdJybrjFc9zyL8qK5aklleIAi5O4nYhBVJaOFtCkNrnU+lKFeJOFC48zpsZQmR8Aok2V79hGpHnzbmFpg==
|
||||||
|
dependencies:
|
||||||
|
"@formatjs/fast-memoize" "2.2.2"
|
||||||
|
"@formatjs/intl-localematcher" "0.5.6"
|
||||||
|
tslib "2"
|
||||||
|
|
||||||
|
"@formatjs/fast-memoize@2.2.2":
|
||||||
|
version "2.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.2.tgz#2409ec10f5f7d6c65f4c04e6c2d6cc56fa1e4cef"
|
||||||
|
integrity sha512-mzxZcS0g1pOzwZTslJOBTmLzDXseMLLvnh25ymRilCm8QLMObsQ7x/rj9GNrH0iUhZMlFisVOD6J1n6WQqpKPQ==
|
||||||
|
dependencies:
|
||||||
|
tslib "2"
|
||||||
|
|
||||||
|
"@formatjs/intl-durationformat@^0.6.1":
|
||||||
|
version "0.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@formatjs/intl-durationformat/-/intl-durationformat-0.6.1.tgz#ea376202b1dc70683a3f3e125bb07f4fab1135a5"
|
||||||
|
integrity sha512-tPSX/D/wjO5ZKnRtwLlUYtjLUBILLX1w6+arU97NpPCpZ8SRWQePu+kDAxDwFKJ/w09idqvSFkJjYGTs6hMd1A==
|
||||||
|
dependencies:
|
||||||
|
"@formatjs/ecma402-abstract" "2.2.1"
|
||||||
|
"@formatjs/intl-localematcher" "0.5.6"
|
||||||
|
tslib "2"
|
||||||
|
|
||||||
|
"@formatjs/intl-localematcher@0.5.6":
|
||||||
|
version "0.5.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.6.tgz#cd0cd99483673d3196a15b4e2c924cfda7f002f8"
|
||||||
|
integrity sha512-roz1+Ba5e23AHX6KUAWmLEyTRZegM5YDuxuvkHCyK3RJddf/UXB2f+s7pOMm9ktfPGla0g+mQXOn5vsuYirnaA==
|
||||||
|
dependencies:
|
||||||
|
tslib "2"
|
||||||
|
|
||||||
"@gulpjs/to-absolute-glob@^4.0.0":
|
"@gulpjs/to-absolute-glob@^4.0.0":
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@gulpjs/to-absolute-glob/-/to-absolute-glob-4.0.0.tgz#1fc2460d3953e1d9b9f2dfdb4bcc99da4710c021"
|
resolved "https://registry.yarnpkg.com/@gulpjs/to-absolute-glob/-/to-absolute-glob-4.0.0.tgz#1fc2460d3953e1d9b9f2dfdb4bcc99da4710c021"
|
||||||
@@ -7834,6 +7866,11 @@ tsconfig-paths@^3.15.0:
|
|||||||
minimist "^1.2.6"
|
minimist "^1.2.6"
|
||||||
strip-bom "^3.0.0"
|
strip-bom "^3.0.0"
|
||||||
|
|
||||||
|
tslib@2:
|
||||||
|
version "2.8.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b"
|
||||||
|
integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==
|
||||||
|
|
||||||
tslib@2.7.0, tslib@^2.0.0, tslib@^2.1.0:
|
tslib@2.7.0, tslib@^2.0.0, tslib@^2.1.0:
|
||||||
version "2.7.0"
|
version "2.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
|
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
|
||||||
|
|||||||
Reference in New Issue
Block a user