mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
ignoring image modal key sliding when modal is shown
This commit is contained in:
parent
e25caef8a3
commit
924b6d4285
7 changed files with 54 additions and 55 deletions
|
@ -3,10 +3,9 @@ import { INode } from '~/redux/types';
|
||||||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||||
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
|
import { INodeComponentProps } from '~/redux/node/constants';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps extends INodeComponentProps {}
|
||||||
node: INode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NodeAudioBlock: FC<IProps> = ({ node }) => {
|
const NodeAudioBlock: FC<IProps> = ({ node }) => {
|
||||||
const audios = useMemo(
|
const audios = useMemo(
|
||||||
|
|
|
@ -5,10 +5,9 @@ import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||||
import path from 'ramda/es/path';
|
import path from 'ramda/es/path';
|
||||||
import { getURL } from '~/utils/dom';
|
import { getURL } from '~/utils/dom';
|
||||||
import { PRESETS } from '~/constants/urls';
|
import { PRESETS } from '~/constants/urls';
|
||||||
|
import { INodeComponentProps } from '~/redux/node/constants';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps extends INodeComponentProps {}
|
||||||
node: INode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NodeAudioImageBlock: FC<IProps> = ({ node }) => {
|
const NodeAudioImageBlock: FC<IProps> = ({ node }) => {
|
||||||
const images = useMemo(
|
const images = useMemo(
|
||||||
|
|
|
@ -1,24 +1,15 @@
|
||||||
import React, { FC, useMemo, useState, useEffect, useRef, useCallback, KeyboardEvent } from 'react';
|
import React, { FC, useMemo, useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import { ImageSwitcher } from '../ImageSwitcher';
|
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { INode } from '~/redux/types';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||||
import { NODE_SETTINGS } from '~/redux/node/constants';
|
import { INodeComponentProps } from '~/redux/node/constants';
|
||||||
import { getURL } from '~/utils/dom';
|
import { getURL } from '~/utils/dom';
|
||||||
import { PRESETS } from '~/constants/urls';
|
import { PRESETS } from '~/constants/urls';
|
||||||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
||||||
import { throttle } from 'throttle-debounce';
|
import { throttle } from 'throttle-debounce';
|
||||||
import * as MODAL_ACTIONS from '~/redux/modal/actions';
|
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps extends INodeComponentProps {}
|
||||||
is_loading: boolean;
|
|
||||||
node: INode;
|
|
||||||
layout: {};
|
|
||||||
updateLayout: () => void;
|
|
||||||
modalShowPhotoswipe: typeof MODAL_ACTIONS.modalShowPhotoswipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getX = event =>
|
const getX = event =>
|
||||||
(event.touches && event.touches.length) || (event.changedTouches && event.changedTouches.length)
|
(event.touches && event.touches.length) || (event.changedTouches && event.changedTouches.length)
|
||||||
|
@ -28,6 +19,7 @@ const getX = event =>
|
||||||
const NodeImageSlideBlock: FC<IProps> = ({
|
const NodeImageSlideBlock: FC<IProps> = ({
|
||||||
node,
|
node,
|
||||||
is_loading,
|
is_loading,
|
||||||
|
is_modal_shown,
|
||||||
updateLayout,
|
updateLayout,
|
||||||
modalShowPhotoswipe,
|
modalShowPhotoswipe,
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -250,7 +242,11 @@ const NodeImageSlideBlock: FC<IProps> = ({
|
||||||
|
|
||||||
const onKeyDown = useCallback(
|
const onKeyDown = useCallback(
|
||||||
event => {
|
event => {
|
||||||
if (event.target.tagName && ['TEXTAREA', 'INPUT'].includes(event.target.tagName)) return;
|
if (
|
||||||
|
(event.target.tagName && ['TEXTAREA', 'INPUT'].includes(event.target.tagName)) ||
|
||||||
|
is_modal_shown
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'ArrowLeft':
|
case 'ArrowLeft':
|
||||||
|
@ -259,7 +255,7 @@ const NodeImageSlideBlock: FC<IProps> = ({
|
||||||
return onNext();
|
return onNext();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onNext, onPrev]
|
[onNext, onPrev, is_modal_shown]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -3,10 +3,9 @@ import { INode } from '~/redux/types';
|
||||||
import path from 'ramda/es/path';
|
import path from 'ramda/es/path';
|
||||||
import { formatTextParagraphs } from '~/utils/dom';
|
import { formatTextParagraphs } from '~/utils/dom';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
|
import { INodeComponentProps } from '~/redux/node/constants';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps extends INodeComponentProps {}
|
||||||
node: INode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NodeTextBlock: FC<IProps> = ({ node }) => (
|
const NodeTextBlock: FC<IProps> = ({ node }) => (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import React, { FC, useMemo } from 'react';
|
import React, { FC, useMemo } from 'react';
|
||||||
import { INode } from '~/redux/types';
|
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import path from 'ramda/es/path';
|
import path from 'ramda/es/path';
|
||||||
|
import { INodeComponentProps } from '~/redux/node/constants';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps extends INodeComponentProps {}
|
||||||
node: INode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NodeVideoBlock: FC<IProps> = ({ node }) => {
|
const NodeVideoBlock: FC<IProps> = ({ node }) => {
|
||||||
const video = useMemo(() => {
|
const video = useMemo(() => {
|
||||||
|
|
|
@ -12,7 +12,12 @@ import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeRelated } from '~/components/node/NodeRelated';
|
import { NodeRelated } from '~/components/node/NodeRelated';
|
||||||
import { NodeComments } from '~/components/node/NodeComments';
|
import { NodeComments } from '~/components/node/NodeComments';
|
||||||
import { NodeTags } from '~/components/node/NodeTags';
|
import { NodeTags } from '~/components/node/NodeTags';
|
||||||
import { NODE_COMPONENTS, NODE_INLINES, NODE_HEADS } from '~/redux/node/constants';
|
import {
|
||||||
|
NODE_COMPONENTS,
|
||||||
|
NODE_INLINES,
|
||||||
|
NODE_HEADS,
|
||||||
|
INodeComponentProps,
|
||||||
|
} from '~/redux/node/constants';
|
||||||
import { selectUser } from '~/redux/auth/selectors';
|
import { selectUser } from '~/redux/auth/selectors';
|
||||||
import pick from 'ramda/es/pick';
|
import pick from 'ramda/es/pick';
|
||||||
import { NodeRelatedPlaceholder } from '~/components/node/NodeRelated/placeholder';
|
import { NodeRelatedPlaceholder } from '~/components/node/NodeRelated/placeholder';
|
||||||
|
@ -25,10 +30,12 @@ import * as styles from './styles.scss';
|
||||||
import * as NODE_ACTIONS from '~/redux/node/actions';
|
import * as NODE_ACTIONS from '~/redux/node/actions';
|
||||||
import * as MODAL_ACTIONS from '~/redux/modal/actions';
|
import * as MODAL_ACTIONS from '~/redux/modal/actions';
|
||||||
import { IState } from '~/redux/store';
|
import { IState } from '~/redux/store';
|
||||||
|
import { selectModal } from '~/redux/modal/selectors';
|
||||||
|
|
||||||
const mapStateToProps = (state: IState) => ({
|
const mapStateToProps = (state: IState) => ({
|
||||||
node: selectNode(state),
|
node: selectNode(state),
|
||||||
user: selectUser(state),
|
user: selectUser(state),
|
||||||
|
modal: pick(['is_shown'])(selectModal(state)),
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
|
@ -63,6 +70,7 @@ const NodeLayoutUnconnected: FC<IProps> = memo(
|
||||||
comment_data,
|
comment_data,
|
||||||
comment_count,
|
comment_count,
|
||||||
},
|
},
|
||||||
|
modal: { is_shown: is_modal_shown },
|
||||||
user,
|
user,
|
||||||
user: { is_user },
|
user: { is_user },
|
||||||
nodeGotoNode,
|
nodeGotoNode,
|
||||||
|
@ -106,6 +114,20 @@ const NodeLayoutUnconnected: FC<IProps> = memo(
|
||||||
const onStar = useCallback(() => nodeStar(node.id), [nodeStar, node]);
|
const onStar = useCallback(() => nodeStar(node.id), [nodeStar, node]);
|
||||||
const onLock = useCallback(() => nodeLock(node.id, !node.deleted_at), [nodeStar, node]);
|
const onLock = useCallback(() => nodeLock(node.id, !node.deleted_at), [nodeStar, node]);
|
||||||
|
|
||||||
|
const createNodeBlock = useCallback(
|
||||||
|
(block: FC<INodeComponentProps>) =>
|
||||||
|
block &&
|
||||||
|
createElement(block, {
|
||||||
|
node,
|
||||||
|
is_loading,
|
||||||
|
updateLayout,
|
||||||
|
layout,
|
||||||
|
modalShowPhotoswipe,
|
||||||
|
is_modal_shown,
|
||||||
|
}),
|
||||||
|
[node, is_loading, updateLayout, layout, modalShowPhotoswipe, is_modal_shown]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!node.cover) return;
|
if (!node.cover) return;
|
||||||
nodeSetCoverImage(node.cover);
|
nodeSetCoverImage(node.cover);
|
||||||
|
@ -114,12 +136,10 @@ const NodeLayoutUnconnected: FC<IProps> = memo(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{head &&
|
{createNodeBlock(head)}
|
||||||
createElement(head, { node, is_loading, updateLayout, layout, modalShowPhotoswipe })}
|
|
||||||
|
|
||||||
<Card className={styles.node} seamless>
|
<Card className={styles.node} seamless>
|
||||||
{block &&
|
{createNodeBlock(block)}
|
||||||
createElement(block, { node, is_loading, updateLayout, layout, modalShowPhotoswipe })}
|
|
||||||
|
|
||||||
<NodePanel
|
<NodePanel
|
||||||
node={pick(
|
node={pick(
|
||||||
|
@ -144,17 +164,7 @@ const NodeLayoutUnconnected: FC<IProps> = memo(
|
||||||
<Padder>
|
<Padder>
|
||||||
<Group horizontal className={styles.content}>
|
<Group horizontal className={styles.content}>
|
||||||
<Group className={styles.comments}>
|
<Group className={styles.comments}>
|
||||||
{inline && (
|
{inline && <div className={styles.inline}>{createNodeBlock(inline)}</div>}
|
||||||
<div className={styles.inline}>
|
|
||||||
{createElement(inline, {
|
|
||||||
node,
|
|
||||||
is_loading,
|
|
||||||
updateLayout,
|
|
||||||
layout,
|
|
||||||
modalShowPhotoswipe,
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{is_loading || is_loading_comments || (!comments.length && !inline) ? (
|
{is_loading || is_loading_comments || (!comments.length && !inline) ? (
|
||||||
<NodeNoComments is_loading={is_loading_comments || is_loading} />
|
<NodeNoComments is_loading={is_loading_comments || is_loading} />
|
||||||
|
|
|
@ -76,24 +76,22 @@ export const NODE_TYPES = {
|
||||||
TEXT: 'text',
|
TEXT: 'text',
|
||||||
};
|
};
|
||||||
|
|
||||||
type INodeComponents = Record<
|
export type INodeComponentProps = {
|
||||||
ValueOf<typeof NODE_TYPES>,
|
|
||||||
FC<{
|
|
||||||
node: INode;
|
node: INode;
|
||||||
is_loading: boolean;
|
is_loading: boolean;
|
||||||
|
is_modal_shown: boolean;
|
||||||
layout: {};
|
layout: {};
|
||||||
updateLayout: () => void;
|
updateLayout: () => void;
|
||||||
modalShowPhotoswipe: typeof modalShowPhotoswipe;
|
modalShowPhotoswipe: typeof modalShowPhotoswipe;
|
||||||
}>
|
};
|
||||||
>;
|
|
||||||
|
export type INodeComponents = Record<ValueOf<typeof NODE_TYPES>, FC<INodeComponentProps>>;
|
||||||
|
|
||||||
export const NODE_HEADS: INodeComponents = {
|
export const NODE_HEADS: INodeComponents = {
|
||||||
// [NODE_TYPES.IMAGE]: NodeImageBlock,
|
|
||||||
[NODE_TYPES.IMAGE]: NodeImageSlideBlock,
|
[NODE_TYPES.IMAGE]: NodeImageSlideBlock,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NODE_COMPONENTS: INodeComponents = {
|
export const NODE_COMPONENTS: INodeComponents = {
|
||||||
// [NODE_TYPES.IMAGE]: NodeImageSlideBlock,
|
|
||||||
[NODE_TYPES.VIDEO]: NodeVideoBlock,
|
[NODE_TYPES.VIDEO]: NodeVideoBlock,
|
||||||
[NODE_TYPES.AUDIO]: NodeAudioImageBlock,
|
[NODE_TYPES.AUDIO]: NodeAudioImageBlock,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue