1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

rename NodeComponentProps

This commit is contained in:
Fedor Katurov 2023-11-04 10:48:57 +06:00
parent 8553f91429
commit 65196bbbbb
15 changed files with 59 additions and 45 deletions

View file

@ -2,9 +2,9 @@ import React, { FC } from 'react';
import { NodeAudioBlock } from '~/components/node/NodeAudioBlock'; import { NodeAudioBlock } from '~/components/node/NodeAudioBlock';
import { Placeholder } from '~/components/placeholders/Placeholder'; import { Placeholder } from '~/components/placeholders/Placeholder';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
const LabAudio: FC<INodeComponentProps> = ({ node, isLoading }) => ( const LabAudio: FC<NodeComponentProps> = ({ node, isLoading }) => (
<Placeholder active={isLoading} width="100%" height={100}> <Placeholder active={isLoading} width="100%" height={100}>
<NodeAudioBlock node={node} isLoading={isLoading} /> <NodeAudioBlock node={node} isLoading={isLoading} />
</Placeholder> </Placeholder>

View file

@ -2,13 +2,13 @@ import React, { FC } from 'react';
import { Markdown } from '~/components/containers/Markdown'; import { Markdown } from '~/components/containers/Markdown';
import { Paragraph } from '~/components/placeholders/Paragraph'; import { Paragraph } from '~/components/placeholders/Paragraph';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useGotoNode } from '~/hooks/node/useGotoNode'; import { useGotoNode } from '~/hooks/node/useGotoNode';
import { formatText } from '~/utils/dom'; import { formatText } from '~/utils/dom';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
const LabDescription: FC<INodeComponentProps> = ({ node, isLoading }) => { const LabDescription: FC<NodeComponentProps> = ({ node, isLoading }) => {
const onClick = useGotoNode(node.id); const onClick = useGotoNode(node.id);
if (!node.description) { if (!node.description) {

View file

@ -4,7 +4,7 @@ import Image from 'next/future/image';
import SwiperCore, { A11y, Navigation, Pagination } from 'swiper'; import SwiperCore, { A11y, Navigation, Pagination } from 'swiper';
import { Placeholder } from '~/components/placeholders/Placeholder'; import { Placeholder } from '~/components/placeholders/Placeholder';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { imagePresets } from '~/constants/urls'; import { imagePresets } from '~/constants/urls';
import { useGotoNode } from '~/hooks/node/useGotoNode'; import { useGotoNode } from '~/hooks/node/useGotoNode';
import { useNodeImages } from '~/hooks/node/useNodeImages'; import { useNodeImages } from '~/hooks/node/useNodeImages';
@ -15,7 +15,7 @@ import styles from './styles.module.scss';
SwiperCore.use([Navigation, Pagination, A11y]); SwiperCore.use([Navigation, Pagination, A11y]);
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const LabImage: FC<IProps> = ({ node, isLoading }) => { const LabImage: FC<IProps> = ({ node, isLoading }) => {
const images = useNodeImages(node); const images = useNodeImages(node);

View file

@ -1,11 +1,11 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useColorGradientFromString } from '~/hooks/color/useColorGradientFromString'; import { useColorGradientFromString } from '~/hooks/color/useColorGradientFromString';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
interface Props extends INodeComponentProps {} interface Props extends NodeComponentProps {}
const LabLine: FC<Props> = ({ node: { title } }) => { const LabLine: FC<Props> = ({ node: { title } }) => {
const background = useColorGradientFromString(title, 5, 3, 270); const background = useColorGradientFromString(title, 5, 3, 270);

View file

@ -5,12 +5,12 @@ import Tippy from '@tippyjs/react';
import { Group } from '~/components/containers/Group'; import { Group } from '~/components/containers/Group';
import { Icon } from '~/components/input/Icon'; import { Icon } from '~/components/input/Icon';
import { Placeholder } from '~/components/placeholders/Placeholder'; import { Placeholder } from '~/components/placeholders/Placeholder';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useGotoNode } from '~/hooks/node/useGotoNode'; import { useGotoNode } from '~/hooks/node/useGotoNode';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
const LabNodeTitle: FC<INodeComponentProps> = ({ node, isLoading }) => { const LabNodeTitle: FC<NodeComponentProps> = ({ node, isLoading }) => {
const onClick = useGotoNode(node.id); const onClick = useGotoNode(node.id);
if (!node.title) return null; if (!node.title) return null;

View file

@ -1,11 +1,11 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useGotoNode } from '~/hooks/node/useGotoNode'; import { useGotoNode } from '~/hooks/node/useGotoNode';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
const LabPad: FC<INodeComponentProps> = ({ node }) => { const LabPad: FC<NodeComponentProps> = ({ node }) => {
const onClick = useGotoNode(node.id); const onClick = useGotoNode(node.id);
return <div className={styles.pad} onClick={onClick} />; return <div className={styles.pad} onClick={onClick} />;
}; };

View file

@ -2,14 +2,14 @@ import React, { FC, useMemo } from 'react';
import { Markdown } from '~/components/containers/Markdown'; import { Markdown } from '~/components/containers/Markdown';
import { Paragraph } from '~/components/placeholders/Paragraph'; import { Paragraph } from '~/components/placeholders/Paragraph';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useGotoNode } from '~/hooks/node/useGotoNode'; import { useGotoNode } from '~/hooks/node/useGotoNode';
import { formatTextParagraphs } from '~/utils/dom'; import { formatTextParagraphs } from '~/utils/dom';
import { path } from '~/utils/ramda'; import { path } from '~/utils/ramda';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
const LabText: FC<INodeComponentProps> = ({ node, isLoading }) => { const LabText: FC<NodeComponentProps> = ({ node, isLoading }) => {
const content = useMemo( const content = useMemo(
() => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''), () => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''),
[node], [node],

View file

@ -2,9 +2,9 @@ import React, { FC } from 'react';
import { NodeVideoBlock } from '~/components/node/NodeVideoBlock'; import { NodeVideoBlock } from '~/components/node/NodeVideoBlock';
import { Placeholder } from '~/components/placeholders/Placeholder'; import { Placeholder } from '~/components/placeholders/Placeholder';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
const LabVideo: FC<INodeComponentProps> = ({ node, isLoading }) => ( const LabVideo: FC<NodeComponentProps> = ({ node, isLoading }) => (
<Placeholder active={isLoading} width="100%" height={400}> <Placeholder active={isLoading} width="100%" height={400}>
<NodeVideoBlock node={node} isLoading={isLoading} /> <NodeVideoBlock node={node} isLoading={isLoading} />
</Placeholder> </Placeholder>

View file

@ -1,19 +1,19 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { AudioPlayer } from '~/components/media/AudioPlayer'; import { AudioPlayer } from '~/components/media/AudioPlayer';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useNodeAudios } from '~/hooks/node/useNodeAudios'; import { useNodeAudios } from '~/hooks/node/useNodeAudios';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const NodeAudioBlock: FC<IProps> = ({ node }) => { const NodeAudioBlock: FC<IProps> = ({ node }) => {
const audios = useNodeAudios(node); const audios = useNodeAudios(node);
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>
{audios.map(file => ( {audios.map((file) => (
<AudioPlayer key={file.id} file={file} /> <AudioPlayer key={file.id} file={file} />
))} ))}
</div> </div>

View file

@ -1,6 +1,6 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { imagePresets } from '~/constants/urls'; import { imagePresets } from '~/constants/urls';
import { useNodeImages } from '~/hooks/node/useNodeImages'; import { useNodeImages } from '~/hooks/node/useNodeImages';
import { getURL } from '~/utils/dom'; import { getURL } from '~/utils/dom';
@ -8,7 +8,7 @@ import { path } from '~/utils/ramda';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const NodeAudioImageBlock: FC<IProps> = ({ node }) => { const NodeAudioImageBlock: FC<IProps> = ({ node }) => {
const images = useNodeImages(node); const images = useNodeImages(node);

View file

@ -13,7 +13,7 @@ import { Swiper, SwiperSlide } from 'swiper/react';
import SwiperClass from 'swiper/types/swiper-class'; import SwiperClass from 'swiper/types/swiper-class';
import { ImageLoadingWrapper } from '~/components/common/ImageLoadingWrapper/index'; import { ImageLoadingWrapper } from '~/components/common/ImageLoadingWrapper/index';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { imagePresets } from '~/constants/urls'; import { imagePresets } from '~/constants/urls';
import { useModal } from '~/hooks/modal/useModal'; import { useModal } from '~/hooks/modal/useModal';
import { useImageModal } from '~/hooks/navigation/useImageModal'; import { useImageModal } from '~/hooks/navigation/useImageModal';
@ -26,7 +26,7 @@ import styles from './styles.module.scss';
SwiperCore.use([Navigation, Pagination, Keyboard, Lazy]); SwiperCore.use([Navigation, Pagination, Keyboard, Lazy]);
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const breakpoints: SwiperOptions['breakpoints'] = { const breakpoints: SwiperOptions['breakpoints'] = {
599: { 599: {

View file

@ -2,7 +2,7 @@ import React, { FC, useMemo } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { useColorGradientFromString } from '~/hooks/color/useColorGradientFromString'; import { useColorGradientFromString } from '~/hooks/color/useColorGradientFromString';
import markdown from '~/styles/common/markdown.module.scss'; import markdown from '~/styles/common/markdown.module.scss';
import { formatTextParagraphs } from '~/utils/dom'; import { formatTextParagraphs } from '~/utils/dom';
@ -10,12 +10,13 @@ import { path } from '~/utils/ramda';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const NodeTextBlock: FC<IProps> = ({ node }) => { const NodeTextBlock: FC<IProps> = ({ node }) => {
const content = useMemo(() => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''), [ const content = useMemo(
node, () => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''),
]); [node],
);
const background = useColorGradientFromString(node.title, 3, 2); const background = useColorGradientFromString(node.title, 3, 2);

View file

@ -1,11 +1,11 @@
import React, { FC, useMemo } from 'react'; import React, { FC, useMemo } from 'react';
import { INodeComponentProps } from '~/constants/node'; import { NodeComponentProps } from '~/constants/node';
import { path } from '~/utils/ramda'; import { path } from '~/utils/ramda';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
interface IProps extends INodeComponentProps {} interface IProps extends NodeComponentProps {}
const NodeVideoBlock: FC<IProps> = ({ node }) => { const NodeVideoBlock: FC<IProps> = ({ node }) => {
const video = useMemo(() => { const video = useMemo(() => {
@ -13,7 +13,7 @@ const NodeVideoBlock: FC<IProps> = ({ node }) => {
const match = const match =
url && url &&
url.match( url.match(
/http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-_]*)(&(amp;)?[\w?=]*)?/ /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-_]*)(&(amp;)?[\w?=]*)?/,
); );
return match && match[1]; return match && match[1];

View file

@ -53,17 +53,17 @@ export const NODE_TYPES = {
ROOM: 'room', ROOM: 'room',
}; };
export type INodeComponentProps = { export type NodeComponentProps = {
node: INode; node: INode;
isLoading: boolean; isLoading: boolean;
}; };
export type INodeComponents = Record< export type INodeComponents = Record<
ValueOf<typeof NODE_TYPES>, ValueOf<typeof NODE_TYPES>,
FC<INodeComponentProps> FC<NodeComponentProps>
>; >;
export const LAB_PREVIEW_LAYOUT: Record<string, FC<INodeComponentProps>[]> = { export const LAB_PREVIEW_LAYOUT: Record<string, FC<NodeComponentProps>[]> = {
[NODE_TYPES.IMAGE]: [LabImage, LabPad, LabNodeTitle, LabDescription], [NODE_TYPES.IMAGE]: [LabImage, LabPad, LabNodeTitle, LabDescription],
[NODE_TYPES.VIDEO]: [LabVideo, LabPad, LabNodeTitle, LabDescription], [NODE_TYPES.VIDEO]: [LabVideo, LabPad, LabNodeTitle, LabDescription],
[NODE_TYPES.AUDIO]: [ [NODE_TYPES.AUDIO]: [

View file

@ -1,43 +1,56 @@
import { createElement, FC, useCallback, useMemo } from 'react'; import { createElement, FC, useCallback, useMemo } from 'react';
import { INodeComponentProps, LAB_PREVIEW_LAYOUT, NODE_COMPONENTS, NODE_HEADS, NODE_INLINES } from '~/constants/node'; import {
NodeComponentProps,
LAB_PREVIEW_LAYOUT,
NODE_COMPONENTS,
NODE_HEADS,
NODE_INLINES,
} from '~/constants/node';
import { INode } from '~/types'; import { INode } from '~/types';
import { isNil, prop } from '~/utils/ramda'; import { isNil, prop } from '~/utils/ramda';
// useNodeBlocks returns head, block and inline blocks of node // useNodeBlocks returns head, block and inline blocks of node
export const useNodeBlocks = (node: INode, isLoading: boolean) => { export const useNodeBlocks = (node: INode, isLoading: boolean) => {
const createNodeBlock = useCallback( const createNodeBlock = useCallback(
(block?: FC<INodeComponentProps>, key = 0) => (block?: FC<NodeComponentProps>, key = 0) =>
!isNil(block) && !isNil(block) &&
createElement(block, { createElement(block, {
node, node,
isLoading, isLoading,
key: `${node.id}-${key}`, key: `${node.id}-${key}`,
}), }),
[node, isLoading] [node, isLoading],
); );
const head = useMemo( const head = useMemo(
() => createNodeBlock(node?.type ? prop(node?.type, NODE_HEADS) : undefined), () =>
[node, createNodeBlock] createNodeBlock(node?.type ? prop(node?.type, NODE_HEADS) : undefined),
[node, createNodeBlock],
); );
const block = useMemo( const block = useMemo(
() => createNodeBlock(node?.type ? prop(node?.type, NODE_COMPONENTS) : undefined), () =>
[node, createNodeBlock] createNodeBlock(
node?.type ? prop(node?.type, NODE_COMPONENTS) : undefined,
),
[node, createNodeBlock],
); );
const inline = useMemo( const inline = useMemo(
() => createNodeBlock(node?.type ? prop(node?.type, NODE_INLINES) : undefined), () =>
[node, createNodeBlock] createNodeBlock(node?.type ? prop(node?.type, NODE_INLINES) : undefined),
[node, createNodeBlock],
); );
const lab = useMemo( const lab = useMemo(
() => () =>
node?.type && prop(node.type, LAB_PREVIEW_LAYOUT) node?.type && prop(node.type, LAB_PREVIEW_LAYOUT)
? prop(node.type, LAB_PREVIEW_LAYOUT).map((comp, i) => createNodeBlock(comp, i)) ? prop(node.type, LAB_PREVIEW_LAYOUT).map((comp, i) =>
createNodeBlock(comp, i),
)
: undefined, : undefined,
[node, createNodeBlock] [node, createNodeBlock],
); );
return { head, block, inline, lab }; return { head, block, inline, lab };