[Refactoring] Media Viewer: Fix imports order, optimize CSS selector (#1567)
This commit is contained in:
parent
6e4b7cc04a
commit
8145e62b8f
@ -1,10 +1,16 @@
|
|||||||
|
import React, {
|
||||||
|
FC, memo, useCallback, useEffect, useMemo, useRef, useState,
|
||||||
|
} from '../../lib/teact/teact';
|
||||||
|
import { withGlobal } from '../../lib/teact/teactn';
|
||||||
|
|
||||||
|
import { GlobalActions } from '../../global/types';
|
||||||
import {
|
import {
|
||||||
ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser,
|
ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
|
import { MediaViewerOrigin } from '../../types';
|
||||||
|
|
||||||
import { ANIMATION_END_DELAY } from '../../config';
|
import { ANIMATION_END_DELAY } from '../../config';
|
||||||
|
|
||||||
import { GlobalActions } from '../../global/types';
|
|
||||||
import useBlurSync from '../../hooks/useBlurSync';
|
import useBlurSync from '../../hooks/useBlurSync';
|
||||||
import useForceUpdate from '../../hooks/useForceUpdate';
|
import useForceUpdate from '../../hooks/useForceUpdate';
|
||||||
import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck';
|
import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck';
|
||||||
@ -12,12 +18,7 @@ import useHistoryBack from '../../hooks/useHistoryBack';
|
|||||||
import useLang from '../../hooks/useLang';
|
import useLang from '../../hooks/useLang';
|
||||||
import useMedia from '../../hooks/useMedia';
|
import useMedia from '../../hooks/useMedia';
|
||||||
import useMediaWithLoadProgress from '../../hooks/useMediaWithLoadProgress';
|
import useMediaWithLoadProgress from '../../hooks/useMediaWithLoadProgress';
|
||||||
|
|
||||||
import usePrevious from '../../hooks/usePrevious';
|
import usePrevious from '../../hooks/usePrevious';
|
||||||
import React, {
|
|
||||||
FC, memo, useCallback, useEffect, useMemo, useRef, useState,
|
|
||||||
} from '../../lib/teact/teact';
|
|
||||||
import { withGlobal } from '../../lib/teact/teactn';
|
|
||||||
import {
|
import {
|
||||||
getChatAvatarHash,
|
getChatAvatarHash,
|
||||||
getChatMediaMessageIds,
|
getChatMediaMessageIds,
|
||||||
@ -46,7 +47,6 @@ import {
|
|||||||
selectScheduledMessages,
|
selectScheduledMessages,
|
||||||
selectUser,
|
selectUser,
|
||||||
} from '../../modules/selectors';
|
} from '../../modules/selectors';
|
||||||
import { MediaViewerOrigin } from '../../types';
|
|
||||||
import { stopCurrentAudio } from '../../util/audioPlayer';
|
import { stopCurrentAudio } from '../../util/audioPlayer';
|
||||||
import captureEscKeyListener from '../../util/captureEscKeyListener';
|
import captureEscKeyListener from '../../util/captureEscKeyListener';
|
||||||
import { captureEvents } from '../../util/captureEvents';
|
import { captureEvents } from '../../util/captureEvents';
|
||||||
@ -55,12 +55,11 @@ import { pick } from '../../util/iteratees';
|
|||||||
import windowSize from '../../util/windowSize';
|
import windowSize from '../../util/windowSize';
|
||||||
import { AVATAR_FULL_DIMENSIONS, MEDIA_VIEWER_MEDIA_QUERY } from '../common/helpers/mediaDimensions';
|
import { AVATAR_FULL_DIMENSIONS, MEDIA_VIEWER_MEDIA_QUERY } from '../common/helpers/mediaDimensions';
|
||||||
import { renderMessageText } from '../common/helpers/renderMessageText';
|
import { renderMessageText } from '../common/helpers/renderMessageText';
|
||||||
|
import { animateClosing, animateOpening } from './helpers/ghostAnimation';
|
||||||
|
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
import ShowTransition from '../ui/ShowTransition';
|
import ShowTransition from '../ui/ShowTransition';
|
||||||
import Transition from '../ui/Transition';
|
import Transition from '../ui/Transition';
|
||||||
import { animateClosing, animateOpening } from './helpers/ghostAnimation';
|
|
||||||
|
|
||||||
import './MediaViewer.scss';
|
|
||||||
import MediaViewerActions from './MediaViewerActions';
|
import MediaViewerActions from './MediaViewerActions';
|
||||||
import MediaViewerSlides from './MediaViewerSlides';
|
import MediaViewerSlides from './MediaViewerSlides';
|
||||||
import PanZoom from './PanZoom';
|
import PanZoom from './PanZoom';
|
||||||
@ -68,6 +67,8 @@ import SenderInfo from './SenderInfo';
|
|||||||
import SlideTransition from './SlideTransition';
|
import SlideTransition from './SlideTransition';
|
||||||
import ZoomControls from './ZoomControls';
|
import ZoomControls from './ZoomControls';
|
||||||
|
|
||||||
|
import './MediaViewer.scss';
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
chatId?: string;
|
chatId?: string;
|
||||||
threadId?: number;
|
threadId?: number;
|
||||||
@ -414,7 +415,7 @@ const MediaViewer: FC<StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isZoomed || IS_TOUCH_ENV) return undefined;
|
if (isZoomed || IS_TOUCH_ENV) return undefined;
|
||||||
const element = document.querySelector<HTMLDivElement>('.MediaViewerSlide.active');
|
const element = document.querySelector<HTMLDivElement>('.MediaViewerSlide--active');
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -492,7 +493,7 @@ const MediaViewer: FC<StateProps & DispatchProps> = ({
|
|||||||
activeKey={selectedMediaMessageIndex}
|
activeKey={selectedMediaMessageIndex}
|
||||||
name={slideAnimation}
|
name={slideAnimation}
|
||||||
>
|
>
|
||||||
{(isActive) => (
|
{(isActive: boolean) => (
|
||||||
<MediaViewerSlides
|
<MediaViewerSlides
|
||||||
messageId={messageId}
|
messageId={messageId}
|
||||||
getMessageId={getMessageId}
|
getMessageId={getMessageId}
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
|
import React, { FC, memo } from '../../lib/teact/teact';
|
||||||
|
import { withGlobal } from '../../lib/teact/teactn';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser,
|
ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
|
import { MediaViewerOrigin } from '../../types';
|
||||||
|
|
||||||
import useBlurSync from '../../hooks/useBlurSync';
|
import useBlurSync from '../../hooks/useBlurSync';
|
||||||
import useMedia from '../../hooks/useMedia';
|
import useMedia from '../../hooks/useMedia';
|
||||||
import useMediaWithLoadProgress from '../../hooks/useMediaWithLoadProgress';
|
import useMediaWithLoadProgress from '../../hooks/useMediaWithLoadProgress';
|
||||||
import React, { FC, memo } from '../../lib/teact/teact';
|
|
||||||
import { withGlobal } from '../../lib/teact/teactn';
|
|
||||||
import {
|
import {
|
||||||
getChatAvatarHash,
|
getChatAvatarHash,
|
||||||
getMessageDocument,
|
getMessageDocument,
|
||||||
@ -25,14 +28,15 @@ import {
|
|||||||
import {
|
import {
|
||||||
selectChat, selectChatMessage, selectScheduledMessage, selectUser,
|
selectChat, selectChatMessage, selectScheduledMessage, selectUser,
|
||||||
} from '../../modules/selectors';
|
} from '../../modules/selectors';
|
||||||
import { MediaViewerOrigin } from '../../types';
|
|
||||||
import { AVATAR_FULL_DIMENSIONS, calculateMediaViewerDimensions } from '../common/helpers/mediaDimensions';
|
import { AVATAR_FULL_DIMENSIONS, calculateMediaViewerDimensions } from '../common/helpers/mediaDimensions';
|
||||||
import { renderMessageText } from '../common/helpers/renderMessageText';
|
import { renderMessageText } from '../common/helpers/renderMessageText';
|
||||||
|
|
||||||
import Spinner from '../ui/Spinner';
|
import Spinner from '../ui/Spinner';
|
||||||
import './MediaViewerContent.scss';
|
|
||||||
import MediaViewerFooter from './MediaViewerFooter';
|
import MediaViewerFooter from './MediaViewerFooter';
|
||||||
import VideoPlayer from './VideoPlayer';
|
import VideoPlayer from './VideoPlayer';
|
||||||
|
|
||||||
|
import './MediaViewerContent.scss';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
messageId?: number;
|
messageId?: number;
|
||||||
chatId?: string;
|
chatId?: string;
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
touch-action: none;
|
touch-action: none;
|
||||||
transform-origin: 0 0;
|
transform-origin: 0 0;
|
||||||
|
|
||||||
&.active {
|
&--active {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
import useDebounce from '../../hooks/useDebounce';
|
import React, {
|
||||||
import useForceUpdate from '../../hooks/useForceUpdate';
|
|
||||||
import {
|
|
||||||
FC, memo, useCallback, useEffect, useRef, useState,
|
FC, memo, useCallback, useEffect, useRef, useState,
|
||||||
} from '../../lib/teact/teact';
|
} from '../../lib/teact/teact';
|
||||||
import React from '../../lib/teact/teactn';
|
|
||||||
import { MediaViewerOrigin } from '../../types';
|
import { MediaViewerOrigin } from '../../types';
|
||||||
|
|
||||||
|
import useDebounce from '../../hooks/useDebounce';
|
||||||
|
import useForceUpdate from '../../hooks/useForceUpdate';
|
||||||
import { animateNumber, timingFunctions } from '../../util/animation';
|
import { animateNumber, timingFunctions } from '../../util/animation';
|
||||||
import arePropsShallowEqual from '../../util/arePropsShallowEqual';
|
import arePropsShallowEqual from '../../util/arePropsShallowEqual';
|
||||||
import { captureEvents } from '../../util/captureEvents';
|
import { captureEvents } from '../../util/captureEvents';
|
||||||
import { IS_TOUCH_ENV } from '../../util/environment';
|
import { IS_TOUCH_ENV } from '../../util/environment';
|
||||||
import { debounce } from '../../util/schedulers';
|
import { debounce } from '../../util/schedulers';
|
||||||
|
|
||||||
import MediaViewerContent from './MediaViewerContent';
|
import MediaViewerContent from './MediaViewerContent';
|
||||||
|
|
||||||
import './MediaViewerSlides.scss';
|
import './MediaViewerSlides.scss';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
@ -430,7 +433,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
)}
|
)}
|
||||||
{activeMessageId && (
|
{activeMessageId && (
|
||||||
<div
|
<div
|
||||||
className={`MediaViewerSlide ${isActive ? 'active' : ''}`}
|
className={`MediaViewerSlide ${isActive ? 'MediaViewerSlide--active' : ''}`}
|
||||||
onClick={handleToggleFooterVisibility}
|
onClick={handleToggleFooterVisibility}
|
||||||
ref={activeSlideRef}
|
ref={activeSlideRef}
|
||||||
/* @ts-ignore */
|
/* @ts-ignore */
|
||||||
@ -454,6 +457,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(MediaViewerSlides);
|
export default memo(MediaViewerSlides);
|
||||||
|
|
||||||
function getAnimationStyle(x = 0, y = 0, scale = 1) {
|
function getAnimationStyle(x = 0, y = 0, scale = 1) {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import React, { FC } from '../../lib/teact/teact';
|
import React, { FC } from '../../lib/teact/teact';
|
||||||
|
|
||||||
import { IS_TOUCH_ENV } from '../../util/environment';
|
import { IS_TOUCH_ENV } from '../../util/environment';
|
||||||
|
|
||||||
import Transition, { TransitionProps } from '../ui/Transition';
|
import Transition, { TransitionProps } from '../ui/Transition';
|
||||||
|
|
||||||
const SlideTransition: FC<TransitionProps> = ({ children, ...props }) => {
|
const SlideTransition: FC<TransitionProps> = ({ children, ...props }) => {
|
||||||
|
|||||||
@ -96,7 +96,7 @@ export function animateClosing(origin: MediaViewerOrigin, bestImageData: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fromImage = document.getElementById('MediaViewer')!.querySelector<HTMLImageElement>(
|
const fromImage = document.getElementById('MediaViewer')!.querySelector<HTMLImageElement>(
|
||||||
'.MediaViewerSlide.active img, .MediaViewerSlide.active video',
|
'.MediaViewerSlide--active img, .MediaViewerSlide--active video',
|
||||||
);
|
);
|
||||||
if (!fromImage || !toImage) {
|
if (!fromImage || !toImage) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user