|
|
|
@ -37,45 +37,48 @@ export const MatchesSlider = ({ cardSize, matches }: MatchesSliderProps) => { |
|
|
|
} = useMatchesSlider(matches) |
|
|
|
} = useMatchesSlider(matches) |
|
|
|
|
|
|
|
|
|
|
|
const scrollToMatchByIndex = (index: number) => { |
|
|
|
const scrollToMatchByIndex = (index: number) => { |
|
|
|
const match = slidesRef.current!.querySelectorAll('li')[index] |
|
|
|
if (slidesRef.current) { |
|
|
|
const offsetLeftCount = match.offsetLeft |
|
|
|
const match = slidesRef.current.querySelectorAll('li')[index] |
|
|
|
|
|
|
|
const offsetLeftCount = match.offsetLeft |
|
|
|
const offsetLeft = offsetLeftCount - PADDING_PARENT |
|
|
|
|
|
|
|
|
|
|
|
const offsetLeft = offsetLeftCount - PADDING_PARENT |
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
slidesRef.current!.scrollBy({ |
|
|
|
setTimeout(() => { |
|
|
|
// @ts-ignore
|
|
|
|
slidesRef.current?.scrollBy({ |
|
|
|
behavior: 'instant', |
|
|
|
// @ts-ignore
|
|
|
|
left: offsetLeft, |
|
|
|
behavior: 'instant', |
|
|
|
}) |
|
|
|
left: offsetLeft, |
|
|
|
}, 0) |
|
|
|
}) |
|
|
|
|
|
|
|
}, 0) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// скролл к лайв матчам или сегодняшней дате
|
|
|
|
// скролл к лайв матчам или сегодняшней дате
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const matchIndexLive = matches.findIndex(({ live }) => live) |
|
|
|
if (slidesRef.current) { |
|
|
|
if (matchIndexLive !== -1) { |
|
|
|
const matchIndexLive = matches.findIndex(({ live }) => live) |
|
|
|
scrollToMatchByIndex(matchIndexLive) |
|
|
|
if (matchIndexLive !== -1) { |
|
|
|
return |
|
|
|
scrollToMatchByIndex(matchIndexLive) |
|
|
|
} |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
const matchIndex = matches.findIndex((item) => new Date() <= item.date) |
|
|
|
|
|
|
|
if (matchIndex !== -1) { |
|
|
|
const matchIndex = matches.findIndex((item) => new Date() <= item.date) |
|
|
|
scrollToMatchByIndex(matchIndex) |
|
|
|
if (matchIndex !== -1) { |
|
|
|
return |
|
|
|
scrollToMatchByIndex(matchIndex) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const slidesRefClientWidth = slidesRef.current.clientWidth |
|
|
|
|
|
|
|
const slidesRefScrollWidth = slidesRef.current.scrollWidth |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
slidesRef.current?.scrollBy({ |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
behavior: 'instant', |
|
|
|
|
|
|
|
left: slidesRefScrollWidth - slidesRefClientWidth + PADDING_PARENT, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const slidesRefClientWidth = slidesRef.current!.clientWidth |
|
|
|
|
|
|
|
const slidesRefScrollWidth = slidesRef.current!.scrollWidth |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
slidesRef.current!.scrollBy({ |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
behavior: 'instant', |
|
|
|
|
|
|
|
left: slidesRefScrollWidth - slidesRefClientWidth + PADDING_PARENT, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []) |
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
|