mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added lazy loading to lab
This commit is contained in:
parent
10bb6f01b5
commit
182ff11d2b
4 changed files with 26 additions and 19 deletions
|
@ -2,28 +2,23 @@ import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
|||
|
||||
import classNames from 'classnames';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import Image from 'next/future/image';
|
||||
import SwiperCore, {
|
||||
Keyboard,
|
||||
Lazy,
|
||||
Navigation,
|
||||
Pagination,
|
||||
SwiperOptions,
|
||||
Lazy,
|
||||
} from 'swiper';
|
||||
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||
import SwiperClass from 'swiper/types/swiper-class';
|
||||
|
||||
import { ImagePreloader } from '~/components/media/ImagePreloader';
|
||||
import { INodeComponentProps } from '~/constants/node';
|
||||
import { imagePresets } from '~/constants/urls';
|
||||
import { useModal } from '~/hooks/modal/useModal';
|
||||
import { useImageModal } from '~/hooks/navigation/useImageModal';
|
||||
import { useNodeImages } from '~/hooks/node/useNodeImages';
|
||||
import { IFile } from '~/types';
|
||||
import { normalizeBrightColor } from '~/utils/color';
|
||||
import { getURL } from '~/utils/dom';
|
||||
|
||||
import { imageSrcSets, ImagePreset } from '../../../constants/urls';
|
||||
import { getFileSrcSet } from '~/utils/srcset';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
|
@ -47,14 +42,6 @@ const lazy = {
|
|||
checkInView: true,
|
||||
};
|
||||
|
||||
const generateSrcSet = (file: IFile) =>
|
||||
Object.keys(imageSrcSets)
|
||||
.map(
|
||||
(preset) =>
|
||||
`${getURL(file, preset as ImagePreset)} ${imageSrcSets[preset]}w`,
|
||||
)
|
||||
.join(', ');
|
||||
|
||||
const NodeImageSwiperBlock: FC<IProps> = observer(({ node }) => {
|
||||
const [controlledSwiper, setControlledSwiper] = useState<
|
||||
SwiperClass | undefined
|
||||
|
@ -154,7 +141,7 @@ const NodeImageSwiperBlock: FC<IProps> = observer(({ node }) => {
|
|||
<SwiperSlide className={styles.slide} key={file.id}>
|
||||
<img
|
||||
style={{ backgroundColor: file.metadata?.dominant_color }}
|
||||
data-srcset={generateSrcSet(file)}
|
||||
data-srcset={getFileSrcSet(file)}
|
||||
width={file.metadata?.width}
|
||||
height={file.metadata?.height}
|
||||
onLoad={updateSwiper}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue