mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
perf(app): redraw the media timestamp only when the second changes (#1938)
This commit is contained in:
1 parent
0fe3f7523d
commit
ef6fb4903f
1 file changed
+14
-1
+14
-1
@@ -5,6 +5,7 @@ import {formatDuration} from '@fluxer/date_utils/src/DateDuration';
|
||||
import {msg} from '@lingui/core/macro';
|
||||
import {useLingui} from '@lingui/react/macro';
|
||||
import {clsx} from 'clsx';
|
||||
import {memo} from 'react';
|
||||
|
||||
const TIME_OF_DESCRIPTOR = msg({
|
||||
message: 'Time: {currentFormatted} of {durationFormatted}',
|
||||
@@ -20,7 +21,17 @@ interface MediaTimeDisplayProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function MediaTimeDisplay({
|
||||
function areTimeDisplayPropsEqualToTheSecond(previous: MediaTimeDisplayProps, next: MediaTimeDisplayProps): boolean {
|
||||
return (
|
||||
Math.trunc(previous.currentTime) === Math.trunc(next.currentTime) &&
|
||||
Math.trunc(previous.duration) === Math.trunc(next.duration) &&
|
||||
previous.size === next.size &&
|
||||
previous.compact === next.compact &&
|
||||
previous.className === next.className
|
||||
);
|
||||
}
|
||||
|
||||
function MediaTimeDisplayImpl({
|
||||
currentTime,
|
||||
duration,
|
||||
size = 'medium',
|
||||
@@ -53,3 +64,5 @@ export function MediaTimeDisplay({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const MediaTimeDisplay = memo(MediaTimeDisplayImpl, areTimeDisplayPropsEqualToTheSecond);
|
||||
Reference in new issue
Block a user