parent
36970c03c4
commit
16e3e75381
|
@ -54,6 +54,7 @@ type IframeSize = {
|
||||||
export type ArticlePageSearchParams = {
|
export type ArticlePageSearchParams = {
|
||||||
scrollTo: 'comments'
|
scrollTo: 'comments'
|
||||||
commentId: string
|
commentId: string
|
||||||
|
slide?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrollTo = (el: HTMLElement) => {
|
const scrollTo = (el: HTMLElement) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { For, Show, createEffect, createSignal, on, onCleanup, onMount } from 'solid-js'
|
import { For, Show, createEffect, createSignal, on, onCleanup, onMount } from 'solid-js'
|
||||||
import SwiperCore from 'swiper'
|
import SwiperCore from 'swiper'
|
||||||
import { Manipulation, Navigation, Pagination } from 'swiper/modules'
|
import { HashNavigation, Manipulation, Navigation, Pagination } from 'swiper/modules'
|
||||||
import { throttle } from 'throttle-debounce'
|
import { throttle } from 'throttle-debounce'
|
||||||
|
|
||||||
import { MediaItem } from '../../../pages/types'
|
import { MediaItem } from '../../../pages/types'
|
||||||
|
@ -12,6 +12,8 @@ import { Lightbox } from '../Lightbox'
|
||||||
|
|
||||||
import { SwiperRef } from './swiper'
|
import { SwiperRef } from './swiper'
|
||||||
|
|
||||||
|
import { useRouter } from '../../../stores/router'
|
||||||
|
import { ArticlePageSearchParams } from '../../Article/FullArticle'
|
||||||
import styles from './Swiper.module.scss'
|
import styles from './Swiper.module.scss'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -31,10 +33,13 @@ export const ImageSwiper = (props: Props) => {
|
||||||
const [slideIndex, setSlideIndex] = createSignal(0)
|
const [slideIndex, setSlideIndex] = createSignal(0)
|
||||||
const [isMobileView, setIsMobileView] = createSignal(false)
|
const [isMobileView, setIsMobileView] = createSignal(false)
|
||||||
const [selectedImage, setSelectedImage] = createSignal('')
|
const [selectedImage, setSelectedImage] = createSignal('')
|
||||||
|
const { searchParams, changeSearchParams } = useRouter<ArticlePageSearchParams>()
|
||||||
|
|
||||||
const handleSlideChange = () => {
|
const handleSlideChange = () => {
|
||||||
thumbSwipeRef.current.swiper.slideTo(mainSwipeRef.current.swiper.activeIndex)
|
const activeIndex = mainSwipeRef.current.swiper.activeIndex
|
||||||
setSlideIndex(mainSwipeRef.current.swiper.activeIndex)
|
thumbSwipeRef.current.swiper.slideTo(activeIndex)
|
||||||
|
setSlideIndex(activeIndex)
|
||||||
|
changeSearchParams({ slide: `${activeIndex + 1}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
|
@ -51,11 +56,19 @@ export const ImageSwiper = (props: Props) => {
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const { register } = await import('swiper/element/bundle')
|
const { register } = await import('swiper/element/bundle')
|
||||||
register()
|
register()
|
||||||
SwiperCore.use([Pagination, Navigation, Manipulation])
|
SwiperCore.use([Pagination, Navigation, Manipulation, HashNavigation])
|
||||||
while (!mainSwipeRef.current || !mainSwipeRef.current.swiper) {
|
while (!mainSwipeRef.current || !mainSwipeRef.current.swiper) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10)) // wait 10 ms
|
await new Promise((resolve) => setTimeout(resolve, 10)) // wait 10 ms
|
||||||
}
|
}
|
||||||
mainSwipeRef.current.swiper.on('slideChange', handleSlideChange)
|
mainSwipeRef.current.swiper.on('slideChange', handleSlideChange)
|
||||||
|
const initialSlide = parseInt(searchParams().slide) - 1
|
||||||
|
if (initialSlide && !Number.isNaN(initialSlide) && initialSlide < props.images.length) {
|
||||||
|
mainSwipeRef.current.swiper.slideTo(initialSlide, 0)
|
||||||
|
} else {
|
||||||
|
changeSearchParams({ slide: '1' })
|
||||||
|
}
|
||||||
|
|
||||||
|
mainSwipeRef.current.swiper.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
@ -106,6 +119,9 @@ export const ImageSwiper = (props: Props) => {
|
||||||
watch-slides-visibility={true}
|
watch-slides-visibility={true}
|
||||||
direction={'horizontal'}
|
direction={'horizontal'}
|
||||||
slides-per-group-auto={true}
|
slides-per-group-auto={true}
|
||||||
|
hash-navigation={{
|
||||||
|
watchState: true,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<For each={props.images}>
|
<For each={props.images}>
|
||||||
{(slide, index) => (
|
{(slide, index) => (
|
||||||
|
@ -152,7 +168,7 @@ export const ImageSwiper = (props: Props) => {
|
||||||
{(slide, index) => (
|
{(slide, index) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
<swiper-slide lazy="true" virtual-index={index()}>
|
<swiper-slide lazy="true" virtual-index={index()} data-hash={index() + 1}>
|
||||||
<div class={styles.image} onClick={handleImageClick}>
|
<div class={styles.image} onClick={handleImageClick}>
|
||||||
<Image src={slide.url} alt={slide.title} width={800} />
|
<Image src={slide.url} alt={slide.title} width={800} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -135,9 +135,13 @@
|
||||||
.counter {
|
.counter {
|
||||||
@include font-size(1.2rem);
|
@include font-size(1.2rem);
|
||||||
|
|
||||||
|
@include media-breakpoint-up(sm) {
|
||||||
|
top: 477px;
|
||||||
|
}
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
top: 477px;
|
top: 276px;
|
||||||
right: 0;
|
right: 0;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
padding: 0.2rem 0.8rem;
|
padding: 0.2rem 0.8rem;
|
||||||
|
|
|
@ -114,8 +114,8 @@ const handleClientRouteLinkClick = async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.hash) {
|
if (url.hash) {
|
||||||
scrollToHash(url.hash)
|
// scrollToHash(url.hash)
|
||||||
return
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user