mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +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 {msg} from '@lingui/core/macro';
|
||||||
import {useLingui} from '@lingui/react/macro';
|
import {useLingui} from '@lingui/react/macro';
|
||||||
import {clsx} from 'clsx';
|
import {clsx} from 'clsx';
|
||||||
|
import {memo} from 'react';
|
||||||
|
|
||||||
const TIME_OF_DESCRIPTOR = msg({
|
const TIME_OF_DESCRIPTOR = msg({
|
||||||
message: 'Time: {currentFormatted} of {durationFormatted}',
|
message: 'Time: {currentFormatted} of {durationFormatted}',
|
||||||
@@ -20,7 +21,17 @@ interface MediaTimeDisplayProps {
|
|||||||
className?: string;
|
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,
|
currentTime,
|
||||||
duration,
|
duration,
|
||||||
size = 'medium',
|
size = 'medium',
|
||||||
@@ -53,3 +64,5 @@ export function MediaTimeDisplay({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MediaTimeDisplay = memo(MediaTimeDisplayImpl, areTimeDisplayPropsEqualToTheSecond);
|
||||||
Reference in new issue
Block a user